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.
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:" << triangulation.triangle(face) << std::endl;
std::cout << "Vertex 0:" << triangulation.triangle(face)[0] << std::endl;
}
}
Output (x,y coordinates):
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
Desired Output (indices):
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…