wenzaifou
wenzaifou

Reputation: 81

How to draw triangles using CGAL?

Problem description
I have a list which contains many triangle_3 objects. It should look like a closed surface mesh, but I don't use a Surface_mesh to represent it for many reasons. However, I really want to check it, so I want to draw it. I read CGAL manual, but I didn't find any functions that I can use on Windows. I found a function named draw_triangles in the Geomview package, but the user manual of this package says "The functionality described in this chapter is not available on Windows". It seems that it is not possible to use draw_triangles function in my programming environment. How can I draw the triangles?
Programming environment
windows x64
VS 2017
CGAL 5.3

Upvotes: 1

Views: 230

Answers (1)

sloriot
sloriot

Reputation: 6263

I would advice to build a Surface_mesh only for display purpose. You can use the following example. If your triangle soup is not directly a valid surface mesh, you can use the functions orient_polygon_soup() and polygon_soup_to_polygon_mesh().

See also this example.

EDIT I never tried it but it seems that you can change color globally or per face by adding a partial template specialization to the following class:

namespace CGAL
{

// Default color functor; user can change it to have its own face color
struct DefaultColorFunctorFaceGraph
{
  template<typename Graph>
  CGAL::IO::Color operator()(const Graph&,
                         typename boost::graph_traits<Graph>::face_descriptor fh) const
  {
    if (fh==boost::graph_traits<Graph>::null_face()) // use to get the mono color
      return CGAL::IO::Color(100, 125, 200); // R G B between 0-255

    return get_random_color(CGAL::get_default_random());
  }
};

}

Upvotes: 1

Related Questions