我正在计算几千点的 2D delaunay 三角剖分。除了 x 和 y 坐标之外,每个点都有更多与之相关的数据。因此,我想知道是否可以检索每个点的索引,以便我可以在另一个向量中访问我自己的点结构。
目前,当我从 Face_handle 访问顶点时,它返回一个点(即 x,y 坐标) 我如何通过其 ID(索引)而不是 x,y 坐标返回每个顶点?谢谢你。
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Delaunay_triangulation_2<Kernel> Delaunay;
typedef Kernel::Point_2 Point;
void example() {
std::vector<Point> points;
points.push_back(Point(1,1)); //index 0
points.push_back(Point(1,2)); //index 1
points.push_back(Point(1,3)); //index 2
points.push_back(Point(2,1)); //index 3
points.push_back(Point(2,2)); //index 4
points.push_back(Point(2,3)); //index 5
Delaunay triangulation;
triangulation.insert(points.begin(),points.end());
for(Delaunay::Finite_faces_iterator fit = triangulation.finite_faces_begin();
fit != triangulation.finite_faces_end(); ++fit) {
Delaunay::Face_handle face = fit;
std::cout << "Triangle:\t" << triangulation.triangle(face) << std::endl;
std::cout << "Vertex 0:\t" << triangulation.triangle(face)[0] << std::endl;
}
}
输出(x,y 坐标):
Triangle: 1 3 1 2 2 2
Vertex 0: 1 3
Triangle: 1 2 1 1 2 1
Vertex 0: 1 2
Triangle: 1 3 2 2 2 3
Vertex 0: 1 3
Triangle: 1 2 2 1 2 2
Vertex 0: 1 2
期望的输出(指数):
Triangle: 2 1 4
Vertex 0: 2
Triangle: 1 0 3
Vertex 0: 1
Triangle: 2 4 5
Vertex 0: 2
Triangle: 1 3 4
Vertex 0: 1