win732位 ehviewer注册教程


win732位+CGAL4.71+VS2013配置最近需要需要队点云进行三角剖分 , 也就是构建Delaunay三角网 , 但是自己写的算法在数据量较小时表现尚且可以 , 但是在数据量较大是消耗的时间太长 。最后了解到CGAL开源库有相关算法 , 但是耗费了将近两天才最终配置好CGAL库 , 现在写一下总结吧 。
一、前期准备
需要的第三方库有
1.下载boost 并安装:
boost_1_67_0-msvc-12.0-32.exe.
选择boost_1_67_0-msvc-12.0-32.exe下载安装 , 用binary方便省事 。(msvc-12.0就是vs2013)
下完之后 , 直接按流程点击安装即可 。
2. 安装CGAL4.41
CGAL4.41
从链接进去 , 选择CGAL-4.41-Setup.exe 下载安装 。选择好英文路径安装 , 中间会要求添加路径 , 环境变量 , 添加就是了 , 继续无脑操作 。
安装完最后会提示你把D:\XXX\CGAL-4.4\auxiliary\gmp\lib手动加到系统PATH中去 , 点击“yes” , 安装完后手动添加即可 。

win732位 ehviewer注册教程

文章插图
win732位 ehviewer注册教程

文章插图

win732位 ehviewer注册教程

文章插图
【win732位 ehviewer注册教程】
win732位 ehviewer注册教程

文章插图

3.CMAKE
从网上下载CMAKE安装包安装即可 , 我选的Cmake3.11.3
4.QT
5.libQGLViewer
二、CGAL的三角数据访问
Triangulation_2 < Traits,TDS > 是CGAL中描述二维三角形剖分的一个模板类 。实例化时, 它的第一个模板参数要传入一个几何核心类, 第二个模板参数是一个三角剖分的数据结构类(这个参数有一个默认的值) 。这个模板类定义了三角剖分的基本用户接口 ,  它也是其它三角剖分类(如Delaunay_triangulation_2、Regular_triangulation_2)的基类 。因此它是基于CGAL进行二维三角形网格生成和优化算法开发 , 必须要掌握好这个类 。
如图· , 对于三角面f来说 , 它一共有三个顶点、三条边 , 还有三个相邻的三角面 。顶点index排序按照逆时针 , 并且相邻面neighbor face和边Edge的index分别与对面的顶点index保持一致(如下图neighbor(i), Edge(i)与点i在空间上相对) 。
win732位 ehviewer注册教程

文章插图
在CGAL中 , 一个三角形面有三个顶点和三个相邻三角面的数据(不显式地存在边的数据 , 这也是我觉得很CGAL中很bug的一件事 , 太不实用了!) 。用一个三角面的内部访问函数vertex(i), neighbor(i)来获取相应的顶点、相邻三角面 , 其数据类型分别为Vertex_handle, Face_handle. 通过这几个指针类型 , 可以访问到对应的数据 。
1.顶点数据访问
CDT::Point pt = vh->point(); 其中vh是数据指针Vertex_handle , 具体访问x, y值就可以通过pt.x(), pt.y()来访问 。注意 , 和一般的点数据不同 , 以上的x, y数据访问多一个括号!(表示通过成员函数访问成员变量 , 而不能直接访问其内部的成员变量)
三个顶点的数据可以通过访问一个三角面的属性:用Face_handle fh; fh->vertex(i), i=0,1,2,来访问 , 而且0,1,2分别按照逆时针来排序 。
三个顶点还可以通过其中一个点的index遍历 , 对应的index分别为i, ccw(i), cw(i)来访问 。
某个顶点也可以通过对边Edge来访问 , Edge是一个二元组 , 由typedef std::pair<Face_handle, int> Edge;定义 , 因此访问Edge_hanle eh; eh->first得到的是它所属的一个三角面 , eh->second得到的是它在该所属三角面的边索引index(而对顶点和这个索引一致);因而结合这两者就可以利用eh->first->vertex(eh->second);访问其余两个点就可以通过先得到三角面指向Face_handle fh = eh->first(); 然后fh->vertex(cdt.cw(eh->second));与fh->vertex(cdt.cw(eh->second))进行顶点访问 。
三角形的创建:
用默认构造函数 TriangulationDSFaceBase_2 f;用三点Vertex_handle v0, v1, v2初始化三角形TriangulationDSFaceBase_2 f ( Vertex_handle v0, Vertex_handle v1, Vertex_handle v2);用三点Vertex_handle v0, v1, v2初始化三角形三个顶点 , 用Face_handle n0, n1, n2初始化三角形相邻的三个三角形TriangulationDSFaceBase_2 f ( Vertex_handle v0, Vertex_handle v1, Vertex_handle v2, Face_handle n0, Face_handle n1, Face_handle n2);三角的访问函数:
Vertex_handlef.vertex (int i); //返回三角面f的第i个顶点(i= 0, 1, 2), 类型为Vertex_handle
Face_handlef.neighbor ( int i); //返回三角面f的第i个相邻三角面(i= 0, 1, 2), 类型为Face_handle
intf.dimension (); //返回三角面维数
boolf.has_vertex ( Vertex_handle v); //如果v是三角面f的一个顶点 , 返回true;否则为false
boolf.has_vertex ( Vertex_handle v, int& i); //如上 , 并且设置该顶点在三角面f的index为i
boolf.has_neighbor ( Face_handle n) //返回三角面n是否为三角面f的相邻三角
boolf.has_neigbor ( Face_handle n, int& i) //如上 , 并且设置该三角面在三角面f的相邻index
intf.index ( Vertex_handle v); //返回顶点v在三角面f上的index
int f.index ( Face_handle n); //返回三角n在f相邻三角的index
三角的设置函数
voidf.set_vertex ( int i, Vertex_handle v) //设置三角面f的第i个顶点是v (i=0, 1, 2)
voidf.set_vertices ( Vertex_handle v0, Vertex_handle v1, Vertex_handle v2)
voidf.set_neighbor ( int i, Face_handle n) //设置三角面f的第i个相邻面为n (i=0, 1, 2)
voidf.set_neighbors ( Face_handle n0, Face_handle n1, Face_handle n2)
约束三角剖分(CDT)中的数据遍历 1. 在Triangulation_2<Traits,TDS> 中 , 要遍历所有的节点、边或三角面 , 要用到相应的 iterator ,  如: Finite_faces_iterator Finite_edges_iterator Finite_vertices_iterator
//例:首先包含所需要的头文件和定义一些数据结构
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_conformer_2.h>
#include
using namespace std;
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Constrained_Delaunay_triangulation_2 CDT;
typedef CDT::Point Point;
typedef CDT::Vertex_handle Vertex_handle;
//用Finite_faces_iterator遍历CDT中的所有三角面Face , 输出每个三角面对应的三个顶点数据
CDT::Finite_faces_iterator f_iter;
for (f_iter=cdt.finite_faces_begin(); f_iter!=cdt.finite_faces_end(); f_iter++)
{
for (int i=0; i<3; i++)
{
Point p = f_iter->vertex(i)->point();
cout<<"("<<p.x()<<","<<p.y()<<")"<<endl;
}
}
//用Finite_edges_iterator遍历CDT中的所有边Edge , 输出每条边对应的两个顶点数据
CDT::Finite_edges_iterator e_iter;
for (e_iter=cdt.finite_edges_begin(); e_iter!=cdt.finite_edges_end(); e_iter++)
{
for(int i=0; i<2; i++)
{
Vertex_handle f_v1 = e_iter->first->vertex(cdt.cw(e_iter->second));
Vertex_handle f_v2 = e_iter->first->vertex(cdt.ccw(e_iter->second));
Point p1 = f_v1->point(); Point p2 = f_v2->point(); cout<<"("<<p1.x()<<","<<p1.y()<<")"<<endl;</span> cout<<"("<<p2.x()<<","<<p2.y()<<")"<<endl;</span>
} }
2. 要遍历一个节点周围的节点、边或单元 , 要用到 circulator ,  如: Face_circulator Edge_circulator Vertex_circulator

    推荐阅读