Storing Additional Information in CGAL Constrained Triangulation Face and Accessing it Using Finite Faces Iterator

Advertisements

I am using CGAL’s Constrained Delaunay Triangulation (Constrained_Delaunay_triangulation_2) to perform triangulation with constraints. I would like to store some additional information in each face of the constrained triangulation and then access this information while iterating over the finite faces.

I have tried to create a custom face base class derived from CGAL::Constrained_triangulation_face_base_2, but I am facing difficulties in accessing the additional information stored in the face using the Finite_faces_iterator.

Here is my attempt (including different types of casts like static, dynamic etc.):

class Constrained_triangulation_face_base_with_info_2 : public CGAL::Constrained_triangulation_face_base_2<EPIC> {
    
public:
    std::vector<Point2d> containedPoints;

    Constrained_triangulation_face_base_with_info_2() : containedPoints() {

    }

    virtual ~Constrained_triangulation_face_base_with_info_2() {}
};

// Constrained (!) Delaunay-Triangulierung
typedef CGAL::Triangulation_vertex_base_2<EPIC> VertexBase;
typedef CGAL::Triangulation_data_structure_2<VertexBase, Constrained_triangulation_face_base_with_info_2> TDS;
typedef CGAL::Constrained_Delaunay_triangulation_2<EPIC, TDS> ConstrainedDelaunayTriangulation;
typedef ConstrainedDelaunayTriangulation::Finite_faces_iterator ConstrainedDelaunayFacesIterator;

// ...

for (
    ConstrainedDelaunayFacesIterator fit = 
    constrainedDelaunayTriangulation.finite_faces_begin(), end = 
    constrainedDelaunayTriangulation.finite_faces_end();
    fit != end;
    ++fit
    ) {

    // Now how to cast/access the custom face base class derived from fit?!
}

I understand that the issue might be related to type casting, but I am unsure how to correctly access the additional information stored in Constrained_triangulation_face_base_with_info_2.

Could someone please guide me on how to store and access additional information in faces of CGAL’s constrained triangulation using Finite_faces_iterator? Any help or code example would be highly appreciated. Thank you!

>Solution :

The correct approach is that you don’t need to create a new face class. You can use the fact that Constrained_triangulation_face_base_2 has a template parameter allowing you pass the existing class Triangulation_face_base_with_info_2 as a base:

typedef CGAL::Triangulation_vertex_base_2<EPIC> Vb;
typedef std::vector<Point2d> My_info;
typedef CGAL::Triangulation_face_base_with_info_2<My_info, EPIC> Fbb;
typedef CGAL::Constrained_triangulation_face_base_2<EPIC, Fbb>;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Your_prefered_itag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<EPIC, Tds, Itag> CDT;

[...]
for(auto fit =  cdt.finite_faces_begin(), end = cdt.finite_faces_end(); fit != end; ++fit) 
{
  fit->info().push_back(Point2d());
  // etc.
}

Just for completeness: if you want to derive your own vertex/face classes (which, again, you don’t need here as you can use existing CGAL classes), then you have to take care of the advanced rebinding mechanism, see https://doc.cgal.org/latest/TDS_2/index.html#title7.

Leave a ReplyCancel reply