Skip to first unread message

Nov 2, 2017, 9:36:12 AM11/2/17
to oce-dev
In a custom STEP importer, I was able to leverage UV-NURB-coordinates(let's call them ST here forward) on a surface while tessellating to map UV texture coordinates for an exported result. I would like to use OCE to do a similar thing, as the mesh quality and STEP support is much better than my custom solution. I have researched for a way to do this in OpenCascade and have mostly seen visualization results where the texture was assigned either by map (as I understand gaining this from a post-processor like blender) or clipPlane fitting. To be specific I have seen the documentation for AIS_Shape and MeshVS_NodalColorPrsBuilder, which as far as I understand serve only the goal of working with the built-in visualizer and interactive handles. 

This is the entirety of the code I applied that retrieves the mesh triangulation and saves to an .stl, I would like to traverse each shape -> surface -> mesh -> triangle, and retrieve the triangle vertices ST coordinates on the BREP or on the Surface parameters (either is fine). I understand this is not very developed code but from reading online this seems to be not possible. 

  STEPControl_Reader stepReader;
  IFSelect_ReturnStatus stat = stepReader.ReadFile("file.stp");
  Standard_Integer NbRoots = stepReader.NbRootsForTransfer();
  Standard_Integer NbTrans = stepReader.TransferRoots();
  TopoDS_Shape Original_Solid = stepReader.OneShape();
  for (TopExp_Explorer exp(Original_Solid, TopAbs_FACE); exp.More(); exp.Next())
    TopoDS_Face face = TopoDS::Face(exp.Current());
    BRepMesh_IncrementalMesh(face, .05);
  StlAPI_Writer stlWriter = StlAPI_Writer();
  stlWriter.ASCIIMode() = Standard_False;
  StlAPI_ErrorStatus outStat = stlWriter.Write(Original_Solid, "out.stl");

Nov 2, 2017, 2:29:12 PM11/2/17
to oce-dev
I would like to update this posting with some updates.  I am now capable of traversing the mesh and I do see that UV for vertices has been saved out. I do not yet know in respect to what surface but this is a lead that I can follow. 

for (TopExp_Explorer exp(Original_Solid, TopAbs_FACE); exp.More(); exp.Next())
    TopoDS_Face face = TopoDS::Face(exp.Current());
    BRepMesh_IncrementalMesh faceMesh(face, .05);
    TopLoc_Location loc;
    Handle(Poly_Triangulation) tri = BRep_Tool::Triangulation(face, loc);
    if (tri)
      // get the nodes
      if (tri->HasUVNodes())
        const Poly_Array1OfTriangle &tris = tri->Triangles();
        const TColgp_Array1OfPnt &triPos = tri->Nodes();
        const TColgp_Array1OfPnt2d &triUV = tri->UVNodes();
        for (Standard_Integer iCount = tris.Lower(); iCount < tris.Length(); ++iCount)
          // get the node indexes for this triangle
          const Poly_Triangle& tri = tris(iCount);
          Standard_Integer indexPos0 = tri(1);
          Standard_Integer indexPos1 = tri(2);
          Standard_Integer indexPos2 = tri(3);
          gp_Pnt v0 = triPos(indexPos0);
          gp_Pnt2d uv0 = triUV(indexPos0);
          gp_Pnt v1 = triPos(indexPos1);
          gp_Pnt2d uv1 = triUV(indexPos1);
          gp_Pnt v2 = triPos(indexPos2);
          gp_Pnt2d uv2 = triUV(indexPos2);

I also found in the OCCT email list a function for point inversion that could be helpful as well

gp_Pnt2d FaceParameters(const TopoDS_Face &face,const gp_Pnt &pt)
// get face as surface
const Handle(Geom_Surface) &surface = BRep_Tool::Surface(face);
// create shape analysis object
ShapeAnalysis_Surface sas(surface);
// get UV of point on surface
gp_Pnt2d uv = sas.ValueOfUV(pt, 0.01);
// return parameters of point on face
return uv;

thomas krijnen

Nov 3, 2017, 5:45:46 AM11/3/17
to oce-dev
You can reuse the code in the 2nd snippet to obtain surface from the face:


Hope that helps,

Kind regards,


Op donderdag 2 november 2017 19:29:12 UTC+1 schreef
Reply all
Reply to author
0 new messages