Search code examples
c++cgaltriangulationdelaunay

Embedding and iterating over custom faces in CGAL Delaunay triangulation


I'm using the CGAL library for performing Delaunay triangulation in my C++ application. I would like to embed custom faces into the triangulation and then iterate over them, but I'm not sure how to incorporate them into the triangulation and how to iterate over the custom faces afterwards.

At the end I want something like this:

  typedef CGAL::Delaunay_triangulation_2<EPIC> DelaunayTriangulation;
  DelaunayTriangulation triangulation;
  // ...
  for (auto it = triangulation.faces_begin(); it != triangulation.faces_end(); ++it)
  {
    MyFace& face = static_cast<MyFace&>(*it);
    // ...
  }

Can someone explain how I can embed my custom face into the Delaunay triangulation?

Edit

As correctly pointed out in the comments, I actually want to extend the Face class used during Delaunay triangulation in CGAL to store additional information in the constructor for reuse.


Solution

  • Short version: have a look at CGAL::Triangulation_face_base_with_info_2.

    Longer version below:

    Your triangulation expects its face type to provide it some specific API: if you check the doc of CGAL::Delaunay_triangulation_2, you can see it wants its face to be a model of the concept TriangulationDataStructure_2::Face.

    By default, CGAL will use CGAL::Triangulation_data_structure_2 templated with CGAL::Triangulation_face_base_2 as template classes that fit those requirements. You can enrich existing face base classes by deriving from CGAL::Triangulation_face_base_2. This is what is done for example in the class CGAL::Triangulation_face_base_with_id_2, which inherits CGAL::Triangulation_face_base_2 and adds an ID member.

    The class CGAL::Triangulation_face_base_with_info_2 provides this in a generic way as you can pass whatever info you want as a template parameter (be it a bool or a class itself).

    Since you are no longer using the default classes, you will need to specify the CGAL::Delaunay_triangulation_2 templates:

    typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    typedef CGAL::Triangulation_vertex_base_2<K> Vb;
    typedef CGAL::Triangulation_face_base_with_info_2<**YOUR_INFO_TYPE**,K> Fb;
    typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
    typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation;