Error when build triangle meshes

Hello everyone, I'm JianBaoXia.
Today I attempted to triangulate a B-spline surface, but the results were not satisfactory. The outcome is shown in the image I upload.

It is evident that triangulation seems to fail in regions with high curvature. I am unsure if this is a limitation of the OCCT algorithms or if I have not used the related tools correctly.

There is my demo:
Handle(Poly_Triangulation) BuildTriangulation(const TopoDS_Face& face, const Standard_Real& linDeflection)
// ! 1、
Handle(Poly_CoherentTriangulation) tris = new Poly_CoherentTriangulation;

BRepMesh_IncrementalMesh meshGen(face, linDeflection);

TopLoc_Location L; //!
const Handle(Poly_Triangulation)& poly = BRep_Tool::Triangulation(face, L);

//! 2、add note
std::unordered_map<int, int> nodesMap;
for (int iNode = 1; iNode <= poly->NbNodes(); ++iNode)
const int n = tris->SetNode(poly->Node(iNode).Transformed(L).XYZ());

nodesMap.insert({ iNode, n });

// 3、add triangle
for (int iTri = 1; iTri <= poly->NbTriangles(); ++iTri)
const Poly_Triangle& tri = poly->Triangle(iTri);

int iNodes[3];
tri.Get(iNodes[0], iNodes[1], iNodes[2]);

if (face.Orientation() == TopAbs_REVERSED)
std::swap(iNodes[1], iNodes[2]);

tris->AddTriangle(nodesMap[iNodes[0]], nodesMap[iNodes[1]], nodesMap[iNodes[2]]);
return tris->GetTriangulation();

Mikhail Sazonov's picture

The code seems to be right. However, I wonder why do you use CoherentTriangulation? Why don't you create directly Poly_Triangulation?
It is also unclear how you obtain the presentation of bad triangulation, and how you obtain the STEP file with edges of bad triangulation.

linbei jianbaoxia's picture

Thank you for your help. I am not familiar with the triangulation tools in OCCT, so I wasn't able to use the appropriate classes correctly.
I don't know how to display it after triangulation. So I connected all the triangles by their vertices to form edges, and then merged them into a TopoDS_Compound and exported it as a STEP model. Now it seems that I made a mistake in this step.

Dmitrii Pasukhin's picture

STEP support import/export tesselation data only after version 7.7.0

For writing/reading tess data you need change static parameters:

  Interface_Static::SetIVal("read.step.tessellated", 1);
  Interface_Static::SetIVal("write.step.tessellated", 1);

But I recommended to use Mesh format to test: Gltf, obj, VRML

Best regards, Dmitrii.

linbei jianbaoxia's picture

Thank you very much for your advice. It has expanded my knowledge. Best wishes to you!