Triangulate a TopoDS_Shape...

I like a simple tutorial how to triangulate a TopoDS_Shape. Where can I find such tutorials, and code samples?
In the end I like to retrieve all vertex and triangles that is in a TopoDS_Shape.

Hugues's picture

Here is how you can retrieve a triangulation of a TopoDS_Face object :

TopoDS_Face face = //load it

TopLoc_Location location;
Handle_Poly_Triangulation triangulation =
BRep_Tool::Triangulation (face, location);
const TColgp_Array1OfPnt& nodes = triangulation->Nodes ();
const Poly_Array1OfTriangle& triangles = triangulation->Triangles ();
// Iterate over the triangles and their nodes.
for (int i = triangles.Lower (); i <= triangles.Upper (); i++)
const Poly_Triangle& triangle = triangles (i);
const gp_Pnt& p1 = nodes (triangle (1));
const gp_Pnt& p2 = nodes (triangle (2));
const gp_Pnt& p3 = nodes (triangle (3));
// Do something with the current triangle's nodes

If you want to set the deflection of the triangulation, call this before iterating over the triangles :

BRepMesh::Mesh (face, 0.1); // deflection == 0.1 here

d00_ape's picture

Yhanks I'll try that.
By the way. I do like to figure out things myself. How did you figure that out. I've scaned through the OCC doc but I couldn't figure this topic out with help of that...
Are there any good tutorials on ?


Hugues's picture


Open OCC's technical documentation and search for "Triangulation", this will give you the interesting materials. This is how I found things about triangulation retrieval.
Meshing operations were already given in this forum.
Generally I peel interestings posts in this forum and make searches in the technical documentation which is unfortunately not complete, but almost.
Also grep applied in the OCC/ros/src directory works well (filter CDL files).

d00_ape's picture

OK, thanks. In which program do you open those cdl-files?