Error when build triangle meshes

jianbaoxia

CAD master
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 below:
1685517368506.png1685517381265.png
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:
Code:
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();
}
o_O o_O o_O
 

Attachments

  • aTest.step
    3.6 MB · Views: 2
  • ruledFace.step
    10.1 KB · Views: 2

jianbaoxia

CAD master
I copied your code and got this mesh out of it:

View attachment 624
It looks good, 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. 😁 (y)
 

JSlyadne

Administrator
Staff member
In case you actually need to save a data to a file, I'd recommend to go with Obj or Stl formats as they are simply more suitable for polygonal data storage, Step is excessive for such a need. To write the data to Obj or STL formats, look at
Code:
asiAlgo_Utils::WriteStl(...)
or
Code:
asiAlgOBJ:: Write(...)
methods.
 
Top