Search code examples
c++cgal

Drawing a colored mesh in CGAL


In CGAL have a Surface_mesh<Point_3> with Surface_mesh::Property_map<Surface_mesh::Face_index, CGAL::Color>. I use CGAL::draw() method to draw this mesh, however the different colors of faces don't reflect. What am I missing?


Solution

  • The current version of basic viewer of Surface mesh does not take into account the color of faces.

    However, it is easy to change the code.

    1. Have a look to the file draw_surface_mesh.h.
    2. Add a functor MyColorFunctorSM (inspired by the existing DefaultColorFunctorSM) that returns the color of a face given its index
    3. Replace in the draw function DefaultColorFunctorSM by your new functor MyColorFunctorSM.

    (If you don't want to modity the CGAL file, you can define your functor in your code, and copy/paste the draw function in your code before to modify it).