[算法]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.
[算法]Comparison of the different algorithms for Polygon Boolean operations的更多相关文章
- OpenCascade Modeling Algorithms Boolean Operations
Modeling Algorithms Boolean Operations of Opencascade eryar@163.com 布尔操作(Boolean Operations)是通过两个形状( ...
- Python - 数据结构与算法(Data Structure and Algorithms)
入门 The Algorithms Python https://github.com/TheAlgorithms/Python 从基本原理到代码实现的Python算法入门,简洁地展示问题怎样解决,因 ...
- 游戏编程算法与技巧 Game Programming Algorithms and Techniques (Sanjay Madhav 著)
http://gamealgorithms.net 第1章 游戏编程概述 (已看) 第2章 2D图形 (已看) 第3章 游戏中的线性代数 (已看) 第4章 3D图形 (已看) 第5章 游戏输入 (已看 ...
- 图及其衍生算法(Graphs and graph algorithms)
1. 图的相关概念 树是一种特殊的图,相比树,图更能用来表示现实世界中的的实体,如路线图,网络节点图,课程体系图等,一旦能用图来描述实体,能模拟和解决一些非常复杂的任务.图的相关概念和词汇如下: 顶点 ...
- 树及其衍生算法(Trees and tree algorithms)
1,二叉树(Binary tree) 二叉树:每一个节点最多两个子节点,如下图所示: 相关概念:节点Node,路径path,根节点root,边edge,子节点 children,父节点parent,兄 ...
- 算法导论(Introduction to Algorithms )— 第十二章 二叉搜索树— 12.1 什么是二叉搜索树
搜索树数据结构支持很多动态集合操作,如search(查找).minmum(最小元素).maxmum(最大元素).predecessor(前驱).successor(后继).insert(插入).del ...
- Technical notes fornight
1.8.2016 Royal trumpeters heralded the beginning of the annual ceremony, as Norway's royal family an ...
- Python基础杂点
Black Hat Python Python Programming for Hackers and Pentesters by Justin Seitz December 2014, 192 p ...
- R语言︱决策树族——随机森林算法
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 笔者寄语:有一篇<有监督学习选择深度学习 ...
随机推荐
- [办公自动化]Wlan无法启动,无法连接无线网wifi,所有无线网都搜索不到
转帖: http://support1.lenovo.com.cn/lenovo/wsi/htmls/detail_20121023172943554.html 故障现象: 启动wlan autoco ...
- try...except 抛出错误
- 2.PHP内核探索:一次请求的开始与结束
PHP开始执行以后会经过两个主要的阶段: 处理请求之前的开始阶段 请求之后的结束阶段 开始阶段有两个过程: 第一个过程是模块初始化阶段(MINIT), 在整个SAPI生命周期内(例如Apache启动以 ...
- web.xml总结整理
web.xml 配置的详细解读 web.xml (部署描述符文件) 整理参考: 加载顺序 ServletContext-->listener->filter->srvlet ...
- [have_fun] 好玩哒小游戏又来啦
联机贪吃蛇,相互厮杀,试一下吧! http://splix.io/
- 从cookie的setDomain方法可以得知localhost不是域名
http://www.baidu.com 其中baidu.com是一个域名.那么http://localhost 中的localhost是不是域名呢?我百度过,发现有人说这是域名.于是我在自己的web ...
- VCL自带的TabControl真心不好用...
不是说功能, 而是指自绘能力, 开启OwnerDraw以后, 画是可以画了, 可是为啥每个Tab页头的边框不能变捏 只能是灰秃秃的, 感觉很不和谐 RZ的TabControl很强大, 可惜想用它需要带 ...
- JQuery源码之“名叫extend的继承”
提起JS中的继承很多”大神“们都会提起call,apply,单纯的对象赋值继承,以及原型链继承等众多的方式以及它们的不足之处,而且还会不时的把一些面向对象的设计模式”团团“的带出来,可谓是厉害非常啊! ...
- Wall---hdu1348(求凸包周长 模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...
- Selenium2学习-011-WebUI自动化实战实例-009-JavaScript 在 Selenium 自动化中的应用实例之一(赋值)
通常在编写 Selenium 的 WebUI 自动化脚本时,有些元素不易定位元素,或有些元素为隐藏的(此时用 WebElement.getText() 获取其值的时候,返回的结果为空),对日常的 UI ...