5

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.

zync
  • 463
  • 3
  • 17

2 Answers2

3

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.

sloriot
  • 6,070
  • 18
  • 27
  • My project's working with Simple_cartesian kernel. Is there a way I can use that function with this kernel? Sorry, I'm new to CGAL... – zync May 12 '14 at 12:56
  • You can try, but there is no guarantee on the result. See http://www.cgal.org/FAQ.html#inexact_NT. – sloriot May 12 '14 at 13:16
  • What can I do to convert from a polyhedron with a Simple_cartesian to one with Exact_predicates_inexact_constructions_kernel? – zync May 13 '14 at 15:32
  • You just need to change the kernel and that should work. – sloriot May 13 '14 at 19:07
  • FYI: this header has since been removed from the CGAL project. A new package for triangulations has been introduced: http://doc.cgal.org/latest/Triangulation/index.html – scry Dec 18 '15 at 00:28
  • @scry: Note that you should use this package in case you have a dimension greater than 3. For dimension 2 and 3, dimension dedicated packages are more efficient. – sloriot Dec 18 '15 at 08:38
1

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

Marcin Kaczmarek
  • 1,063
  • 2
  • 9
  • 20