Search code examples
c++cgaldelaunay

How to create CGAL constrained delaunay triangulation with custom info per vertex?


I want to create a constrained delaunay triangulation and attach a custom piece of information to each vertex (an unsigned value in the example below).

I have read the official example to add info to a "normal" triangulation, which works perfectly. I have also created a constrained delaunay triangulation without info, which works as well.

If I however adjust the example to use a constrained delaunay triangulation with info, which only means changing the two lines marked in the code below, I get loads of build errors (see below).

I have by now spend a few hours trying to make sense of the errors or to find another way to add information to each vertex. Does anyone have an idea what I'm doing wrong or how I could proceed to solve this problem?

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>                        // change 1
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel         K;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned, K>    Vb;
typedef CGAL::Triangulation_data_structure_2<Vb>                    Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds>          Delaunay; // change 2
typedef Delaunay::Point                                             Point;
int main()
{
  std::vector< std::pair<Point,unsigned> > points;
  points.push_back( std::make_pair(Point(0,0),0)   );
  points.push_back( std::make_pair(Point(1,0),1)   );
  points.push_back( std::make_pair(Point(0,1),2)   );
  points.push_back( std::make_pair(Point(14,4),3)  );
  points.push_back( std::make_pair(Point(2,2),4)   );
  points.push_back( std::make_pair(Point(-4,0),5)  );

  Delaunay T;
  T.insert( points.begin(),points.end() );
  CGAL_assertion( T.number_of_vertices() == 6 );
  // check that the info was correctly set.
  Delaunay::Finite_vertices_iterator vit;
  for (vit = T.finite_vertices_begin(); vit != T.finite_vertices_end(); ++vit)
    if( points[ vit->info() ].first != vit->point() ){
      std::cerr << "Error different info" << std::endl;
      exit(EXIT_FAILURE);
    }
  std::cout << "OK" << std::endl;
  return 0;
}
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_triangulation_2.h(653): error C2039: 'is_constrained': is not a member of 'CGAL::Triangulation_ds_face_base_2<TDS2>'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Triangulation_ds_face_base_2.h(356): note: see declaration of 'CGAL::Triangulation_ds_face_base_2<TDS2>'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_triangulation_2.h(648): note: while compiling class template member function 'CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_vertex_base_with_info_2<unsigned int,GT,CGAL::Triangulation_vertex_base_2<GT,CGAL::Triangulation_ds_vertex_base_2<TDS2>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false> CGAL::Constrained_triangulation_2<Gt,Tds_,Itag_>::insert(const CGAL::Point_2<Kernel_> &,CGAL::Triangulation_2<Gt,CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>::Locate_type,CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int)'
1>        with
1>        [
1>            GT=K,
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>,
1>            Gt=K,
1>            Tds_=Tds,
1>            Itag_=CGAL::Default,
1>            Kernel_=CGAL::Epick
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_triangulation_2.h(622): note: see reference to function template instantiation 'CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_vertex_base_with_info_2<unsigned int,GT,CGAL::Triangulation_vertex_base_2<GT,CGAL::Triangulation_ds_vertex_base_2<TDS2>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false> CGAL::Constrained_triangulation_2<Gt,Tds_,Itag_>::insert(const CGAL::Point_2<Kernel_> &,CGAL::Triangulation_2<Gt,CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>::Locate_type,CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int)' being compiled
1>        with
1>        [
1>            GT=K,
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>,
1>            Gt=K,
1>            Tds_=Tds,
1>            Itag_=CGAL::Default,
1>            Kernel_=CGAL::Epick
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_Delaunay_triangulation_2.h(888): note: while compiling class template member function 'void CGAL::Constrained_Delaunay_triangulation_2<K,Tds,CGAL::Default>::triangulate_hole(std::list<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,std::allocator<_Kty>> &,std::list<std::pair<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int>,std::allocator<_Ty>> &,std::list<_Ty,std::allocator<_Ty>> &)'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>,
1>            _Kty=CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,
1>            _Ty=std::pair<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int>
1>        ]
1>C:\Users\Albert\Documents\projects\TestEnv_CGAL\main.cpp(9): note: see reference to class template instantiation 'CGAL::Constrained_Delaunay_triangulation_2<K,Tds,CGAL::Default>' being compiled
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_triangulation_2.h(1142): error C2039: 'set_constraint': is not a member of 'CGAL::Triangulation_ds_face_base_2<TDS2>'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Triangulation_ds_face_base_2.h(356): note: see declaration of 'CGAL::Triangulation_ds_face_base_2<TDS2>'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_triangulation_2.h(1130): note: while compiling class template member function 'void CGAL::Constrained_triangulation_2<Gt,Tds_,Itag_>::triangulate_hole(std::list<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,std::allocator<_Kty>> &,std::list<std::pair<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int>,std::allocator<_Ty>> &,std::list<_Ty,std::allocator<_Ty>> &,std::list<_Ty,std::allocator<_Ty>> &)'
1>        with
1>        [
1>            Gt=K,
1>            Tds_=Tds,
1>            Itag_=CGAL::Default,
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>,
1>            _Kty=CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,
1>            _Ty=std::pair<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_Delaunay_triangulation_2.h(890): note: see reference to function template instantiation 'void CGAL::Constrained_triangulation_2<Gt,Tds_,Itag_>::triangulate_hole(std::list<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,std::allocator<_Kty>> &,std::list<std::pair<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<TDS2>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int>,std::allocator<_Ty>> &,std::list<_Ty,std::allocator<_Ty>> &,std::list<_Ty,std::allocator<_Ty>> &)' being compiled
1>        with
1>        [
1>            Gt=K,
1>            Tds_=Tds,
1>            Itag_=CGAL::Default,
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>,
1>            _Kty=CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,
1>            _Ty=std::pair<CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>>,CGAL::Default,CGAL::Default,CGAL::Default>,false>,int>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Constrained_triangulation_2.h(1143): error C2039: 'set_constraint': is not a member of 'CGAL::Triangulation_ds_face_base_2<TDS2>'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>
1>        ]
1>C:\Users\Albert\Documents\libs\cgal_4_13\include\CGAL/Triangulation_ds_face_base_2.h(356): note: see declaration of 'CGAL::Triangulation_ds_face_base_2<TDS2>'
1>        with
1>        [
1>            TDS2=CGAL::Triangulation_data_structure_2<Vb,CGAL::Triangulation_ds_face_base_2<void>>
1>        ]

Solution

  • The face type (second template parameter in the TDS) must be a model of ConstrainedTriangulationFaceBase_2, for example CGAL::Constrained_triangulation_face_base_2<K> in you case.

    Replace:

    typedef CGAL::Triangulation_data_structure_2<Vb>                    Tds;
    

    by

    typedef CGAL::Constrained_triangulation_face_base_2<K>  Fb;
    typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;