Wed, 05/31/2023 - 14:45
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();
}
Wed, 05/31/2023 - 22:25
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.
Thu, 06/01/2023 - 05:55
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.
Thu, 06/01/2023 - 11:51
STEP support import/export tesselation data only after version 7.7.0
For writing/reading tess data you need change static parameters:
But I recommended to use Mesh format to test: Gltf, obj, VRML
Best regards, Dmitrii.
Mon, 06/05/2023 - 14:24
Thank you very much for your advice. It has expanded my knowledge. Best wishes to you!