Elektrotehniški vestnik 73(2-3): 8^-92, 2006 Electrotechnical Review, Ljubljana, Slovenija Reconstructing 3D Curves with Euclidean Minimal Spanning Trees Simon Kolmanic, Nikola Guid University of Maribor, Faculty of Electrical Engineering and Computer Science, Smetanova ulica 17, Maribor, Slovenia E-mail: simon.kolmanic@uni-mb.si, guid@uni-mb.si Abstract. In this paper, we present a new efficient algorithm for reconstruction of nonintersecting 3D curves from a sufficiently dense sample. We use the Euclidean minimal spanning trees to identify line segments reconstructing curve shapes. To deal with more than one curve in a sample and to eliminate noisy data, we introduce chains of connected line segments. With the incremental growth based on heuristics, the chains contain finally curve shapes. The method is robust and fast for both 2D and 3D curves. Key words: point cloud, curve reconstruction, Euclidean minimal spanning trees Rekonstrukcija prostorskih krivulj s pomocjo evklidskih minimalnih vpetih dreves Povzetek. V članku predstavljamo nov učinkovit algoritem za rekonstrukcijo prostorskih krivulj iz dovolj gostega vzorca. S pomočjo evklidskih minimalnih vpetih dreves poiščemo tiste daljice, ki rekonstruirajo krivuljo. Za delo z več krivuljami v vzorcu in odstranitev točk šuma uporabljamo strukturo, ki jo imenujmo verige povezanih daljic. Z inkrementalno rastjo, ki temelji na hevristiki, dobimo v verigah iskano rekonstrukcijo krivulj. Predstavljena metoda je robustna in hitra tako pri rekonstrukciji ravninskih kot tudi prostorskih krivulj. Ključne besede: oblak točk, rekonstrukcija krivulj, evklidska minimalna vpeta drevesa 1 Introduction Suppose that a cloud of points obtained by sampling of a collection of arbitrary 3D curves is given. The number of curves is not known. A curve sample in general does not contain the same number of points and the distribution of points in a sample may vary. If the sampling is dense enough, it is an easy task for the human to find these curves and perceive their shapes. For a computer, however, the task is much harder. From the cloud of points, the computer must find those points that belong to the same curve and then to sort them in a correct order, compatible with the original trace of the curve. In this case, the curve is reconstructed. Received 4 October 2005 Accepted 30 January 2006 There are many known methods for curve reconstruction in the plane [1, 3, 4, 8-10, 12-14, 18]. Most of these methods are based on the Delaunay triangulation, therefore, they do not work or run much slower if a 3D curve has to be reconstructed. Exceptions are methods presented in [1] and [8]. In [1], the curve reconstruction is given by a travelling salesman route while the reconstruction in [8] is based on the nearest neighbour graph [17]. Therefore, we search for a solution of reconstruction of 3D curves in the graph theory. In contrast to [1, 8], we focused on the minimal spanning trees, which were used in the early seventies for pattern recognition and cluster analysis [19, 11]. The advantage of minimal spanning trees is in their independence on the space dimension where the sample is given, and in relatively simple algorithms for their computation. In [2], methods [1, 3, 4, 8-10, 13] are classified as algorithms with guaranteed performance, i.e., algorithms that provably reconstruct curves under certain assumptions. In [13], the formal proof can be found that the Euclidean minimal spanning trees correctly reconstruct different iable arcs from sufficiently dense samples. The correct reconstruction, also called polygonal reconstruction, G(5, T) of a sample S with respect to a collection of the nonintersecting curves T is defined as a graph G with the vertex set S having exactly those edges that connect sample points adjacent in T [3, 8, 14]. In this paper, we use the definition for a dense sample given by Figueiredo and Gomes [13]: a sample is sufficiently dense if there is a real positive number £ such that no two consecutive sample points are more than £ apart and closed discs of the radius centered at the sample points, form a tubular neighbourhood of the single curve G. It is clear that the Euclidean minimal spanning trees cannot give the correct reconstruction of a collection of nonintersecting curves without additional heuristics since the polygonal reconstructions of individual curves are connected to each other with edges, which Figueiredo terms bridges (see Fig. lb). Only if all the bridges are eliminated, the correct reconstruction of sample S is given. To do that, we introduce a structure we term a chain of connected line segments. This is a list of line segments giving the correct reconstruction of one curve sorted in the right order. With special criteria for adding a line segment to the chain, we achieve that all the bridges form their own chains, which have to be eliminated at the end of the reconstruction process. The chains of the connected line segments are not only used to give us the correct reconstruction of single lines, but also to reduce the noise significantly. The paper is organised in seven sections. In Section 2, we introduce the Euclidean spanning trees as a possible solution of the curve reconstruction and problems connected with it. A chain of connected line segments with its incremental growth and corresponding heuristics is presented in Section 3. In Section 4, we consider the handling of closed curves and noise reduction. The procedure for speeding up the reconstruction process is described in Section 5. The experimental results are shown in Section 6 and the last section presents a conclusion. 2 Euclidean minimal spanning trees The computation of the correct reconstruction of curves, i.e. G(£, F), is possible only if a sufficiently dense sample determined by the Figueiredo-Gomes criterion is given [13]. In this case, the sample is called an ^-sample. The correct reconstruction G(5, T) is not only a graph having the same topology as the curve, but its vertices are the points lying in the plane or space and the edges are line segments connecting the points into the polygonal approximation of the curve. Therefore, G(5, T) is also a geometric graph. If we introduce line segment lengths in G(£, T) as weights of its edges, the graph G(£, T) becomes a weighted geometric graph. The minimal spanning tree (MST) for a weighted graph is a spanning tree for which the sum of edge weights is minimal. The geometric version of the minimal spanning tree is called the Euclidean minimal spanning tree (EMST). In the early seventies, EMST was used for solving of the particle track problem, where the shape of a single curve in a noisy sample had to be found, and for a cluster analysis [19, 11]. Finally in [13, 1], we can find the formal proof that the Euclidian minimal spanning trees can correctly reconstruct differential arcs from a sufficiently dense sample. Although Figueiredo considers only plane curves, his proof can easily be extended to 3D curves. This is not surprising since Zahn pointed out already that the Euclidean minimal spanning tree could be used in higher dimensional spaces or, in fact, in general metric spaces [19]. Besides, the minimal spanning trees are interesting because they are well understood and easily computed. In this paper, we use the simplest but by far not an optimal algorithm for computation of the minimal spanning tree - the Kruskal algorithm [7, 16]. If G(£, T) is a geometric graph, the Kruskal algorithm [7] returns the edges of the Euclidean minimal spanning tree. The first step to obtain EMST for a sample S is to generate the geometric graph G( V, E), where V are the points of the sample S and E are line segments connecting those points. Next, the algorithm for computing the minimal spanning tree has to be started to obtain the line segments reconstructing the curve shape. If S is a dense sample of an open single curve G, EMST returns all the edges forming correct reconstruction, but generally, we have to find their correct order. If S is a sample of several nonintersecting curves, however, the problem is much harder. With EMST, we get a set of the line segments that reconstruct the shape of curves. Then, we have to classify which line segments belong to which curve and finally the correct order of lines has to be determined. The sample of nonintersecting curves and the corresponding set of the line segments obtained by EMST can be seen in Fig. 1. In Fig. lb, the line segments 1-5, which are a part of EMST, are marked, but they are not a part of the original curves. Figueiredo calls those line segments bridges and they have to be removed in order to get the correct reconstruction. He proposes the same method Zahn already mentioned in [18]. Those line segments are removed according to the combination of their lengths and the degree of their edge points, where the degree of a point is given by a number of line segments meeting at that point. This works well if only the sample of one curve with noisy data is given or if the lengths of the line segments, representing the correct reconstruction, are nearly the same. In Fig. lb, the problem of the bridge removal is much harder. The bridges 3 and 5, for example, cannot be removed according to the Zahn criterion because they are shorter than the line segments reconstructing the ellipse and their endpoints do not a) b) Figure 1. Implementation of EMST in the curve reconstruction: a) Sample of nonintersecting curves, b) Set of the line segments obtained by EMST with marked "bridges" have degrees of 3 and 1. To solve similar problems and to efficiently classify the line segments to appropriate curves, we propose a structure we have named a chain of connected line segments. 3 The chain of connected line segments The chain of connected line segments is a sequence of equally oriented vectors v^, where the end point of the vector v^ is at the same time the starting point of the vector (see Fig. 2). The direction of the vector Wi is defined by the sequence of vertices defining the line segment z, accepted by the algorithm for computing EMST. The requirement for the same orientation in the chain assures that the points belonging to the same polygonal reconstruction are sorted in the right order. In the reconstruction of the sample of several nonintersecting curves, each chain represents one of the curves. Figure 2. Degree of vertices of EMST with chains of connected line segments The chain of connected line segments is built incrementally by adding new lines to the existing chains, since there are usually more than one chain in the reconstruction process. The line segments, accepted by the algorithm for computation of EMST, have to be sorted in the increasing order according to their lengths. This is done automatically by the Kruskal algorithm [7], but they have to be sorted first by other minimal spanning trees generation algorithms. Since their number is relatively small (n - 1, where n is the number of points in the sample) regarding to the number of edges in E1, the sorting does not represent a significant time lost. The chain orientation helps us to define a starting vertex and an ending one of the chain. Only those two vertices in the chain can have the degree 1 while all the others have the degree 2 at least. Therefore, a new line segment can be added to the chain only if it has one common vertex at the beginning or at the end of the chain and its degree is 1. In other case, the line segment generates a new chain. When the line segment is added to the chain, the degree of their common point is increased by 1. The chains, whose starting and ending vertex have the degree greater than 1, are attached to another chain and usually represent bridges or noisy data. This can be seen in Fig. 2, where four different chains of connected line segments can be seen. The degree of one from the border vertices of the chains C2, C3, and C4 is larger than 1 and, therefore, the chains represent a noise. We have already mentioned that many chains of connected line segments can be generated in the reconstruction process, since they are built incrementally by adding edges of EMST. Two of the existing chains are combined into a single one if the line segment is added whose endpoints belong to both of these chains where the orientation of the chain with shorter edges is preserved. The described procedure can be seen in Figure 3. procedure AddLineSegment (1) { i=0; // find the appropriate chain while (i