Computational Geometry 46 (2013) 263–275
Contents lists available at SciVerse ScienceDirect
Computational Geometry: Theory and Applications www.elsevier.com/locate/comgeo
Approximation of a closed polygon with a minimum number of circular arcs and line segments Georg Maier a,∗ , Georg Pisinger b a b
Institute for Software Systems in Technical Applications, University of Passau, Innstr. 43, 94032 Passau, Germany Heilbronn University, Max-Planck Str. 39, 74081 Heilbronn, Germany
a r t i c l e
i n f o
Article history: Received 28 August 2012 Accepted 5 September 2012 Available online 12 September 2012 Communicated by S. Suri Keywords: Approximation Arc spline Polygon Simplification
a b s t r a c t Optimal approximation of closed polygons differs from the case of open polygons in the sense that the location of a starting point must be determined in a suitable way. We present an algorithm which first computes a proper extremal arc as starting point and then approximates the input polygon with a minimum number of circular arcs and line segments. The resulting curve is called Cyclic Minimum Arc Path (CMAP). Our algorithm guarantees the CMAP staying inside a user-specified tolerance. In contrast to the existing approaches, we do not restrict the breakpoints of the arc spline to a predefined set of points but choose them automatically. This has considerable effects on the resulting number of segments. We can handle every type of tolerance zone representing the user-specified tolerance as long it is formed by piecewise restricted analytic curves. In case of polygonal tolerance zones the proposed algorithm takes O (n3 ) time for an original polygonal chain with n vertices. For generating a solution which has at most one additional segment we present an O (n2 ) algorithm. © 2012 Elsevier B.V. All rights reserved.
1. Introduction 1.1. Motivation Approximations of polygonal curves, especially closed ones, by a comparatively small number of higher order geometric primitives, as for instance circular arcs, can achieve a considerable data compression and a parameter free description. This is beneficial for various applications in Computer Graphics, vectorization of pixel images, Shape Recognition, Robotics and Reverse Engineering. One possible choice of suitable primitives are circular arcs and line segments, shortly segments. Since an accurate approximation and a small number of segments are both desirable, we have to deal with a multi-objective optimization problem. 1.2. Related work As circular arcs have many advantages compared to spline curves, such as exact offset computation, invariance regarding rotation, translation and scaling and simple closest point computation (cf. [1]), research on arc splines, which are continuous curves composed of circular arcs and line segments (cf. [2]), has been very active in the last decades (e.g. [2–5]).
*
Corresponding author. E-mail addresses:
[email protected] (G. Maier),
[email protected] (G. Pisinger).
0925-7721/$ – see front matter © 2012 Elsevier B.V. All rights reserved. http://dx.doi.org/10.1016/j.comgeo.2012.09.003
264
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
Fig. 1. Grey shaded: Tolerance channel for a maximum tolerance ε ; red: segment approximation of input polygon (dotted points) within tolerance channel; right: Biarc approximation based on heuristical tangent choice (indicated by black arrows). (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)
In particular, curves composed of single arcs or biarcs, i.e. G 1 curve segments consisting of two circular arcs, have been used in a large number of algorithms for approximation or interpolation of given point and possibly tangent data. Biarcs, which were first studied by Sandel (cf. [6]) and further popularized by Sabin (cf. [7]), require input data for the two end points and the corresponding tangents, thus having one degree of freedom for positioning the breakpoint. Usually, biarcs algorithms fit biarcs or single arcs between selected pairs of points and use the connecting line segments of each two corresponding points for the tangent data (e.g. [8,9]). Algorithms which guarantee that the resulting arc spline lies within a user-specified tolerance from the original points typically use geometric approaches. The canonical shape of a tolerance zone to a polygonal curve of width ε is given by the set of points which have a Euclidean distance of at most ε . Held and Eibl introduce both symmetric and asymmetric tolerance zones and use Voronoi diagrams for their generation, see [5]. Under the restriction that breakpoints are original points, Drysdale et al. showed in [4] an algorithm for approximating an open polygonal curve with a minimal number of circular arcs and biarcs while remaining within a given tolerance region in O (n2 log(n)) runtime for an n-vertex input. Held et al. achieve a better runtime of O (n log(n)), whereas they lose the minimality of the number of biarcs (see [4,5,8]). Biarc methods are well established and are appropriate for various applications. However, there are cases where they suffer from the unnatural requirement that breakpoints and tangent data of the approximating arc spline have to be chosen from a given finite point set in advance. Fig. 1 shows an input polygon and an arc spline approximation consisting of one segment γ . As the distances of adjacent vertices are not constant, γ does not run through original points or the midpoints of two adjacent points. On the right-hand side a biarc approximation based on a frequently used heuristic proposed by [9]: The admissible tangent at a point p i is p −p p −p given by p i − p i−1 + p i+1 − p i . Independent on the chosen tangents, arcs and line segments starting at original points cannot i
i −1
i +1
i
cover more than a constant number of vertices. It is not hard to see that the input polygon and γ can be easily continued in an arbitrary manner. Given a biarc algorithm based on any admissible point and tangent data generation method yields a finite set of end points and tangents. Thus, for each biarc algorithm and n ∈ N we can construct a polygon with n vertices and can choose an ε such that this algorithm needs O (n) segments, whereas there exists a feasible solution which approximates the polygon with only one segment. In the depicted example γ is a line segment, but this is not crucial: It is not hard to imagine that γ and the input polygon can be slightly bent such that γ becomes an arc and the assertion above is still valid. Although this is a synthetic example, similar shapes can appear in practical applications: for instance, when extracting contours from pixel graphics. 1.3. Own work
In order to construct an arc spline approximation with the actual minimum number of segments, one has to determine the loci of breakpoints and to find a constructive approach for determining the particular segments. An algorithm for computing a so-called Smooth Minimum Arc Path (SMAP) for approximating an open polygonal curve is described in [1]. This approach deals with an approximation up to a given tolerance, which can vary locally. The approximation error is controlled by focusing on solutions staying inside a so-called tolerance channel. The tolerance zones described in [4,5,8] are simply examples for tolerance channels. Although tolerance channels can be formed by a comparatively broad class of bounding
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
265
curves, namely piecewise restricted analytic curves,1 for practical implementations they are typically given by a simple closed polygon or an arc spline. In addition, a source and a destination segment are fixed. Any smooth, i.e. G 1 -continuous arc spline staying inside the tolerance channel and connecting the source and destination segments with a minimal number of segments solves the problem and is called SMAP. Note that the SMAP-approach produces the solution, which has only one segment, indicated in Fig. 1. In case of polygonal tolerance channels, a worst case complexity of O (n2 ) for an input point set of size n can be shown. If one wants to abstain from smoothness, a Minimum Arc Path (MAP), i.e. a continuous, but not necessarily smooth arc spline having the minimal number of segments, can be computed in O (n2 ) time as well. 1.4. Our results We have developed an efficient algorithm that approximates a closed polygon within a user-specified tolerance by an arc spline having the minimal number of segments. Although the approach of [1] is not adapted to cyclic structures, as a tolerance channel has to be defined by a simple closed curve, we can adapt the algorithm for computing an MAP for our purposes. We introduce cyclic tolerance channels, which are more general than the tolerance zones described in [5]. Then, we present a greedy algorithm based on alternating sequences which computes an arc spline staying inside a cyclic tolerance channel having the minimal number of segments. The idea is to successively construct arcs passing through points which are on the boundary of the tolerance channel such that these points touch the arc alternately from the left and the right. These extremal arcs serve as efficient starting points where the channel can be forced open such that an MAP can be computed. In case of polygonal bounded tolerances we can show that computing such a Cyclic Minimum Arc Path (CMAP) needs O (n3 ) time for a closed polygon with n vertices. If it is acceptable to obtain not necessarily the optimum segment number but to have possibly one additional segment, we present an algorithm running in quadratic time. 1.5. Outline This paper is organized as follows. In Section 2 we summarize the approach of computing an MAP and introduce the notions of alternating sequences and windows, which are needed to understand our approach for computing a CMAP. Based on these results, in Section 3 we formalize the problem of computing a CMAP inside a cyclic tolerance channel and generalize the MAP algorithm for computing a CMAP. In Section 4 we present a short extract of our test results. Finally, further extensions and possible future work are discussed. 2. Minimum arc path In this section we consider the case where the tolerance region is given by a simple closed polygon. The methods needed for this case are described in [1]. Since many of these definitions and results, for instance the concept of alternating sequences are also needed in the cyclic case, they are presented next but first of all we introduce some elementary terms and definitions we want to use subsequently. 2.1. Basic definitions For a set A ⊂ R2 , ∂ A denotes the boundary of A, A and A ◦ its closure and interior, respectively. In our notation, arcs are connected and compact strict subsets of circles or lines containing more than one point. We consider lines as circles with infinite radius. Every oriented arc γ has exactly two endpoints, the starting point S (γ ) and the endpoint E (γ ). An arc spline is a simple or simple closed curve Γ , which is composed of pairwise distinct (oriented) arcs γ1 , . . . , γm . We call |Γ | := m the segment number of Γ . Throughout this section, let P be a simple closed polygon in R2 . The term polygon is used to denote the union of both the boundary and the interior of the corresponding polygonal Jordan curve. Let ∂ P be oriented counterclockwise; this orientation induces an orientation to every edge of P . Furthermore, let s and d be two disjoint edges of P . To keep the notation as simple as possible, we assume that the two vertices of s are convex, i.e. the interior angles are strictly smaller than 180◦ . The definitions for the general case can be found in [1]. Then ( P , s, d) is called tolerance channel and a Minimum Arc Path (MAP) is an arc spline starting at s, ending in d and staying in P with the minimal number of arcs. The counterclockwise polygonal path of P from E (s) to S (d) is denoted by P r and is called right polygonal subcurve. Analogously, P l is the clockwise polygonal path from S (s) to E (d) (cf. Fig. 2). Let M = ∅ be a subset of P . A point a ∈ P is said to be circularly visible from M (with respect to P ) if there exists an arc γ in P that has its starting point in M and ends in a. The set of all circularly visible points from M with respect to P is denoted by V ( M ).
1
Restricted analytic curves are curves which have analytic extensions, i.e. developable as power series. See [1] for an exact definition.
266
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
Fig. 2. Illustration of a left and right polygonal subcurve of a polygon P . The point a is circularly visible from s and
Fig. 3. Illustration of right restriction points a. The straight arrows indicate that which is illustrated by the bended arrows.
γ is a visibility arc of s.
γ is restricted from the right according to the corresponding orientation
For the further examination, we focus on the cases of M being the edge s or an arc in P with endpoints in P l \ d and P r \ d. An oriented arc γ as above, starting at a point of M, being maximally extended with respect to inclusion in the closure of the connected component of P \ M which includes d is called visibility arc of M (see Fig. 2). By definition all points on an arbitrary visibility arc are circularly visible. 2.2. Characterizations and algorithm As a circle is uniquely determined by three distinct points, one would intuitively say an arc has three degrees of freedom. Alternating sequences are used to characterize these degrees of freedom defining a visibility arc. Whenever an arc in a tolerance channel is in an ‘extremal’ position, its ‘variability’ is restricted by three alternating left and right restriction points. In fact, restriction points are points the visibility arc and ∂ P ∪ M have in common (cf. [1]). Hence restriction points can particularly appear at the starting point of γ . Let γ be a visibility arc and a be a point on γ and on the boundary of P or on M. The point a is called right restriction point (of γ with respect to M) if one of the following conditions holds:
• a is not an endpoint of γ and ∂ P is locally right of γ at a. • a ∈ M is the starting point of γ and M is locally left of γ at a. ‘M is locally left of γ ’ means that M lies in the closed region to the left of the circle or line containing γ and oriented as γ . The first two images in Fig. 3 illustrate the first case and Fig. 3(c) and (d) show the second one. Likewise, we can define left restriction points. In [1] it is shown that the boundary points of V ( M ) which do not belong to ∂ P (see Fig. 4) lie on arcs, and the corresponding visibility arcs are denoted by blocking arcs. These arcs distinguish themselves from the other visibility arcs as they have at least three alternating restriction points. Three restriction points of a visibility arc, ordered as a1 , a2 and a3 are called alternating if a1 and a3 are left restriction points and a2 is a right restriction point or a1 and a3 are right restriction points and a2 is a left restriction point. Examples of alternating restriction points can be found in Fig. 5. Arcs passing through three alternating restriction points can be described in an efficient manner regarding to an algorithmic approach as they are uniquely determine the three degrees of freedom an arc has. This is closely related to the well-known Apollonius’ Problem: Given three objects, each of which may be a point, line or circle, draw a circle that is tangent to each. There are
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
267
Fig. 4. Illustration of the visibility set V ( M ). The portion that is not circularly visible from M is shaded. The corresponding connected components are denoted by C 1 , C 2 , C 3 , C ∗ . In this example we have s = M. The dashed arcs γ1 , γ2 , γ3 , γ ( M ) are the blocking arcs of V ( M ) and the solid part of γ ( M ) illustrates the window ω( M ).
Fig. 5. Illustration of Theorem 1; several configurations of alternating restriction points are shown.
a total of ten cases having at most eight solutions (e.g. [10]). Then it is not hard to show that we obtain at most one arc satisfying the same conditions, staying inside P and starting from M. For every connected component C i of P \ V ( M ) there exists exactly one corresponding blocking arc γi (see Fig. 4). If d is not circularly visible from M, there exists a connected component C ∗ containing d. The subset γ∗ ∩ C ∗ of the corresponding blocking defines an arc ω called window (with respect to M), where C ∗ denotes the closure of C ∗ . In this case, we say that γ∗ is associated with ω and we use the notations: ω( M ) := ω , γ ( M ) := γ∗ . For convex start vertices the following theorem holds (cf. [1]): Theorem 1. Let γ be a blocking arc of V ( M ) with endpoint v ∈ P l . Then γ is associated with the window ω( M ) if and only if there are three alternating restriction points a1 , a2 , a3 with a1 , a3 ∈ P r and a2 ∈ P l . Similar conditions hold if v ∈ P r . (All possible cases are illustrated in Fig. 5.) Remark 1. If M is a singleton, for instance a vertex v of P , the window ω( v ) := ω( M ) is defined by two alternating restriction points a1 , a2 and the end point a3 s.t. a1 , a3 ∈ K l and a2 ∈ K r or vice versa (cf. [1]). Setting s = M we are able to efficiently describe the set of points which can be reached by only one arc. In particular, we can uniquely determine the visibility arc γ (s), which runs furthest in direction of d in comparison to all the other visibility arcs. It turned out that we can use the same results to compute a whole MAP. Although there might exist more than only one MAP, the minimal number of arcs is unique. We focus on the construction of an MAP that is defined by a sequence of alternating restriction points as we successively compute windows ωi for different segments M as follows: The algorithm first computes the window with respect to the starting edge M = s, denoted by ω1 . Until d is visible, the windows ωi +1 with respect to their predecessors M = ωi are computed iteratively. In [1] it is shown that the resulting sequence of arcs
268
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
Fig. 6. Constructive approach. MAP with four arcs.
Algorithm 1 Minimum arc path. Require: Tolerance Channel ( P , s, d) Ensure: List of arcs defining an MAP ω0 ← s i←0 while d ∩ V (ωi ) = ∅ do ωi +1 ← window with respect to ωi γi ← associated blocking arc Add γi to the segments of Γ i←i+1 end while Add a visibility arc joining ωi and d to Γ return Γ
ω1 , . . . , ωk defines an arc spline which is indeed an MAP. Thus, all we need to do for computing an MAP is to calculate windows successively, which can be efficiently determined by restriction points until d is circularly visible. The whole strategy is summarized in Algorithm 1. In order to understand better how the algorithm works, see the following example: Example 2. Let us consider the situation in Fig. 6. By examining different constellations of restriction points as listed above, Algorithm 1 first computes the window ω1 with respect to s. In this case, three vertices yield the desired arc. Likewise, we obtain ω2 := ω(ω1 ) and ω3 := ω(ω2 ). In the next step, d is circularly visible and a connecting segment ω4 can be constructed by two alternating restriction points s.t. it passes through a vertex of d. Having shrunken the corresponding arcs, we obtain an MAP with 4 segments. Now the question arises how we can efficiently implement Algorithm 1, i.e. how to determine the several windows in an efficient manner. In general, the particular windows have at least three distinct alternating restriction points, and therefore they can be determined by
• three vertices, • two vertices and one edge or • one vertex and two edges, if we assume a polygonal tolerance channel. An exemplary situation is illustrated in Fig. 5. The case of three edges does not occur since a circle cannot be touched by an edge from the inner side. The best known running time for the MAP problem in case of polygonal tolerance channels is O (n2 ), where n is the number of vertices of the simple polygon (see [1]). The proposed implementation uses Circular Visibility Diagrams (CVD) to compute the windows ω1 , . . . , ωk . We will use CVDs as a black box in the following and refer readers to [11] for a detailed description. 3. The cyclic case The main aim of this paper is to tackle the problem of approximating a closed polygon from a given point set within a user-specified tolerance, by an arc spline having a minimum number of segments. As it sounds similar to the problem of computing an MAP, we call a solution of the ‘cyclic case’ a Cyclic Minimum Arc Path (CMAP). We are able to trace the problem of computing a CMAP back to an MAP computation of some suitable tolerance channels. According to tolerance channels we
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
269
Fig. 7. Cyclic tolerance channel.
introduce cyclic tolerance channels and present an algorithm for computing a CMAP. If we accept a solution with a segment number which is not necessarily minimal but having at most one additional segment, we can get an approximating arc spline in O (n2 ). 3.1. Cyclic tolerance channel In order to use the terminology and methodology presented in Section 2, we can adapt the term tolerance channel to the cyclic case as well. For the sake of simplicity let us deal with polygonal tolerance channels in the sequel though we could expand this term to piecewise restricted analytic curves. Let P and Q be two closed polygons with P ⊂ Q ◦ . Let K := Q \ P , K l := ∂ Q and K r := ∂ P . Hence we have K l ∪ K r = ∂ K . Then we call K a cyclic tolerance channel. An example is visualized in Fig. 7. Again, we refer the reader to [8,5] to have examples for the development of a suitable cyclic tolerance channel. A Cyclic Minimum Arc Path (CMAP) is a closed arc spline which encloses K r and has the minimum number of segments. In particular, circles are closed arc splines having one segment. Fig. 7 shows an example of an arc spline enclosing K r . It is not hard to prove that for every cyclic tolerance channel there exists a CMAP since the set of all arc spline enclosing K r in K is not empty and the segment number is a natural number. Analogous to the (S)MAP computation a CMAP is not unique but its segment number surely is. 3.2. The computation of a CMAP First of all, we have to check if one segment suffices for approximation, i.e. we have to check if K contains any nontrivial circles. Non-trivial means in this context that the circle encloses K r . This can be checked in linear time for instance by applying the method of [12]. Let us suppose to have the non-trivial case, i.e. the minimum number of segments is at least two. As we want to use the techniques developed for the MAP computation, we want to derive a suitable non-cyclic tolerance channel from K . We cannot simply choose a line segment s connecting K l and K r s.t. K \ s is simply connected since ∂ K ∪ s does not yield a tolerance channel since ∂ K ∪ s is not representable as a simple closed curve. Therefore, we propose to choose an extremal arc of K as starting segment. According to the definition of windows of ordinary tolerance channels we call an oriented arc γ extremal if
• it is maximally extended with respect to inclusion in K ; • it runs through some points a1 , a3 ∈ K r and a2 , a4 ∈ K l or vice versa, where a4 is the end point and the ai are ordered according to the orientation of
γ;
• a1 , a3 and a2 , a4 are increasingly order regarding the clockwise orientation of K l and K r , respectively. An example is shown in Fig. 8. We call (a1 , a2 , a3 ) an alternating sequence. Furthermore, an oriented arc is said to correspond to an extremal arc η if it is equal to η after maximal extension in K . By searching for arcs which have at least two points in common with K l and one with K r or the other way around, we can identify the extremal arcs of K . As we want to use the techniques for computing an MAP we define a tolerance channel K η given by η in the sense of Section 2 as follows: Let η be such an extremal arc of K with an alternating sequence (a1 , a2 , a3 ). Then K η is given by the connected component of K \ η which is bounded by the portion s of η between the last restriction point a3 and the end point a4 , and the portion d between the starting point S (η) and the restriction point a2 . Since (a1 , a2 , a3 ) is alternating and the end point a4 of η is at the opposite side of a3 the described approach yields indeed a tolerance zone which is bounded by a simple closed curve. Thus, choosing s and d as the start and the destination segment of K η we obtain a tolerance channel (cf. Fig. 8). Generally, K η is not a polygonal tolerance channel as the ‘edges’ s and d are arcs and therefore not necessarily line segments. However, the results and the complexity bound introduced in Section 2 for this slightly modified version are still valid. A proof can be found in [1].
270
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
Fig. 8. Cyclic tolerance channel K with extremal arc
η (left) and the corresponding tolerance channel K η (right).
Theorem 2. Let η be an extremal arc of K and let Ω be an MAP of K η . Let the number of segments of any CMAP be denoted by k. Then ˜ defined by η and the segments of Ω encloses K r and we have |Ω| ˜ k + 1. the arc spline Ω
˜ encloses K r . As Ω is an MAP of K η , any restriction of a CMAP to K η has at least |Ω| segments, i.e. Proof. By definition Ω ˜ |Ω| + 1 k + 1. 2 |Ω| k. By definition we have |Ω| Thus, we can guarantee the minimal possible number of segments needed for a CMAP up to one segment but not necessarily the actual minimum. Whether we really achieve the minimum number or not depends on the choice of the starting extremal arc η . Therefore, we will prove that there exists an extremal arc s.t. the approach presented above yields a CMAP. For this purpose, we first have to deal with some technical details in advance. Lemma 3. Let γ1 and γ2 be two disjoint arcs in K having non-empty intersections with K l and K r . If there exists another arc γ0 with S (γ0 ) ∈ γ1 and E (γ0 ) ∈ γ2 , there exits an extremal arc η of K cutting both of them, i.e. η ∩ γ1 = ∅ = η ∩ γ2 . Proof. Since the intersections K l ∩ γi and K r ∩ γi are not empty for i = 1, 2, there is a tolerance channel P ⊂ K including all γi (i = 0, 1, 2) such that the maximal extension of γ0 intersects the corresponding start segment s and the window η of s in P cuts both γ1 and γ2 . Some possibly tedious manipulation of P yields a window η which satisfies the same conditions, has neither a restriction point on s nor on the corresponding destination segment d. Therefore, the maximal extension of η in K is an extremal arc of K . 2 Lemma 4. There exists a CMAP having a segment which corresponds to an extremal arc of K . Proof. Let Ω be an arbitrary CMAP with segments ω1 , . . . , ωk . We can assume k > 2 as we do not deal with the trivial case (k = 1) here and the case k = 2 is straightforward to show. Using a simple continuity argument, we can even assume that every segment ω j ( j = 1, . . . , k) has intersections with both K l and K r . Applying Lemma 3, there exists an extremal arc γi in K s.t. γi ∩ ωi −1 = ∅ = γi ∩ ωi +1 . After a possible shrinking of γi at the intersection points with ωi −1 and ωi +1 , the arc spline defined by ω1 , . . . , ωi −1 , γi and ωi −1 , . . . , ωk is a CMAP. 2 Lemma 5. Let Γ be a CMAP of K having a segment which corresponds to an extremal arc η of K . Then, for every MAP Ω of K η , the arc spline defined by η and Ω is a CMAP. Proof. Let us denote the segments of Γ by γ1 , . . . , γk and let γi be the arc corresponding to η . Then it suffices to prove that |Ω| k − 1. Obviously, the arc spline given by γi +1 , . . . , γk and γ1 , . . . , γi −1 stays in K η , starts at s and ends in d, where s is the starting segment and d is the destination segment of K η . Since Ω is an MAP, we have |Ω| k − 1. 2 Now we have shown all necessary conditions to prove the following theorem, where we show the existence of a CMAP which is deduced from an extremal arc and a corresponding MAP. This justifies the algorithmic approach we propose in the next section and shows its correctness. Theorem 6. There is an extremal arc η in K s.t. the arc spline defined by η and Ω is a CMAP, where Ω is an MAP with respect to K η . Proof. By Lemma 4 there exists a CMAP having a segment whose corresponding maximal arc Applying Lemma 5 concludes the proof. 2
η is an extremal arc of K .
It remains to show how to obtain extremal arcs for a cyclic tolerance channel K . We will prove that all extremal arcs of K can be computed by examining windows in suitable tolerance channels being contained in K . For each edge e in K
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
271
Fig. 9. Cyclic tolerance channel K and the simple polygon K e (non-shaded) for the two cases. The straight line g is shown dashed.
a tolerance channel K e is computed. For this purpose, we construct a line g intersecting K l and K r and compute a proper line segment defined by the resulting intersection points. Then a stripe containing this line segment is removed from K . Let K l and K r be oriented clockwise and e be an arbitrary edge of K . For defining g we consider two cases. If e ∈ K r , let g be the line which contains e and is ordered according to e. Since P ⊂ Q ◦ , g has at least two intersections with K l . In particular, we have intersections v and w with both K r and K l before the start point of e such that the straight line from v to w is completely inside K . If e is an edge of K l , let g be the straight line passing through the start point of e and the closest vertex a of K r . This line g defines two half planes E + and E − , where e lies in the half plane E + . If for a neighborhood V of a the set V ∩ K r lies completely in E + , let w be the next intersection point of g and K such that there is no neighborhood U of w with U ∩ ∂ K lies in one halfplane defined by g. If w ∈ K r let v ∈ K l (or vice versa) be the closest point to w on g between w and S (e ) such that the straight line from v to w is completely inside K . If V ∩ K r lies completely in E − or in both half planes, then set w = a and v = S (e ). Let
ε=
1 2
· min
min
u vertex of K , u ∈ /g
dist(u , g ), dist H ( K l , K r ) ,
where dist and dist H denote the Euclidean distance and the Hausdorff distance, respectively. Removing a stripe of width ε defined by the line segment from v to w we obtain a simple polygon K e ⊂ K (see Fig. 9). First we consider the case e ∈ K r . If the line segment connecting w and S (e ) is not completely inside K this stripe lies in the half plane defined by g and the normal vector pointing inside the tolerance channel. Then d is the straight line from v to w. Otherwise, the stripe lies in the other halfplane and d is the opposite line segment of the stripe. Next we consider the case e ∈ K l . If the line segment connecting w and S (e ) is not completely inside K or v = S (e ) the stripe does not lie in the halfplane where e lies. Then d is the straight line from v to w. Otherwise, the stripe lies in the same halfplane where e lies and d is the opposite line segment of the stripe. We are now in the position to show the connection between extremal arcs and windows of tolerance channels K e for the edges e of K . On the one hand, each edge e yields a unique tolerance channel K e . On the other hand, each extremal arc belongs to exactly one edge: An extremal arc η is said to belong to the edge e of K if S (η) ∈ e \ { S (e )} in case of e ⊂ K l and S (η) ∈ e \ { E (e )} in case of e ⊂ K r . By construction, the restriction η˜ of η to K e is a visibility arc of e and the points of η˜ in K l and K r are left and right restriction points in K e . We are now in the position to show the connection between an extremal arc which belongs to an edge e and the window of the tolerance channel K e . Theorem 7. Let η be an extremal arc belonging to an edge e. Case 1: d ∩ η = ∅. Then the window ω(e ) (build within K e ) corresponds to η . Case 2: d ∩ η = ∅. Then there is an edge e ∗ of K r and the window ω( S (e ∗ )) (build within K e∗ ) corresponds to sequence of η lies in K e .
η or the alternating
Proof. If d ∩ η = ∅, then η is included in K e and by definition of η and K e from Theorem 1 it follows that the associated blocking arc of the window ω(e ) equals η . Next we show that the assumption d ∩ η = ∅ implies e ∈ K l . Let us assume to the contrary that e ∈ K r . Then the defining line g which is used for constructing K e contains e. As P ⊂ Q ◦ there are at least two disjoint line segments in ( K ∩ g ) \ e. Then η must pass through these line segments. Since S (η) = E (e ) there must be at least three intersections between η and g, a contradiction. Thus, e belongs to K l . Since η is an extremal arc, it runs through some points a1 , a3 ∈ K r and a2 , a4 ∈ K l or vice versa, where a4 is the end point and the ai are ordered according to the orientation of η . If η runs through some points a1 , a3 ∈ K r and a2 , a4 ∈ K l , where a4 is the end point, then a1 is a right restriction point of η . Let e ∗ be the edge of K r where the start point of e ∗ is a1 . In [1] it is shown that there is a blocking arc of ω(a1 ) with restriction points on K l and K r in K e∗ . Thus, the window ω(a1 ) corresponds to η .
272
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
Next we consider the case a1 , a3 ∈ K l and a2 , a4 ∈ K r . If a4 ∈ d, then the alternating sequence (a1 , a2 , a3 ) must lie in K e . Otherwise, the intersection point between d and η lies before a4 . If the line segment connecting w and S (e ) is not completely inside K , then for every intersection point x between the line segment from w to S (e ) and K r there is a neighborhood U of x such that U ∩ ∂ K lies in one half plane defined by the line g (used for construction K e ). Thus, there is no point (except on d) of K r inside the removed stripe. Therefore, this case cannot appear. Hence the line segment connecting w and S (e ) lies completely inside K and d is the opposite line segment of the straight line from v to w. Likewise, for every intersection point x between the line segment from w to S (e ) and K r there is a neighborhood U of x such that U ∩∂ K lies in one half plane defined by the line g (used for constructing K e ). Consequently, the end point a4 lies in the removed stripe. As dist(a3 , a4 ) dist H ( K l , K r ) > ε , the subset of η from S (η) to a3 must be in K e . 2 Due to Theorem 7 we obtain all extremal arcs if we compute the windows for all vertices v of K r .
ω(e ) of all edges e of K and the windows ω( v )
3.3. Algorithm and complexity analysis Suppose that a closed polygon with n vertices should be approximated. First we have to develop a cyclic tolerance channel ensuring a maximum deviation ε given by a user-specified tolerance. If we can be sure that a usual ε -offset channel doesn’t yield any self intersections, we can compute such a channel in O (n). Otherwise, the Voronoi based method presented in [5] results in an O (n log(n)) runtime. Additionally, in order to guarantee that the curve remains close to the given points, i.e. to actually ensure a resulting Hausdorff distance of the CMAP to the input points, we integrate offset spikes at sharp corners (cf. [4,5]). In any case, the output channel has O (n) vertices. Without loss of generality we can assume that the resulting cyclic tolerance channel K has n vertices. The strategy for computing an arc spline with possibly one more segment in contrast to the minimally possible number is summarized in Algorithm 2. As the minimum number k is greater than one, we have to elucidate how we can choose an extremal arc of K : For this purpose, let e be an arbitrary edge of K r . Then the simple polygon K e can be computed in O (n) time. We obtain an extremal arc η by computing the associated blocking arc of ω(e ) with respect to K e which needs O (n2 ) time. Algorithm 2 Cyclic minimum arc path – light. Require: Cyclic Tolerance Channel K Ensure: List of oriented arcs defining a closed arc spline if there exists a circle C separating K l from K r then return C end if Compute tolerance channel K e for arbitrary edge e of K r γ (e) ← blocking arc associated with ω(e) η ← extremal arc corresponding to γ (e) Compute Tolerance Channel K η Ω ← MAP of K η computed by Algorithm 1 Add η to the segments of Ω return Ω
Having computed an extremal arc η , we propose to compute the tolerance channel K η , which can be done in O (1). Applying Algorithm 1 to this channel yields an MAP and Theorem 2 shows the correctness of Algorithm 2. Since the MAP computation needs O (n2 ) time as well, the total time complexity of Algorithm 2 is still O (n2 ). Similar to the observation for the MAP algorithm the procedure leads to an O (kn)-time algorithm, where k is the number of CVDs computed. In the worst case, k can only be bounded by n. However, in many test scenarios we discovered a subquadratic runtime. The method for computing an arc spline with the minimally possible number of segments is summarized in Algorithm 3. Let us still assume the non-trivial case. According to Lemma 5 we then search not for any extremal arc in K but for one which corresponds to a single segment of a CMAP. Theorem 7 shows that we obtain all extremal arcs if we consider all edges e of K and possibly all vertices of K r (cf. Case 2). The number of edges and vertices in K and thus the number of extremal arcs is O (n). Due to Theorem 6 we can be sure that applying Algorithm 2 for sufficiently many extremal arcs provides a CMAP. In the worst case, we have to consider all extremal arcs and thus the total time complexity for Algorithm 3 is O (n · n2 ) = O (n3 ). Nevertheless, the algorithm stops if the segment number in the current step differs from the one computed in the predecessor step. Hence we can specify an efficient stop criterion. 4. Experimental results We have tested our algorithmic approach for CMAP computation on various test data, in particular on contours with different shape and size. Four examples are presented in Fig. 10. The first three figures are images taken from
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
273
Algorithm 3 Cyclic minimum arc path. Require: Cyclic Tolerance Channel K Ensure: List of oriented arcs defining a CMAP visible_flag ← FALSE Γ ← arc spline computed by Algorithm 2 for all edges e of K do if d is visible from the edge e of K e then visible_flag ← TRUE end if η ← extremal arc in K starting from e {see Algorithm 2} Ω ← MAP of K η computed by Algorithm 1 if |Ω| + 1 < |Γ | then Add η to the segments of Ω return Ω end if if |Γ | < |Ω| + 1 then return Γ end if end for if visible_flag is TRUE then for all vertices v of K r do η ← extremal arc in K starting from v Ω ← MAP of K η computed by Algorithm 1 if |Ω| + 1 < |Γ | then Add η to the segments of Ω return Ω end if if |Γ | < |Ω| + 1 then return Γ end if end for end if return Γ
Fig. 10. Synthetic test images (top) with contour point lists and the results of the proposed algorithm for are (from left to right) k = 67, k = 64, k = 40 and k = 40.
ε = 0.5. The corresponding number of segments
http://www.pdclipart.org/. For this sort of test data we extracted the contours of the images and approximated them with a CMAP. To extract edges from the binary images we applied the Canny edge detector, which produces a sorted list of pixels representing the contour (cf. [13]). The fourth picture is an example of a contour representing the second class of data we tested, which were kindly provided by A. Kolesnikov. In [14] these data were used for vectorization of pixel images based on a polynomial spline approximation. Overall we analyzed the resulting segment numbers for 53 contours, which are represented by a point list of roughly a size of n = 50 to n = 3000, and tolerances ranging in the pixel interval [0.1, 2.0]. For each input contour and tolerance ε we constructed a cyclic tolerance channel and then applied the proposed algorithm. As for the chosen tolerances the offset curves of the input polygons doesn’t lead to any self intersections, overlapping or other critical effects, we simply computed an (symmetric) offset channel with width 2ε . Then we approximated the appearing arc segments by some line segments in order to obtain a polygonal representation. In addition, we inserted offset spikes (e.g. [5]) at sharp corners in order to ensure that the polygonal offset curve is not further away from the input polygon P than ε . In the bottom of Fig. 10 we can see the CMAPs computed for the four examples in the top. For each approximation we have chosen a tolerance of roughly half a pixel, which is a reasonable tolerance for this sort of input points as they are
274
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
Fig. 11. Tolerance
ε versus number of segments k for the synthetic test images of Fig. 10.
extracted from pixel images. Besides, the third image (bat) reveals one shortcoming of the proposed algorithm. Till now we did not integrate side conditions, like for instance symmetry, in our computations. Although the original image of this bat is obviously axially symmetric, the resulting CMAP is not. Certainly, the smaller the tolerance the less the asymmetry impinges upon the approximation. However, we cannot guarantee to obtain a symmetric arc spline approximation for any tolerance. Fig. 11 summarizes the results of our algorithm for the test images illustrated in Fig. 10. Note that we show the number of segments only for some ε in order to make the diagram easier to read. For the remaining test data we could establish a similar behavior of the ratio ‘tolerance vs. segment number’ but did not display them for clarity reasons. In any case, we can observe the unsurprising fact that the displayed graph corresponds to a monotonically decreasing function. Since the contours were extracted from pixel images without any scaling, tolerances below 0.3 pixels seem not to be reasonable, which is confirmed by the depicted segment numbers. They increase by leaps and bounds for tolerances between 0.1 and 0.3 pixels. This is comprehensible since in this case the tolerance is considerably smaller than the average distance between adjacent contour points. 5. Conclusion In this paper, we have presented a method for approximating closed polygons by arc splines guaranteeing the minimum number of segments for any user-specified tolerance. Note that we achieve the actual minimum number since the breakpoints of the resulting arc spline are not restricted to any pre-defined set of points but are generated automatically. Obviously, a restriction of the loci of the particular breakpoints can have a considerable impact on the segment number. However, having a preferably low number of segments is decisive for numerous applications as this results in a compact representation and a more efficient noise reduction. Most important, a minimum number of segments provides a considerably faster computation of point-to-curve distances. In particular, we have introduced Cyclic Minimum Arc Paths (CMAP), which are arc splines having a minimum number of segments inside a so-called cyclic tolerance channel. This channel is used to represent the approximation tolerance of the input set of points or polygon, respectively. Cyclic tolerance channels are a comparatively general construct as they can be build by piecewise restricted analytic curves although for practical belongs polygons mostly seem to be sufficient. In case of a polygonal bounded tolerances we can ensure a worst case complexity of O (n3 ) for n input points. However, we are able to specify a very efficient stop criterion. If one accepts to have possibly one additional segment, a solution can be provided in O (kn) = O (n2 ) time, where k is the number of CVDs computed. Although we can easily construct an example, which really needs quadratic runtime, we could observe that k is considerably smaller than n for non-synthetic test data. We conclude by mentioning possible research avenues for future work. As many applications need smooth curve encodings, the next step would be to require smoothness at the breakpoints of the resulting curve. In our notation that would lead to a Smooth Cyclic Minimum Arc Path (SCMAP). Similar to the approach introduced in this paper, we are confident of generalizing the SMAP algorithm (see [1]) to obtain a SCMAP when using extremal arcs as well. However, the problem that the ‘last’ and ‘first’ segment of a SCMAP have to be joined not only in continuous but in smooth manner remains.
G. Maier, G. Pisinger / Computational Geometry 46 (2013) 263–275
275
References [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]
G. Maier, Smooth Minimum Arc Paths. Contour Approximation with Smooth Arc Splines, Shaker, Aachen, 2010. X. Yang, Efficient circular arc interpolation based on active tolerance control, Computer Aided Design 34 (2002) 1037–1046. D.S. Meek, D.J. Walton, Approximating smooth planar curves by arc splines, Journal of Computational and Applied Mathematics 59 (1) (1995) 221–231. R. Drysdale, G. Rote, A. Sturm, Approximation of an open polygonal curve with a minimum number of circular arcs and biarcs, Computational Geometry 41 (2008) 31–47. M. Heimlich, M. Held, Biarc approximation, simplification and smoothing of polygonal curves by means of Voronoi-based tolerance bands, International Journal of Computational Geometry and Applications 18 (3) (2008) 221–250. G.D. Sandel, Zur Geometrie der Korbbögen, ZAMM – Journal of Applied Mathematics and Mechanics / Zeitschrift für Angewandte Mathematik und Mechanik 17 (5) (1937) 301–302. M.A. Sabin, The use of piecewise forms for the numerical representation of shape, Ph.D. thesis, Computer and Automation Institute, Hungarian Academy of Sciences, Budapest, 1977. M. Held, J. Eibl, Biarc approximation of polygons within asymmetric tolerance bands, Computer Aided Design 37 (4) (2005) 357–371. D.S. Meek, D.J. Walton, Approximation of discrete data by G 1 arc splines, Computer Aided Design 24 (6) (1992) 301–306. C.B. Boyer, A History of Mathematics, Wiley, New York, 1968. S.-Y. Chou, T.C. Woo, A linear-time algorithm for constructing a circular visibility diagram, Algorithmica 14 (1995) 203–228. J.-D. Boissonnat, J. Czyzowicz, O. Devillers, M. Yvinec, Circular separability of polygons, Algorithmica 30 (2001) 67–82. J. Canny, A computational approach to edge detection, IEEE Transactions on Pattern Analysis and Machine Intelligence 8 (6) (1986) 679–698. A. Kolesnikov, Approximation of digitized curves with cubic Bézier splines, in: ICIP, 2010, pp. 4285–4288.