Getting the triangulation from a shape

Is there a function to get the triangulation from a TopoDS_Shape? I make a triangulation on a face with

Handle (BRepMesh_Discret) mesh = new BRepMesh_Discret(
1,
my_Face,
30*3.1415/180,
TRUE,
TRUE,//this tells that the trangulation will be stored in the shape
FALSE,
FALSE
);

The objective is to get the triangulation from that face in the form of Poly_Triangulation or something else. In fact I'm interested to get the coordinates of the nodes and the triangles with the node indices. I saw that BRepMesh_Discret has a member Triangle but this returns a BRepMesh_Triangle which has only edges and orientations. So to get the nine(3x3) coordinates of a triangle I have to ask for every edge the endpoints, compare them to not store duplicates and so one, while Poly_Triangulation is a more elegant class having the nodes with their coordinates and triangles with indices. I tried to get with
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(my_Face,L), but it is very strange because it gives me a Poly_Triangulation even if it wasn't triangulated with the Discret method. I don't know if BRep_Tool::Triangulation makes himself a triangulation or not?
Another question would be, how can I control the coarseness of the generated triangulation. With the above settings I get a very fine triangulation for any shape I tried to triangulate. I don't understand the meaning of the deflection. It is the minimum distance between the generated node and the surface?

Andras

Rob Bachrach's picture

You are correct in using BRep_Tool::Triangulation to get the final triangulation. Understand that if you are using the OpenCASCADE visualization to display your shape, it also uses the triangulation. If the face does not already have a triangulation, it will create one. This is why you may be seeing a triangulation on faces that you did not access directly.

Your nodes will always fall on the surface of the face. The deflection is the distance that an edge of the triangulation can be from the face. Imagine a 2D circle with a chord. The ends of the chord are the nodes. The deflection is the distance from the chord to the circle or the chord height.

The angle is the maximum angle between two triangle edges along an actual edge.

For a courser mesh, increase the deflection.

Andras's picture

OK thanks for the reply,

A small question only. Triangulation will create a new one only and only when it doesn't find any?

Rob Bachrach's picture

It depends on the mesher. For the most part, they only create a new one if the new one has a smaller deflection (i.e. better mesh). I always call BRepTools::Clean(myShape) first to make sure the previous triangulation has been cleared.