CGAL - 检索Delaunay三角测量后的顶点索引 [英] CGAL - Retrieve Vertex Index After Delaunay Triangulation
问题描述
我计算了几千点的2D delaunay三角测量。除了x和y坐标之外,每个点具有与其相关联的更多数据。因此,我想知道是否可以检索每个点的索引,以便我可以访问我自己的点结构在另一个向量。
I am computing the 2D delaunay triangulation of a few thousand points. Each point has more data associated with it beyond x and y coordinates. Therefore, I was wondering if it is possible to retrieve the index of each point so that I can access my own point struct in another vector.
目前,当我访问顶点从一个Face_handle,它返回一个点(即x,y坐标)我如何返回每个顶点的ID(索引)而不是它的x,y坐标?谢谢。
Currently, as I access vertices from a Face_handle, it returns a point (i.e. x,y coordinates) How can I return each vertex by its ID (index) instead of its x,y coordinates? Thank you.
#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
推荐答案
您可以在三角测量中将任何信息附加到顶点。例如,要添加索引( unsigned int
),您可以执行以下操作:
You can attach any information to vertices in a triangulation. For example to add indices (unsigned int
) you could do the following:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned int, Kernel> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb> Tds;
typedef CGAL::Delaunay_triangulation_2<Kernel, Tds> Delaunay;
typedef Kernel::Point_2 Point;
int main() {
std::vector< std::pair<Point,unsigned> > points;
points.push_back( std::make_pair( Point(1,1), 0 ) );
points.push_back( std::make_pair( Point(1,2), 1 ) );
points.push_back( std::make_pair( Point(1,3), 2 ) );
points.push_back( std::make_pair( Point(2,1), 3 ) );
points.push_back( std::make_pair( Point(2,2), 4 ) );
points.push_back( std::make_pair( Point(2,3), 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;
std::cout << "Vertex 0:\t" << face->vertex(0)->info() << std::endl;
}
}
这篇关于CGAL - 检索Delaunay三角测量后的顶点索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!