creating indexed face sets from OpenCascade shapes

Does anyone know a way of creating an indexed face set from a TopoDS_Solid object (or TopoDS_Shell)?

By indexed face set, I mean a representation like that in VRML or OpenInventor. What I want is coordinates of all the vertices stored in an array and a list of all the faces in terms of the indices into the array of vertices. For example, if my shape contains a triangle (for the sake of simplicity), I would like the following:

// array of vertices contains the following coordinates:
0: (1.0, 0.0, 0.0)
1: (0.0, 1.0, 0.0)
2: (0.0, 0.0, 1.0)

// array of faces contains the following:
0: (0, 1, 2)

i.e. the face consists of 0th vertex, 1st vertex, and 2nd vertex.


I know how to iterate over the vertices in the

Hugues Delorme's picture

You should be able to do that thanks to the class TopExp_Explorer, dedicated to the visiting of topological shapes.

Having a TopoDS_Solid object named "solid", iterate on its faces, and on the vertices of these faces by doing :

TopExp_Explorer face_ex;
for (face_ex.Init(solid, TopAbs_FACE); face_ex.More(); face_ex.Next())
TopExp_Explorer vertex_ex;
for (vertex_ex.Init(face_ex.Current (), TopAbs_VERTEX); vertex_ex.More(); vertex_ex.Next())
// update your indexed face set here
// update your indexed face set here