For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

How to triangularize the shape, not surface.

Jun WANG's picture
Forums: 

Maybe you can say that a shape(also shell) consists of surface and hence the shape(shell) can be triangularized surface by surface by using of "BRep_Tool::Triangulation". However, if so,there are something wrong with the generated triangle meshes at the boundary edge of adjacent surfaces. So I want to generate a whole triangle meshes for the shape(shell). How can I carry out that??????

Rob Bachrach's picture

You would still use the BRepMesh_FastDiscrete to mesh your entire shell (not face-by-face). Just make sure you set the withShare parameter in the constructor to true. This causes the mesher to share the meshes of coincident edges and, therefore, matches the meshes of adjacent faces.

Jun WANG's picture

Thanks a lot. Can you give me more details?
//----------------------
TopoDS_Shape tpShape = ...;// Suppose "tpShape" is the shell which needs to be triangulized.
... // Can you give some details
//----------------------

Rob Bachrach's picture

Of course you will have to come up with a deflection and angle for your geometry. My code looks something like this:

BRepMesh_Discrete *myMesh =
new BRepMesh_Discrete(deflection, tpShape, angle, Standard_True, Standard_True);
if (myMesh != NULL) delete myMesh;

The first Standard_True keeps the mesh continuous at the edges. The second tells it to store the final mesh in the shape, allowing it to be accessed through the Poly_Triangulation. Since the mesh is stored in the shape, I do not keep the BRepMesh_Discrete object around.

Jun WANG's picture

Thanks for your reply. After that, how can I explore the triangles, nodes???
So I am wondering if you can give me a small episode, Thank you VERY much!!!

Rob Bachrach's picture

Assuming you store the triangulation in the shape, as described above...

TopExp_Explorer exFace;
for (exFace.Init(tpShape, TopAbs_FACE);
exFace.More(); exFace.Next()) {
TopoDS_Face face = TopoDS::Face(exFace.Current());

// get the triangulation
TopLoc_Location loc;
Handle(Poly_Triangulation) tri = BRep_Tool::Triangulation(face, loc);
if (tri.IsNull()) continue;

// create a transformation from the location
gp_Trsf xloc = loc;

// get the nodes
const TColgp_Array1OfPnt &nodes = tri->Nodes();
for (iCount = nodes.Lower(); iCount Standard_Real x,y,z;
nodes(iCount).Coord(x,y,z);
xloc.Transforms(x,y,z);
// do something with the point
}

// copy the polygons
Standard_Integer i1, i2, i3;
const Poly_Array1OfTriangle &tris = tri->Triangles();
for (iCount = tris.Lower(); iCount // get the node indexes for this triangle
tris(iCount).Get(i1, i2, i3);

// reverse the triangle orientation if the face is reversed
if (face.Orientation() != TopAbs_FORWARD) {
// do something with the node indexes
}
else {
// do something with the node indexes
}
}
}

davenkin's picture

Hi,Rob Bachrach. The example you gave can get nodes from a face, but how can I get the inner nodes of a solid.

LeeYin's picture

Hi,Rob Bachrach. The example you gave can get nodes from a face, but how can I get the inner nodes of a solid£¿£¿

Ling's picture

if (face.Orientation() != TopAbs_FORWARD)

when read Iges file , we want to iges to STL ,,the face.Orientation() is always = TopAbs_FORWARD for every face...

what's wrong with this .? how to process this problem? can you give me some advices Thank you very much

Ling's picture

if (face.Orientation() != TopAbs_FORWARD)

when read Iges file , we want to iges to STL ,,the face.Orientation() is always = TopAbs_FORWARD for every face...

what's wrong with this .? how to process this problem? can you give me some advices Thank you very much

Jun WANG's picture

Thank you very much. However, I can NOT find the BRepMesh_FastDiscrete ??? Is your OCC 6.3 version ??? Does anyone know that ??? Thanks in advance.

Rob Bachrach's picture

Sorry, this was a typo on my part. It is actually BRepMesh_FastDiscret (without the trailing "e"). I guess the French spell it differently. And yes, you should find the header file in the inc directory.

Rob