Question

Having an arbitrary polyhedron in CGAL (one that can be convex, concave or, even, have holes) how can I triangulate its faces so that I can create OpenGL Buffers for rendering?

I have seen the convex_hull_3() returns a polyhedron that has triangulated faces, but it won't do what I want for arbitrary polyhedrons.

Was it helpful?

Solution

The header file <CGAL/triangulate_polyhedron.h> contains a non-documented function

template <typename Polyhedron>
void triangulate_polyhedron(Polyhedron& p)

that is working with CGAL::Exact_predicates_inexact_constructions_kernel for example.

OTHER TIPS

The Polygon Mesh Processing package provides the function CGAL::Polygon_mesh_processing::triangulate_faces with multiple overloads. The simplest thing to do would be

typedef CGAL::Simple_cartesian<float> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;

Polyhedron_3 polyhedron = load_my_polyhedron();
CGAL::Polygon_mesh_processing::triangulate_faces(polyhedron);

After that, all faces in polyhedron are triangles.

The function modifies the model in-place, so one has to use a HalfedgeDS that supports removal. This is the default, but, for example, HalfedgeDS_vector won't do.

See also an official example that uses Surface_mesh instead of Polyhedron_3: Polygon_mesh_processing/triangulate_faces_example.cpp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top