[算法]Comparison of the different algorithms for Polygon Boolean operations

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 are sometimes used to describe a  polygon with holes by means of single contour. SI means that a library  allows self-intersecting polygons at 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 NT Workstation 4.0 SP4. All source code was compiled with Microsoft  Visual C++ 6.0 using the same alignment (8 bytes) and optimization options.  Sample polygons were extracted from True Type Font contours using different  levels of Bezier curves polygonal approximation. The test program was executed 5  times for every Boolean operation. The results are 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 are 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 stack overflow due to the O(N)  recursion depth. For N=174239 LEDA caused memory overflow (despite the  presence of the extra 100 Mb of virtual memory) due to the extensive use of the  rational ariphmetic.

Like Clippoly, CGAL and CPG have quadratic running time. BOPS produced incorrect results on test polygons so I did not include its  timings.

Numerical robustness

Most of the programs listed above are 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 satisfactory for practical applications. PolyBoolean uses John Hobby‘s rounding cell technique to avoid extraneous  intersections and is therefore completely robust. Boolean also rounds the  intersection points to the integer grid, then repeats until no new intersection  points are found.

References

Algorithm used in Boolean is described in [Holwerda  98]. Some additional information can be found in [Preparata  and Shamos 85] (a must-have Computational Geometry book).

Algorithm used in BOPS is described in [Zalik,  Gombosi and Podgorelec 98].

Algorithm used in CGAL is not documented.

Algorithm used in Clippoly is described in [Schutte  94] and [Schutte  95].

Algorithm used in CPG is described in [Eberly  98].

GPC uses a modified version of [Vatti  92]. Implementation details are discussed in [Murta  98]. Alan Murta is currently working on a paper describing GPC.

Polygon Boolean algorithm used in LEDA is not documented by itself.  The segment intersection part is described in [Mehlhorn  and Naher 94].

Polygon Boolean algorithm used in PolyBoolean is described in [Leonov  and Nikitin 97]. Additional algorithmic and implementation issues are  discussed in [Leonov 98].  The segment intersection part is based on [Bentley  and Ottmann 79] 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, 13(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 English translation). A. P. Ershov   Institute of Informatics Systems, Preprint 46, 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,   35(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 are 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 are only  mine, and I don‘t attempt to make strong assertions about usefulness of these  programs. Click here  to get the polygons I used for testing. Soon I will make the source code of the  test program (with all necessary modifications of the tested libraries) publicly  available.

时间: 2024-12-28 19:28:34

[算法]Comparison of the different algorithms for Polygon Boolean operations的相关文章

算法导论(Introduction to Algorithms )— 第十二章 二叉搜索树— 12.1 什么是二叉搜索树

搜索树数据结构支持许多动态集合操作,如search(查找).minmum(最小元素).maxmum(最大元素).predecessor(前驱).successor(后继).insert(插入).delete(删除),这些都是基本操作,可以使用一颗搜索树当做一个字典或者一个优先队列. 12.1.什么事二叉搜索树 二叉搜索树是以一棵二叉树来组织的,可以用一个链表数据结构来表示,也叫二叉排序树.二叉查找树: 其中的每个结点都是一个对象,每个对象含有多个属性(key:该结点代表的值大小,卫星数据:不清楚

算法导论(Introduction to Algorithms )— 第二章 算法入门 — 2.1 插入排序

一.插入排序:INSERTION-SORT 1.适用范围: which is an efficient algorithm for sorting a small number of elements. 对于少量元素的排序,插入排序是一种高效的算法. 2.原理: Insertion sort works the way many people sort a hand of playing cards. We start with an empty left hand and the cards

图及其衍生算法(Graphs and graph algorithms)

1. 图的相关概念 树是一种的图,相比树,图更能用来表示现实世界中的的实体,如路线图,网络节点图,课程体系图等,一旦能用图来描述实体,能模拟和解决一些非常复杂的任务.图的相关概念和词汇如下: 顶点vertex:图的节点 边Edge:顶点间的连线,若边具有方向时,组成有向图(directed graph) 权重weight:从一个顶点到其他不同顶点的距离不一样,因此边具有权重,来表示不同的距离 路径path:从一个顶点到另一个的所有边的集合 回路cycle:在有向图中,从一个顶点开始,最后又回到起

An Experimental Comparison of Min-Cut/Max-Flow Algorithms for Energy Minimization in Vision

实现参考: http://blog.sina.com.cn/s/blog_60a0e97e0101bfj9.html 介绍流.割.最大流.最小割.最大流最小割定理.增广路径.残存网络.Ford-Fulkerson算法 https://blog.csdn.net/sinat_41613352/article/details/84481115 逻辑正确.表达清晰 https://blog.csdn.net/smartxxyx/article/details/9293665 理论正确.表达一般 原文地

树及其衍生算法(Trees and tree algorithms)

1,二叉树(Binary tree) 二叉树:每一个节点最多两个子节点,如下图所示: 相关概念:节点Node,路径path,根节点root,边edge,子节点 children,父节点parent,兄弟节点sibling, 子树subtree,叶子节点leaf node, 度level,树高hight 节点Node: 路径path:从一个节点到拧一个节点间的边 根节点root, 边edge:节点间的连线 子节点 children, 父节点parent, 兄弟节点sibling, 子树subtre

聚类算法总结

最近要在spark上做一个聚类的项目,数据量和类的个数都比较大.KMeans效果尚可,但是有点慢,因而重新看了下常用的算法. kmeans attention: init centers (randomize vs kmeans++) mini-batch kmeans loops: random samples; find closest for all; update centers for each mean shift init: get centers by bandwidth loo

R语言︱决策树族——随机森林算法

笔者寄语:有一篇<有监督学习选择深度学习还是随机森林或支持向量机?>(作者Bio:SebastianRaschka)中提到,在日常机器学习工作或学习中,当我们遇到有监督学习相关问题时,不妨考虑下先用简单的假设空间(简单模型集合),例如线性模型逻辑回归.若效果不好,也即并没达到你的预期或评判效果基准时,再进行下换其他更复杂模型来实验. ---------------------------------------------- 一.随机森林理论介绍 1.1 优缺点 优点. (1)不必担心过度拟合

计算机视觉算法与代码集锦

计算机视觉算法与代码集锦 计算机视觉是结合了传统摄影测量,现代计算机信息技术.人工智能等多学科的一个大学科,是一片开垦不足的大陆,路很远,但很多人都在跋涉! 本文转自CSDN(地址http://blog.csdn.net/whucv/article/details/7907391),是一篇很好的算法与代码总结文档,转载在此供大家学习参考. 原文如下: UIUC的Jia-Bin Huang同学收集了很多计算机视觉方面的代码,链接如下: https://netfiles.uiuc.edu/jbhua

癌症检测算法头名_ 附代码

最近,近一万名数据科学家在数据科学方面参与开发机器学习算法,可以更精确地通过CT扫描检测癌变病变 数据科学家正在使用机器学习来解决肺癌的检测.从1月份开始,世界各地近1万名数据科学家在Kaggle上竞争开发最有效的算法,帮助医疗专业人员更早地准确地检测肺癌. 2010年,国家肺癌筛查试验显示,使用低剂量计算机断层扫描(CT)进行年度筛查,让计算机处理X光篇产生高对比度3D图像,可以减少肺部癌症死亡人数达20%.然而早期检测与更传统的X光片相比,该技术也导致了相对较高的误报率. 来自NCI的匿名高