Building faces from TopoDS_Compounds and TopoDS_Edges

Hello, i am working on a small CAD importer. I have the XCAF doc of the file and while browsing the shapes, I'm getting lots of TopoDS_Faces which i know how to translate.
Other than TopoDS_Faces in the document there are a number of Compounds grouping inside other compounds or edges.

I'd like to convert these edges in TopoDS_Faces. Browsing the forum I'v found the BRepBuilderAPI_MakeWire and BRepBuilderAPI_MakeFace classes. So I wrote down a little funcion to collect the edges and to fill a face vector:

void facesFromCompounds (const TopoDS_Shape &Shape, std::vector &topoFaceVector)
// if the compound is made of other compunds... i go down one level in the recursion
for(TopoDS_Iterator iter(Shape); iter.More(); iter.Next())
if(iter.Value ().ShapeType()==TopAbs_COMPOUND)
facesFromCompounds (iter.Value (), topoFaceVector);

// if the compound holds the edges, i extract them and then feed em to the builder
std::vector edgeVector;
for(TopoDS_Iterator iter(Shape); iter.More(); iter.Next())
if(iter.Value ().ShapeType()==TopAbs_EDGE)
TopoDS_Edge edge = TopoDS::Edge(iter.Value());
edgeVector.push_back (edge);

if (edgeVector.size ()!=0)
BRepBuilderAPI_MakeWire wireMaker (edgeVector[0]);

for (int i=1;i wireMaker.Add (edgeVector[i]);

//wireMaker.Build ();

TopoDS_Wire wire = wireMaker.Wire();

BRepBuilderAPI_MakeFace faceMaker (wire);

faceMaker.Build ();
TopoDS_Shape geoFace = faceMaker.Face();

topoFaceVector.push_back (geoFace);

this function crashes everytime in the

TopoDS_Wire wire = wireMaker.Wire();

instruction. Am i applying it to the wrong edges?
Is there a way to check if the builder is doing fine before it crashes?


Seac02Devel's picture

after adding a small error control i've discovered that the builder gets stuck in the "disconnectedwire" error. Probably one or more edges are't touching.
The problem is that i know that it's possible to reconstruct the geometry (if i let OCC do it automatically it works) so i assume i am doing something wrong.

Is there a way to find out the order in which i should add the edges?


sergey zaritchny's picture

Hi Enrico,
First of all you should analyze a set of edges coming from compound (s) to find suitable candidates for wire (s) building. Resulting Wire (s) (to be used for face creation) should be well oriented, connected, not self-intersected and etc. So, you should take care (during wire building) to satisfy these conditions.
The most suitable method - ShapeAnalysis_FreeBounds::ConnectEdgesToWires (myclass; edges : in out HSequenceOfShape from TopTools; ...). Pay your attention to the value of input parameter.
Good luck.