OCCT知识笔记之分解BOX
OCCT中一个矩形 可以分解出 点 线 面 线框 实体,直接看代码示例。
1.创建一个矩形盒子
Standard_Real aSizeX = 5.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
2.遍历盒子根据具体类型提取元素
a. 点类型
Standard_Integer nbVertices = 0;
for(TopExp_Explorer anExp(aBox, TopAbs_VERTEX); anExp.More(); anExp.Next(), ++nbVertices)
{const TopoDS_Shape& aShape = anExp.Current();Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);myContext->Display(anAisShape, Standard_True);
}
b. 边类型
Standard_Integer nbEdges = 0;
for(TopExp_Explorer anExp(aBox, TopAbs_EDGE); anExp.More(); anExp.Next(), ++nbEdges)
{const TopoDS_Shape& aShape = anExp.Current();Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);myContext->Display(anAisShape, Standard_True);
}
c.面类型
Standard_Integer nbFaces = 0;
for(TopExp_Explorer anExp(aBox, TopAbs_FACE); anExp.More(); anExp.Next(), ++nbFaces )
{const TopoDS_Shape& aShape = anExp.Current();Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);myContext->Display(anAisShape, Standard_True);
}
d.线框类型
Standard_Integer nbWires = 0;
for(TopExp_Explorer anExp(aBox, TopAbs_WIRE); anExp.More(); anExp.Next(), ++nbWires )
{const TopoDS_Shape& aShape = anExp.Current();Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);myContext->Display(anAisShape, Standard_True);
}
e.壳类型
Standard_Integer nbShells = 0;for (TopExp_Explorer anExp(aBox, TopAbs_SHELL); anExp.More(); anExp.Next(), ++nbShells){const TopoDS_Shape& aShape = anExp.Current();Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);myContext->Display(anAisShape, Standard_True);}
f.实体
Standard_Integer nbSolids = 0;for (TopExp_Explorer anExp(aBox, TopAbs_SOLID); anExp.More(); anExp.Next(), ++nbSolids){const TopoDS_Shape& aShape = anExp.Current();Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);myContext->Display(anAisShape, Standard_True);}
整个矩形盒子通过不同的点线边面壳可以获取到不同的基本类型。