Skip to content

**** ****

for my bad memories..

OpenCASCADE topology


출처: https://dev.opencascade.org/content/exploring-compound

OpenCASCADE의 topology는 다음과 같음.

아래와 같이 탐색.

MainWindow::MainWindow(QMainWindow *parent):QMainWindow(parent)
{
    //! ---------
    //! a viewer
    //! ---------
    occViewPort aViewer = new occViewPort(this);
    if(aViewer->getContext().IsNull()) aViewer->init();
    this->setCentralWidget(aViewer);

    //! ------------------------
    //! load the file from disk
    //! ------------------------
    STEPControl_Reader aReader;
    IFSelect_ReturnStatus stat = aReader.ReadFile(FILENAME);

    if(stat!=IFSelect_RetDone) exit(1);

    aReader.TransferRoots();
    TopoDS_Shape aShape = aReader.OneShape();

    //! ----------------
    //! list of shapes
    //! ----------------
    QList<TopoDS_Shape> csolids;
    QList<TopoDS_Shape> solids;
    QList<TopoDS_Shape> wires;
    QList<TopoDS_Shape> edges;
    QList<TopoDS_Shape> shells;
    QList<TopoDS_Shape> faces;

    for(TopoDS_Iterator anIt(aShape); anIt.More(); anIt.Next())
    {
        const TopoDS_Shape &curShape = anIt.Value();
        TopAbs_ShapeEnum type = curShape.ShapeType();

        if(type==TopAbs_COMPOUND)
        {
            cout<<"____COMPOUND____"<<endl;

            TopoDS_Builder aShellBuilder;
            TopoDS_Shell aShell;

            TopoDS_Builder aWireBuilder;
            TopoDS_Wire aWire;

            aShellBuilder.MakeShell(aShell);
            aWireBuilder.MakeWire(aWire);

            int faceCount = 0;
            int edgeCount = 0;

            for(TopoDS_Iterator anExp(curShape); anExp.More(); anExp.Next())
            {
                const TopoDS_Shape &curShape1 = anExp.Value();
                TopAbs_ShapeEnum type1 = curShape1.ShapeType();

                if(type1==TopAbs_SHELL)
                {
                    for(TopExp_Explorer anExp(curShape1,TopAbs_FACE);anExp.More();anExp.Next())
                    {
                        const TopoDS_Shape &curShape2 = anExp.Current();
                        aShellBuilder.Add(aShell,curShape2);
                        faceCount++;
                    }
                }

                if(type1==TopAbs_EDGE)
                {
                    aWireBuilder.Add(aWire,curShape1);
                    edgeCount++;
                }
            }

            if(faceCount>1) shells<<aShell;
            if(edgeCount>1) wires<<aWire;
            else if(edgeCount==1)
            {
                //! --------------------------------------
                //! remove "aWire" from the list of wires
                //! --------------------------------------
                wires.removeOne(aWire);
                for(TopExp_Explorer anExp(aWire,TopAbs_EDGE); anExp.More(); anExp.Next())
                {
                    const TopoDS_Shape &curEdge = anExp.Current();
                    edges<<curEdge;
                }
            }
        }

        //! -----------------
        //! composite solids
        //! -----------------
        if(type==TopAbs_COMPSOLID)
        {
            cout<<"____COMPSOLID____"<<endl;
            csolids<<curShape;
        }

        //! -------
        //! solids
        //! -------
        if(type==TopAbs_SOLID)
        {
            solids<<curShape;
        }

        //! ------
        //! faces
        //! ------
        if(type==TopAbs_SHELL)
        {
            for(TopExp_Explorer anExp(curShape,TopAbs_FACE);anExp.More();anExp.Next())
            {
                const TopoDS_Shape &curShape1 = anExp.Current();
                faces<<curShape1;
            }
        }
    }

    cout<<"____Nb solids: "<<solids.length()<<"____"<<endl;
    cout<<"____Nb shells: "<<shells.length()<<"____"<<endl;
    cout<<"____Nb faces: "<<faces.length()<<"____"<<endl;
    cout<<"____Nb wires: "<<wires.length()<<"____"<<endl;
    cout<<"____Nb edges: "<<edges.length()<<"____"<<endl;

    //! --------
    //! display
    //! --------
    QList<TopoDS_Shape> listOfShapes;
    listOfShapes<<csolids<<solids<<shells<<faces<<wires<<edges;
    for(int i=0; i<listOfShapes.length(); i++)
    {
        const Handle(AIS_Shape) &anAIS_Shape = new AIS_Shape(listOfShapes.at(i));
        aViewer->getContext()->Display(anAIS_Shape,AIS_Shaded,-1,true,false);
    }
    aViewer->FitAll();
    aViewer->setAction3D_Rotation();
}

It gives

____Nb solids: 1____
____Nb shells: 2____
____Nb faces: 1____
____Nb wires: 1____
____Nb edges: 1____

for file 000000000_mixed_1

and

____Nb solids: 1____
____Nb shells: 1____
____Nb faces: 3____
____Nb wires: 1____
____Nb edges: 1____

for 000000000_mixed_2.stp

sample.zip


Categorized as: Programming



답글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다


이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.