Search code examples
inheritancecolorskernelpointcgal

Add variable to CGAL's Point class


I am trying to add a color variable (unsigned char) to CGAL's Point_3 class so I can access the color after doing Delaunay triangulation.

What I have tried is using Triangulation_vertex_base_with_info_3 to store the color like this (following the example at http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_3/Chapter_main.html#Subsection_39.5.3)

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned char, K> Vb;
typedef CGAL::Triangulation_data_structure_3<Vb> Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds> Triangulation;
typedef Triangulation::Point CGAL_Point;

//...
//here I make a vector of pairs of points and their color

std::vector<std::pair<CGAL_Point, unsigned char> > points;

Point currentPoint;
for (int i=0; i<roiPoints.size(); i++){
    currentPoint=roiPoints[i];
    points.push_back(std::make_pair(CGAL_Point(currentPoint.x, currentPoint.y, currentPoint.z), roiColors[i]));
} 

//...
//triangulation
T.clear();
T.insert(points.begin(), points.end());

What I actually want to achieve is to be able to access vertices colors through the Triangulation::Tetrahedron class after doing the triangulation.

Let say I have a point P at (x,y,z). After triangulation I find the Tetrahedron t which contains this point P and I have access to this tetrahedron's vertices (using t.vertex(0..3)). This returns vertices of type Point_3 and I can't access the colors I have stored before.

I guess a way to do this is to create my own Point class which contains the color information. That's easy, but I don't understand how to use this class instead of Point_3. I found that I also have to write my own Kernel to do this and an example at http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23/Chapter_main.html#Section_11.5 but I can't figure out what Kernel should I use as base class or what functions should my Kernel even contain.

I even found two similar topics here at stackoverflow: Customizing CGAL Kernel with my own Point class and CGAL: Inheritance and the kernel but they didn't help me.

Thank you for your help!


Solution

  • From your description, I think you simply need to add the color inside the vertex class. After the locate, you'll have the simplex and will be able to access the color inside the vertices.

    See the examples here.