What are the subordinates of TopoDS_Shape

Does "solid" in OCC correspond to "body"?

If I traverse the Solids under a Shape, and then iterate through the Faces within each Solid, will that give me all the Faces?

I tried doing this, but the Faces I obtained were only a subset.

gkv311 n's picture

Does "solid" in OCC correspond to "body"?

From Training: Topology - TopoDS_Solid is a collection of TopoDS_Shell, and TopoDS_Shell is a collection of TopoDS_Face.

The 'body' from other kernels might have different type - closed solid (can be roughly mapped to TopoDS_Solid), open sheet (can be mapped to TopoDS_Shell, which is not inside of a TopoDS_Solid), acorn (corresponds to TopoDS_Vertex which is not part of any TopoDS_Edge).

If I traverse the Solids under a Shape, and then iterate through the Faces within each Solid, will that give me all the Faces?

The simplest Solid like a sphere will consist of one Shell and 1+ Faces. The Solid with inner hole parts (imagine a small sphere cut from a larger box) will consists of one outer Shell and 1+ inner hole Shells.

I tried doing this, but the Faces I obtained were only a subset.

There are different ways to traverse topology in OCCT. Please share some sample shape, code snippet and why you think you get unexpected result.

Xu Boyi's picture

Thanks for your answer.

Here is my code snippet.

// the TopoShape from a STEP file
// then use convertToBody function
for (TopExp_Explorer aSolidExp(aTopoShape, TopAbs_SOLID); aSolidExp.More(); aSolidExp.Next(), index++)
{
    m_aDebugLog << std::format("\nSolid[{}]:", index) << std::endl;
    TopoDS_Solid aTopoSolid = TopoDS::Solid(aSolidExp.Current());
    Body* aBody = convertToBody(aTopoSolid);
    m_aBodyVec.push_back(aBody);
}
// 将一个TopoDS_Solid转换为Body
Body* TopoTools::convertToBody(TopoDS_Solid& aTopoSolid)
{
    BodyInfo aBodyInfo;
    aBodyInfo.aBody = new Body();
    aBodyInfo.aTopoSolid = aTopoSolid;
    //aBodyInfo.aShape = healShape(aTopoSolid);
    m_aDebugLog << "Converting a new body......" << std::endl;
    // 遍历TopoDS_Solid中的所有边,并保存到aBodyInfo->aEdgeMap中
    for (TopExp_Explorer anEdgeExp(aBodyInfo.aTopoSolid, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next())
    {
        TopoDS_Edge aTopoEdge = TopoDS::Edge(anEdgeExp.Current());
        Edge* anEdge = convertToEdge(aTopoEdge);
        aBodyInfo.anEdgeMap.Bind(aTopoEdge, anEdge);
    }
    // 遍历TopoDS_Solid中的所有环,并保存到aBodyInfo->aLoopMap中
    for (TopExp_Explorer aWireExp(aBodyInfo.aTopoSolid, TopAbs_WIRE); aWireExp.More(); aWireExp.Next())
    {
        TopoDS_Wire aTopoWire = TopoDS::Wire(aWireExp.Current());
        Loop* aLoop = new Loop();
        for (TopExp_Explorer aExp(aTopoWire, TopAbs_EDGE); aExp.More(); aExp.Next())
        {
            TopoDS_Edge aTopoEdge = TopoDS::Edge(aExp.Current());
            Edge* anEdge = aBodyInfo.anEdgeMap.Find(aTopoEdge);
            aLoop->addEdge(*anEdge);
        }
        aBodyInfo.aLoopMap.Bind(aTopoWire, aLoop);
    }
    // 遍历TopoDS_Solid中的所有面,并保存到aBodyInfo->aBody中
    Standard_Integer faceIndex = 1;
    for (TopExp_Explorer aFaceExp(aBodyInfo.aTopoSolid, TopAbs_FACE); aFaceExp.More(); aFaceExp.Next(), faceIndex++)
    {
        TopoDS_Face aTopoFace = TopoDS::Face(aFaceExp.Current());
        Face* aFace = convertToFace(aTopoFace);
        aFace->index = faceIndex;
        for (TopExp_Explorer aWireExp(aTopoFace, TopAbs_WIRE); aWireExp.More(); aWireExp.Next())
        {
            TopoDS_Wire aTopoWire = TopoDS::Wire(aWireExp.Current());
            Loop* aLoop = aBodyInfo.aLoopMap.Find(aTopoWire);
            aFace->addLoop(*aLoop);
        }
        for (TopExp_Explorer anEdgeExp(aTopoFace, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next())
        {
            TopoDS_Edge aTopoEdge = TopoDS::Edge(anEdgeExp.Current());
            Edge* anEdge = aBodyInfo.anEdgeMap.Find(aTopoEdge);
            aFace->addEdge(*anEdge);
        }
        aBodyInfo.aBody->addFace(*aFace);
    }

    return aBodyInfo.aBody;
}

This TopoShape comes from a STEP file, maybe some problem about map in present code. I find that so many faces isn't in solids. I don't know how to correctly traverse and store these structures.

Xu Boyi's picture

my data structrue is Body Face Loop Edge Vertex