码迷,mamicode.com
首页 > 其他好文 > 详细

二维平面三角划分

时间:2016-03-11 11:47:18      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:

1 INTRODUCTION

在OpenGL中,为了更方便的提供能对符合条件的多边形进行快速渲染,对合法的多边形做出条件限制。已知对于空间中的多边形P的分割是等价于原始多边形P的一系列互不相交的多边形的并集。为了最大限度的提高性能,同时解决在三维空间中绘制的凹多边形在旋转时发生的闪烁问题。在系统研究学习CGAL三角划分算法的基础上,对算法的性能进行分析,得出适合本课题的算法方案。

2 POLYGON PARTITIONING

多边形划分有诸多算法,本文通过函数random_polygon_2产生指定数量下的随机顶点,对比分析单调划分(Monotone Partitioning)以及凸划分(Convex Partitioning)算法性能,同时辅助以OpenGL环境下的图形显示。

template<class OutputIterator , class PointGenerator , class Traits >
OutputIterator CGAL::random_polygon_2   (   std::size_t     n,
OutputIterator  result,
const PointGenerator &  pg,
Traits  t = Default_traits 
)   

函数通过pg产生n个唯一的随机顶点,这些顶点以逆时针的顺序形成简单多边形将结果写入到result中。

2.1 单调划分(Monotone Partitioning)

y值单调多边形(y-monotone polygon)是将顶点v1,v2,...,vn划分成v1,v2,...,vk和vk,...,vn,v1两部分。这样任意水平线至少与其相交一次。为了对给定的多边形产生y值单调划分,在函数y_monotone_partition_2()中运用了扫描线算法。它的时间复杂度为O(nlogn),空间复杂度为O(n)。该算法产生的多边形约束数量并不能确保与最优数量保持一致。通过使用is_y_monotone_2()检测y_monotone_partition_2()函数划分的有效性。

template<class InputIterator , class OutputIterator , class Traits >
OutputIterator CGAL::y_monotone_partition_2 (   InputIterator   first,
InputIterator   beyond,
OutputIterator  result,
const Traits &  traits = Default_traits 
)   

前提:由点集[first,beyond)所定义的多边形为简单多边形,且节点按逆时针顺序存放。

技术分享

2.2 凸划分(Convex Partitioning)

多边形凸划分可以利用提供的三个函数来产生。第一个用来产生最优数量。其他两个用来产生相似最优凸划分。这两个函数都是将多边形分解成简单的多边形。

2.2.1 最优凸划分(optimal convex partition)

最优凸划分运用了格林的动态规划算法,时间复杂度为 O ( n 4 ) ,空间复杂度为 O ( n 3 )

template<class InputIterator , class OutputIterator , class Traits >
OutputIteratorCGAL::optimal_convex_partition_2  (   InputIterator   first,
InputIterator   beyond,
OutputIterator  result,
const Traits &  traits=Default_traits
)   

技术分享

2.2.2 近似凸划分( approx convex partition)

函数approx_convex_partition_2()运用了 Hertel 和 Mehlhorn的简单近似算法。 对于一个给定的三角,这需要凸分区算法 O ( n ) 时间和空间复杂度来构建一个最优分解为不超过四次凸块的数量。

template<class InputIterator , class OutputIterator , class Traits >
OutputIterator CGAL::approx_convex_partition_2  (   InputIterator   first,
InputIterator   beyond,
OutputIterator  result,
const Traits &  traits = Default_traits 
)   

技术分享

2.2.3 扫描线近似算法(sweep-line approximation algorithm)

greene_approx_convex_partition_2()函数需要的时间复杂度为 O ( n log ? n ) 空间复杂度为 O ( n )

template<class InputIterator , class OutputIterator , class Traits >
OutputIterator CGAL::greene_approx_convex_partition_2   (   InputIterator   first,
InputIterator   beyond,
OutputIterator  result,
const Traits &  traits = Default_traits 
)   

技术分享

3 CASE STUDY

在程序中通过指定函数CGAL::randompolygon2(50, std::backinserter(polygon),Pointgenerator(500));,产生50个随机顶点的简单多边形。多边形在各个算法下的划分如上图所示。上述算法的执行时间如下表所示:

技术分享

从以上分析结果来看y值单调多边形的时间效率最高。然而将此算法运用在旋转的三维空间时,会发生闪烁的现象。

而通过选择近似凸划分算法则不会发生上图的情况,且运行效率比其他算法较高。对代码性能进行分析,算法的主要时间在分块部分。

执行近似凸划分算法,选取13个样本,CPU运行效率如下:

技术分享

函数详细信息如下图所示程序运行的convex_partion_is_valid_2函数最为占用资源,可以通过改进该函数提高程序性能。

技术分享

样本数百分比如下图所示:

技术分享

函数百分比详细信息如下图所示:

技术分享

函数调用关系库如下图所示:

技术分享

技术分享

 

4 CONCLUSION

在课题中选用的结构面数量较少,一般不超过10个结构面,在对弧线微分后,产生的顶点数一般不超过100,运用近似凸划分能够很好的解决三维空间中的几何平面旋转时发生的闪烁问题,且该算法的性能相对其他算法要高。从该算法中,可以发现程序所占用的时间开销位于函数convex_partion_is_valid_2部分,因此可以进一步分析研究以提升算法的效率。

5 ACKNOWLEDGMENT

本次实验主要基于CGAL计算几何算法库,由于本人能力有限,对算法理解分析难免有疏忽的地方,在此感谢老师对我的耐心指导,烦请批评指正。

6 REFERENCES

[1]Jianyong Li,Jian Xue,Jun Xiao. Three Dimensional Sphere Analysis Method of Block Theory[C]//Computer Application and System Modeling (ICCASM), 2010 International Conference on, 2010: 1-578.

[2]CGAL 4.7 - 2D Polygon Partitioning :http://doc.cgal.org/latest/Partition2/group_PkgPolygonPartitioning2.html

[3]Windows环境下CGAL的安装:http://www.cnblogs.com/ucas/p/5264609.html

二维平面三角划分

标签:

原文地址:http://www.cnblogs.com/ucas/p/5264573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!