출처: 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
'블로그 (Blog) > 개발로그 (Devlogs)' 카테고리의 다른 글
phong shading의 아주 좋은 예제 (0) | 2024.03.08 |
---|---|
CentOS 6.5 repository 변경 (0) | 2024.03.08 |
pyinstaller 설치 on Python 2.7 (0) | 2024.03.08 |
ntldd (0) | 2024.03.08 |
gcc 메세지 컬러 표시 켜기 (0) | 2024.03.08 |