[英]CGAL - wrong vertices index retrieved after Delaunay Triangulation in 3d
[英]CGAL - Retrieve Vertex Index After Delaunay Triangulation
我正在計算幾千點的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
您可以將任何信息附加到三角測量中的頂點。 例如,要添加索引( unsigned int
),您可以執行以下操作:
#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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.