How to get unique node ids for each vertex of a shape while triangulating its surface?

I am using the below to triangulate a shape:

int main()
{
  TopoDS_Shape box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), gp_Pnt(1, 1, 1));
  BRepMesh_IncrementalMesh aMesher(box, 1.2, Standard_False, 1.8, Standard_True);

  TopExp_Explorer ex;
  for (ex.Init(box, TopAbs_FACE); ex.More(); ex.Next())
  {
    TopoDS_Face face = TopoDS::Face(ex.Current());
    TopLoc_Location location;
    const Handle(Poly_Triangulation) triangles = BRep_Tool::Triangulation(face, location);
    for (int i = 1; i <= triangles->NbTriangles(); ++i)
    {
      Standard_Integer node1, node2, node3;
      if (face.Orientation() == TopAbs_REVERSED)
      {
        triangles->Triangle(i).Get(node1, node3, node2);
      }
      else
      {
        triangles->Triangle(i).Get(node1, node2, node3);
      }
      std::cout << node1 << " " << node2 << " " << node3 << std::endl;
    }
  }
}

However for each face of the box, I only get node numbers from 1 to 4. How do I get numbers from 1 to 8 (or 0 to 7), where the numbers uniquely represent the vertices of my cube?

gkv311 n's picture

Each TopoDS_Face defines it's own Poly_Triangulation, so that to have a unified triangulation for an entire solid or another shape you'll have to fill in triangulation of your own. Connectivity is preserved via Poly_PolygonOnTriangulation stored inside TopoDS_Edge, connecting TopoDS_Face.

Alternatively, you may use tools like Poly_MergeNodesTool to create new triangulation considering only geometrical connectivity of nodes, regardless of topological connectivity.

DKGH's picture

Couldn't understand what gkv said above. Ended up implementing a few hash maps.