如何使用 OpenCASCADE 迭代 TopoDS_Face 中的所有边
你可以使用 OCCUtils 库迭代 TopoDS_Solid 中的所有 TopoDS_Face 实例
iterate_edges_occutils.cpp
#include <occutils/ShapeComponents.hxx>
using namespace OCCUtils;
TopoDS_Shape myShape = /* ... */;
auto edges = ShapeComponents::AllEdgesWithin(myShape);
// 迭代所有实体
for(const TopoDS_Edge& edge : edges) {
/* ... */
}或者,你可以使用此原始 OpenCASCADE 源代码而不使用 OCCUtils:
iterate_edges_raw.cpp
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopExp.hxx>
TopoDS_Shape myShape = /* ... */;
TopTools_IndexedMapOfShape faces;
TopExp::MapShapes (myShape, TopAbs_EDGE, faces);
for (int i = 1; i <= faces.Extent (); i++) {
TopoDS_Edge face = TopoDS::Edge(edges(i));
/* ... */
}如果有选择,我推荐使用 OCCUtils,因为它使你的代码比使用原始 OpenCASCADE API 更易读。
Check out similar posts by category:
C/C++, OpenCASCADE
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow