Constrained DT, how to keep track of vertex IDs? #7738
Replies: 2 comments 7 replies
-
I use these typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
struct FaceInfo2 {
FaceInfo2() {}
int nesting_level;
bool in_domain() { return nesting_level % 2 == 1; }
};
typedef CGAL::Triangulation_vertex_base_with_info_2<int, K> Vbi2;
typedef CGAL::Triangulation_face_base_with_info_2<FaceInfo2, K> Tfbi2;
typedef CGAL::Constrained_triangulation_face_base_2<K, Tfbi2> Ctfb2;
typedef CGAL::Triangulation_data_structure_2<Vbi2, Ctfb2> Tds2;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds2, Itag> CDT; This code has not be written with the latest CGAL version, so maybe some things have changed. The type You have to make "marked points", that is to say a pair made of a point and an integer, the id. Something like that: points[i] = std::make_pair(CDT::Point(2, 3), i); Then after inserting the constraints you insert the marked points like this: cdt.insert(points.begin(), points.end()); And here is a piece of code showing how to retrieve the ids, they are in for(CDT::Face_handle f : cdt.finite_face_handles()){
if(f->info().in_domain()){
const int id0 = f->vertex(0)->info();
const int id1 = f->vertex(1)->info();
const int id2 = f->vertex(2)->info();
const face_descriptor fd = mesh.add_face(
vertex_descriptor(id0),
vertex_descriptor(id1),
vertex_descriptor(id2)
);
if(fd == Mesh::null_face()) { // that should not happen
exit().......;
}
}
} Sorry for some vagueness. I hope this helps. |
Beta Was this translation helpful? Give feedback.
-
The constraints must (?) be inserted before the points. At least this is what I do (and it works). Here is the beginning of my code. But I use Rcpp, a C++ library whose purpose is to write C++ code for R. The wording is clear: const int npoints = pts.ncol();
std::vector<std::pair<CDT::Point, int>> points(npoints);
Mesh mesh;
for(int i = 0; i < npoints; ++i) {
const Rcpp::NumericVector pt_i = pts(Rcpp::_, i);
points[i] = std::make_pair(CDT::Point(pt_i(0), pt_i(1)), i);
mesh.add_vertex(Point2(pt_i(0), pt_i(1)));
}
CDT cdt;
{
const size_t nedges = edges.ncol();
for(size_t k = 0; k < nedges; ++k) {
const Rcpp::IntegerVector edge_k = edges(Rcpp::_, k);
cdt.insert_constraint(points[edge_k(0) - 1].first,
points[edge_k(1) - 1].first);
}
}
cdt.insert(points.begin(), points.end());
....... |
Beta Was this translation helpful? Give feedback.
-
One issue I'm getting over and over with CGAL is I'm always having difficulties keeping track of vertex ids. This is a major pain point in my workflow, for example I have a CDT where I want to keep track of the vertex IDs:
I get this error, I'm not sure what I'm missing and I'm struggling to find examples
Beta Was this translation helpful? Give feedback.
All reactions