Search code examples
colorspointcgaltriangulation

Color points on CGAL Triangulation_3


I am trying to give a color to the points into a triangulation_3 on CGAL. I just take the example from CGAL describe here

I made a simple modification on this example to be able to draw the triangulation:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Delaunay_triangulation_cell_base_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h>
#include <CGAL/IO/Color.h>
#include <CGAL/draw_triangulation_3.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel         K;
typedef CGAL::Triangulation_vertex_base_with_info_3<CGAL::Color, K> Vb;
typedef CGAL::Delaunay_triangulation_cell_base_3<K>                 Cb;
typedef CGAL::Triangulation_data_structure_3<Vb, Cb>                Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds>                      Delaunay;
typedef Delaunay::Point                                             Point;
int main()
{
  Delaunay T;
  T.insert(Point(0,0,0));
  T.insert(Point(1,0,0));
  T.insert(Point(0,1,0));
  T.insert(Point(0,0,1));
  T.insert(Point(2,2,2));
  T.insert(Point(-1,0,1));
  // Set the color of finite vertices of degree 6 to red.
  Delaunay::Finite_vertices_iterator vit;
  for (Delaunay::Vertex_handle v : T.finite_vertex_handles())
      if (T.degree(v) == 6)
    v->info() = CGAL::Color(0,255,0);

  CGAL::draw(T);
  return 0;
}

But no matter which color I put on v->info() = CGAL::Color(0,255,0); the method draw always give the same red points in the window displayed:

Triangulation

I understand that the code is constructing a data structure that contains color information but this could be independent of the draw method, so i think that the window doesn't show me green points because this is not the way to color the points. If so, what is the way to get a triangulation with green points using the draw method?'.


Solution

  • In its current form, the viewer is not able to change the color of vertices nor edges.

    But it is easy to change the code.

    1. Copy the file draw_triangulation_3.h in your project
    2. edit the method void compute_vertex(Vertex_const_handle vh), (line 92 in this file) to use the add_point method with a color as parameter: add_point(vh->point(), vh->info());