如何在 CGAL 中迭代人脸
我正在尝试使用 CGAL 进行一些 Delaunay 三角测量。我使用 CGAL 示例之一来计算包含高度场属性的三角测量。
我遇到的问题是我不知道如何获得最终的三角测量。我想出了如何获取face_iterator,但我不知道从那里做什么。我希望得到的是每个三角形上 3 个点的点数组的索引。
我在遍历所有嵌套模板时遇到问题:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_euclidean_traits_xy_3.h>
#include <CGAL/Delaunay_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_euclidean_traits_xy_3<K> Gt;
typedef CGAL::Delaunay_triangulation_2<Gt> Delaunay;
typedef K::Point_3 Point;
int main()
{
//initialize the points with some trivial data
std::vector<Point> pts;
pts.push_back(Point(1., 2., 3.));
pts.push_back(Point(2., 2., 3.));
pts.push_back(Point(1., 3., 3.));
pts.push_back(Point(4., 2., 3.));
//create a delaunay triangulation
Delaunay dt;
dt.insert(pts.begin(), pts.end());
//iterate through the faces
Delaunay::Finite_faces_iterator it;
for (it = dt.finite_faces_begin(); it != dt.finite_faces_end(); it++)
{
//What do I do here??
}
return 0;
}
I am trying to use CGAL to do some Delaunay triangulation. I used one of the CGAL samples to compute a triangulation which includes a height field attribute.
The problem I have having is that I have no idea how to get the resulting triangulation. I figured out how to get the face_iterator, but I don't know what to do from there. What I'm hoping to get is an index into the point array for each of the 3 points on each triangle.
I'm having trouble wading through all of the nested templates:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_euclidean_traits_xy_3.h>
#include <CGAL/Delaunay_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_euclidean_traits_xy_3<K> Gt;
typedef CGAL::Delaunay_triangulation_2<Gt> Delaunay;
typedef K::Point_3 Point;
int main()
{
//initialize the points with some trivial data
std::vector<Point> pts;
pts.push_back(Point(1., 2., 3.));
pts.push_back(Point(2., 2., 3.));
pts.push_back(Point(1., 3., 3.));
pts.push_back(Point(4., 2., 3.));
//create a delaunay triangulation
Delaunay dt;
dt.insert(pts.begin(), pts.end());
//iterate through the faces
Delaunay::Finite_faces_iterator it;
for (it = dt.finite_faces_begin(); it != dt.finite_faces_end(); it++)
{
//What do I do here??
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 Delaunay::triangle 将面(迭代器)转换为相应的三角形。这是在 CGAL 3.8 下测试的:
You can use Delaunay::triangle to convert from a face (iterator) to the corresponding triangle. This is tested under CGAL 3.8:
可以使用 dt.triangle(it)[idx] 访问三角形的顶点,其中 it 是面迭代器,idx 是顶点编号(0,1 或 2) )。在下面的示例中,顶点是 Point_2 对象,可以使用 x() 和 y() 方法访问其笛卡尔坐标。
A vertex of a triangle can be accessed using dt.triangle(it)[idx], where it is a faces iterator and idx is vertex number (0,1 or 2). In the example below, a vertex is a Point_2 object, its cartesian coordinates can be accessed using x() and y() methods.
这是谷歌的一个例子。 Finite_faces_iterator 是类型定义的。
这不会执行您想要的操作,但为您提供了一个可以使用迭代器执行的操作的示例。
Here is an example from Google. Finite_faces_iterator was typedefed.
This does not do what you want, but gives you an example of what can be done with an iterator.
如果您想要一个真正扩展的示例,了解如何准确地完成您想要的操作,请从此处查看 X-Plane 风景工具的源代码:http://scenery.x-plane.com/code.php
通过扩展示例,我的意思是几十万行,但是 CGAL 几乎可以使用所有内容处理 Delaunay 三角剖分和其中的扩展属性。
If you want a really extended example of how to do exactly what you want, take a look at the source to the X-Plane scenery tools from here: http://scenery.x-plane.com/code.php
By extended example, I mean a couple of hundred thousand lines, but there's uses of nearly everything CGAL can do with Delaunay triangulations and extended attributes in there.
好吧,我刚刚遇到了类似的问题,我做了很多研究(主要是因为我对 C++ 没有任何了解)。我希望能够通过顶点整数表示来打印三角形。它的外观如下:
使用以下命令进行编译(如果
mesh_implicit_function
是源代码、目标文件和可执行文件):Well I just had a similar problem where I did a lot of research (mainly because I did not have any knowledge of C++). I wanted to be able to print triangles by it's vertex integer representation. Here it is how it looks:
compile it with (if
mesh_implicit_function
is source, object file, and executable):