Comparison of the different algorithms for Polygon Boolean operations.
Michael Leonov 1998
Http://www.angusj.com/delphi/clipper.php#screenshots
Http://www.complex-a5.ru/polyboolean/comp.html
Http://www.angusj.com/delphi/clipper.php#screenshots
Introduction
When writing my BS degree work I tested the following software libraries for speed and robustness of performing polygon Boolean Operations:
Library name |
Principal Author |
Language |
Boolean (v.1.34) |
Klaas Holwerda |
C++ |
Boolean Operations on polygons (v. 2.0) (BOPS) |
Matej Gombosi |
C++ |
Cgal (R. 1.1) |
Joint Project of 7 sites |
C++ |
Clippoly (pl. 7) |
Klamer Schutte |
C++ |
Constructive Planar Geometry (CPG) |
Dave Eberly |
C++ |
GPC (v.2.22) |
Alan Murta |
C |
LEDA (v.r-3.6.1) |
Max-planck-institut fuer Informatik |
C++ |
Polyboolean v0.0 |
Michael Leonov, Alexey Nikitin |
C++ |
Capabilities
Library |
| and
SUB |
OR |
XOR |
HOLES |
KH I |
SI |
DV |
KH O |
boolean |
+ |
+ |
+ |
+ |
+ |
+ |
- |
+ |
+ |
bops |
+ |
- |
+ |
- |
+ |
- |
- |
- |
+ |
cgal |
+ |
+ |
+ |
- |
- |
- |
- |
- |
- |
clippoly |
+ |
+ |
- |
- |
- |
- |
- |
- |
- |
cpg |
+ |
+ |
+ |
+ |
+ |
- |
- |
+ |
- |
GPC |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
- |
leda |
+ |
+ |
+ |
+ |
+ |
- |
- |
+ |
- |
Polyboolean |
+ |
+ |
+ |
+ |
+ |
+ |
- |
+ |
- |
First 4 columns denote supported Boolean operations. HOLES means that a library can handle polygons with HOLES. KH I means that a library can handle polygons with ' keyholed ' edges, which is sometimes used to describe a pol Ygon with holes by means of single contour. SI means that a library allows self-intersecting polygons on its input. DV means that a library supports polygons with vertices of high degree, i.e. self-touching polygons. KH O means that a library's output can contain keyholed edges (I think this is the library ' s disadvantage).
Speed
for testing I used PC with CPU Pentium II (233 MHz) and 96Mb RAM running Windows N T Workstation 4.0 SP4. All source code is compiled with microsoft Visual C + + 6.0 using the same alignment (8 bytes) and optimization Optio ns. Sample polygons were extracted from True Type Font contours using different levels of Bézier curves Polygo NAL approximation. The test program is executed 5 times for every Boolean operation. The results is summarized in the table below (N denotes the total number of vertices in input polygons, all timings are measured in seconds, best times for each N is bold):
Library |
n=3885 |
n=7076 |
n=20190 |
n=69839 |
n=174239 |
Boolean |
1.084 |
1.773 |
5.923 |
23.219 |
65.927 |
Clippoly |
15.482 |
51.965 |
487.942 |
... |
... |
Gpc |
0.160 |
0.381 |
8.570 |
64.463 |
133.670 |
LEDA |
0.806 |
1.422 |
3.801 |
16.636 |
... |
Polyboolean |
0.158 |
0.255 |
0.721 |
3.532 |
16.011 |
For n=69839, 174239 clippoly caused stacks overflow due to the O (N) recursion depth. For n=174239 LEDA caused memory overflow (despite the presence of the extra MB of virtual memory) due to the Extensive use of the rational ariphmetic.
Like clippoly, cgal and CPG has quadratic running time. BOPS produced incorrect results on test polygons so I do not include its timings.
Numerical Robustness
Most of the programs listed above is not strictly robust and use floating point arithmetic with some tolerance values. cgal, CPG and LEDA use exact rational arithmetic to achieve robustness. In this case, required memory size grows exponentially with a number of cascaded operations, and this seems not to be SA Tisfactory for practical applications. Polyboolean uses John Hobby ' s rounding cell technique to avoid extraneous intersections and is therefore complet Ely Robust. Boolean also rounds the intersection points to the integer grid and then repeats until no new intersection points is found.
References
Algorithm used in Boolean was described in [Holwerda 98]. Some additional information can be found in [Preparata and Shamos] (a must-have computational Geometry book).
Algorithm used in BOPS are described in [Zalik, Gombosi and Podgorelec 98].
Algorithm used in Cgal are not documented.
Algorithm used in Clippoly are described in [Schutte 94] and [Schutte 95].
Algorithm used in CPG are described in [Eberly 98].
GPC uses a modified version of [Vatti 92]. Implementation details is discussed in [Murta 98]. Alan Murta is currently working on a paper describing GPC.
Polygon Boolean algorithm used in LEDA are not documented by itself. The segment intersection part was described in [Mehlhorn and Naher 94].
Polygon Boolean algorithm used in Polyboolean are described in [Leonov and Nikitin 97]. Additional algorithmic and implementation issues is discussed in [Leonov 98]. The segment intersection part was based on [Bentley and Ottmann] and [Hobby 99].
-
-
Bentley and Ottmann 1979
-
- J. L. Bentley and T. A. Ottmann. Algorithms for reporting and counting geometric intersections.
IEEE Trans. Comput., c-28:643-647, 1979.
-
-
Eberly 1998
-
- D. Eberly. Polysolids and Boolean Operations.
-
-
Hobby 1999
-
- J. Hobby. Practical segment intersection with finite precision output. Computation Geometry theory and Applications,
(4), 1999.
-
-
Holwerda 1998
-
- K. Holwerda et al complete Boolean Description.
-
-
Leonov and Nikitin 1997
-
- M. v. Leonov and A. G. Nikitin. An efficient algorithm for a Closed Set of Boolean Operations on polygonal regions in the Plane (draft 中文版 TRANSLA tion).
A. P. Ershov Institute of Informatics Systems, Preprint, 1997.
-
-
Leonov 1998
-
- M. v. Leonov. Implementation of Boolean operations on sets of polygons in the plane (in Russian).
BS thesis, Novosibirsk State University, 1998.
-
-
Mehlhorn and Naher 1994
-
- K. Mehlhorn and S. Naher. Implementation of a Sweep line algorithm for the straight line Segment intersection problem.
max-planck-institut fur Informatik, mpi-i-94-160, 1994.
-
-
Murta 1998
-
- A. Murta. A Generic Polygon Clipping Library.
-
-
Preparata and Shamos 1985
-
- F. P. preparata and M. I. Shamos.
Computational Geometry:an Introduction. Springer-verlag, New York, NY, 1985
-
-
Schutte 1994
-
- K. Schutte. Knowledge Based recognition of man-made Objects.
PhD thesis, University of Twente, 1994. Isbn90-9006902-x.
-
-
Schutte 1995
-
- K. Schutte. An edge labeling approach to concave polygon clipping. Manuscript, 1995.
-
-
Vatti 1992
-
- B. R. Vatti. A generic solution to polygon clipping.
Commun. ACM, + (7): 56-63, 1992.
-
-
Zalik, Gombosi and Podgorelec 1998
-
- B. Zalik, M. Gombosi and D. Podgorelec. A Quick intersection algorithm for arbitrary polygons. In L. Szirmay-kalos (Ed.),
SCCG98 Conf. On Comput. Graphics and it ' s applicat., 195-204, 1998. ISBN 80-223-0837-4.
Conclusions
All tested libraries is very good for educational purposes and for studying different approaches to the polygon Boolean Operations. Polyboolean, Boolean and GPC are probably the fastest publicly available libraries. The correct rounding of intersection points is performed only in Polyboolean and Boolean. Of course, all these opinions is only mine, and I don ' t attempt-make strong assertions about usefulness of these pro Grams. Click here to get the polygons I used for testing. Soon I'll make the source code of the "Test program" (with all necessary modifications of the tested libraries) publicly Available.
Algorithm Comparison of the different algorithms for Polygon Boolean operations