Wave and Matter
Wave and Matter

Reputation: 161

What are the defaults to cgal::delaunayTriangulation<K,??> and how to add own data to vertices?

My actual goal is to add additional information to the vertices in a D-dimensional CGAL Delaunay-Triangulation. Analogous to the 2D and 3D triangulations (where this is described in the manual), this should be possible by creating a class inheriting from some cgal vertex type and passing this in as a template parameter.

As a prerequisite, I wanted to do something much simpler.

For the standard case you use the typedefs

typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag >   K;
typedef CGAL::Delaunay_triangulation<K>  Triangulation;

Actually there is one more template parameter, which ultimately would allow you to pass in your own vertex class. I wanted to find out what the default parameter for this second parameter is, by explicitly passing it.

After wading through unintelligible "modern c++" code and the cgal manual, my first guess was something like

typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag >   K;
typedef CGAL::Triangulation_data_structure<K,CGAL::Triangulation_ds_vertex<>,CGAL::Triangulation_ds_full_cell<>  >  TDS;
typedef CGAL::Delaunay_triangulation<K,TDS>  Triangulation;

However this gives me lots of errors, the first one stating that my vertex class is missing a "Point" typedef. I also tried variations (trying to pass template parameters to the ds_vertex and ds_full_cell as well) with the same result.

The manual (https://doc.cgal.org/latest/Triangulation/index.html#title7) tells me that I would have to pass the TDS type itself to the vertex and cell classes, creating "circular dependencies" being resolved by a "rebind mechanism". I do not understand how this works, however i would think that this should be solved in this simple case where i just use the default vertex/cell classes by supplied by CGAL itself.

So finally, my question is: How would I explicitly choose the template parameters in order to get the same result as with the defaults (ie "What actually are the default parameters"?)?.

Upvotes: 1

Views: 83

Answers (1)

Wave and Matter
Wave and Matter

Reputation: 161

I found the answer following the advice of user Richard Critten.

From Code-reading it was clear, that the second template parameter must be a Triangulation_data_structure, but with more template parameters which would have to be resolved further. So I tried to gather information on the default parameters of that type in turn.

Trying to force a compiler error (surprisingly resulting only in a warning), I added

Triangulation::Triangulation_ds test; 
test="XX";

Getting the warning

triangulation2.cpp:86:8: warning: invalid user-defined conversion from ‘const char [3]’ to ‘const CGAL::Triangulation_data_structure<CGAL::Dynamic_dimension_tag, CGAL::Triangulation_vertex<CGAL::Epick_d<CGAL::Dynamic_dimension_tag>, CGAL::No_vertex_data, CGAL::Default>, CGAL::Triangulation_full_cell<CGAL::Epick_d<CGAL::Dynamic_dimension_tag>, CGAL::No_full_cell_data, CGAL::Default>  >&’ [-fpermissive]

Apparently this is the default instantiation I was looking for. A simple copy+paste of the type from the error message gives me compiling+working code.

typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag >   K;

typedef CGAL::Triangulation_data_structure
<CGAL::Dynamic_dimension_tag,
CGAL::Triangulation_vertex<CGAL::Epick_d<CGAL::Dynamic_dimension_tag>,CGAL::No_vertex_data, CGAL::Default>,
CGAL::Triangulation_full_cell<CGAL::Epick_d<CGAL::Dynamic_dimension_tag>, CGAL::No_full_cell_data, CGAL::Default>  >  TDS;

typedef CGAL::Delaunay_triangulation<K,TDS>  Triangulation;

Or in a slightly more readable form making use of more structured typedefs:

typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag >   K;
typedef CGAL::Triangulation_vertex<K,CGAL::No_vertex_data, CGAL::Default>  default_vertex;
typedef CGAL::Triangulation_full_cell<K, CGAL::No_full_cell_data, CGAL::Default>  default_cell;
typedef CGAL::Triangulation_data_structure<CGAL::Dynamic_dimension_tag, default_vertex, default_cell >  default_TDS;
typedef CGAL::Delaunay_triangulation<K,default_TDS>  Triangulation;

As it seems, this information is very useful also for the ultimate goal of my question, since it is possible to replace

typedef CGAL::Triangulation_vertex<K,CGAL::No_vertex_data, CGAL::Default>  default_vertex;

by(for instance)

typedef CGAL::Triangulation_vertex<K,double, CGAL::Default>  default_vertex;

which will allow me to add a double data member to my vertices without having to create a custom vertex class.

The data can then be set by using one of those Triangulation classes "insert" methods which return a vertex handle. The vertex handle can be assigned to a variable and the data can be set with the vertices data() member:

void runTriangulation(Triangulation tri, std::vector<TPoint>  points, std::vector<double> mydata)
{

   //tri.insert(points.begin(), points.end());
   for(int ip=0; ip<points.size(); ip++)
   {
      Triangulation::Vertex_handle vh = tri.insert(points[ip]);
      vh->data() = mydata[ip];
   }
}

Upvotes: 1

Related Questions