Face Triangulation


I think i have a very simple problem but I cant solve it.
I simply want to create ONE TopoDS_Face and want to read the triangulation of it. The Face consists of several Wires.
I am able to create the Face by BRepBuilderAPI_MakeFace.

This is the way I am try to read the triangulation data:

TopoDS_Face face = // face loaded!
TopLoc_Location aLoc;
Handle(Poly_Triangulation) myPoly = BRep_Tool::Triangulation(face,aLoc);
if (myPoly.IsNull()) {
throw std::exception("error");

But everytime I run the app, myPoly.IsNull() is true!
Whats wrong? Once more, i only want to triangulate one Face, not a complete Shape!
Does anyone has an example code or could help me?

Thank you in advance!


Rob Bachrach's picture

You're code to get the triangulation is correct. The problem is that a triangulation has not been generated and attached to the face. The easiest way to generate the mesh is to call:

BRepMesh::Mesh(face, d); // d is the deflection for the mesh

Then, you can use your existing code.

AndyDF's picture


thank you for your fast answer. I knew it that it is easy. (for you) ;)
What would be a proper value for deflection? Sorry, i am new to OCC ...


Rob Bachrach's picture

The value of deflection kind of depends on your geometry and the desired accuracy of the mesh. It defines the distance between a curved edge or surface and the corresponding edge or surface of the mesh triangle. So, it has no effect on flat, square surfaces and should vary based on the scale of the geometry.

I typically find the diagonal of the bounding box of my geometry and make dx a fraction of that:

// compute the bounding box for the shape (face)
Bnd_Box bounds;
BRepBndLib::Add(myShape, bounds);

// compute the diagonal length of the bounding box
Standard_Real fXMin, fYMin, fZMin, fXMax, fYMax, fZMax;
bounds.Get(fXMin, fYMin, fZMin, fXMax, fYMax, fZMax);
Standard_Real fDiag = sqrt(((fXMax-fXMin)*(fXMax-fXMin)) + ((fYMax-fYMin)*(fYMax-fYMin)) + ((fZMax-fZMin)*(fZMax-fZMin)));

// set the deflection to 1/1000 of the diagonal length
Standard_Real fDeflection = fDiag/1000.0;