在《拓扑》一文中,拓扑定义了"围成"和“一部分的”概念。拓扑几何中,面(Face)是由闭合的线(wire)围成的。闭合的线,是由一系列边(Edge)按首尾连接组成的。边是由顶点(Vertex)围成的。
本文我们以球面为例子,尝试解析拓扑面的信息。
1. 球面详细信息
以下给出使用OCC的“Draw Test Harness”模块,给出球面的详细信息。
Dump of 7 TShapes-----------------Flags : Free, Modified, Checked, Orientable, Closed, Infinite, Convex, LockedTShape # 1 : FACE 11010000 00000171D02146E0+2NaturalRestrictionTolerance : 1e-07Surface : 1TShape # 2 : WIRE 01011000 00000171C94249D0+4 +5 -3TShape # 3 : EDGE 01010000 00000171C9B70160-6Tolerance : 1e-07same parametrisation of curvessame range on curvesdegeneratedPCurve : 4 on surface 1, range : 0 6.28318530717959UV Points : 0, 1.5707963267949 6.28318530717959, 1.5707963267949TShape # 4 : EDGE 01010000 00000171C9B70960-7Tolerance : 1e-07same parametrisation of curvessame range on curvesdegeneratedPCurve : 3 on surface 1, range : 0 6.28318530717959UV Points : 0, -1.5707963267949 6.28318530717959, -1.5707963267949TShape # 5 : EDGE 01010000 00000171C9B70DE0-6Tolerance : 1e-07same parametrisation of curvessame range on curvesCurve 3D : 1, range : -1.5707963267949 1.5707963267949PCurve : 1, 2 (C0) on surface 1, range : -1.5707963267949 1.5707963267949UV Points : 6.28318530717959, -1.5707963267949 6.28318530717959, 1.5707963267949UV Points : 0, -1.5707963267949 0, 1.5707963267949TShape # 6 : VERTEX 01011010 00000171D02F1900Tolerance : 1e-07Point 3D : 1.22464679914735e-15, 0, 20TShape # 7 : VERTEX 01011010 00000171D02F2290Tolerance : 1e-07Point 3D : 1.22464679914735e-15, 0, -20-------Dump of 4 Curve2ds-------1 : LineOrigin :6.28318530717959, 0Axis :0, 12 : LineOrigin :0, 0Axis :0, 13 : LineOrigin :0, -1.5707963267949Axis :1, 04 : LineOrigin :0, 1.5707963267949Axis :1, 0-------Dump of 1 Curves-------1 : Trimmed curveParameters : 4.71238898038469 7.85398163397448Basis curve :CircleCenter :0, 0, 0Axis :0, -1, 0XAxis :1, 0, 0YAxis :-0, 0, 1Radius :20-------Dump of 0 Polygon3Ds--------------Dump of 0 PolygonOnTriangulations--------------Dump of 1 surfaces-------1 : SphericalSurfaceCenter :0, 0, 0Axis :0, 0, 1XAxis :1, 0, -0YAxis :-0, 1, 0Radius :20-------Dump of 0 Triangulations--------------Dump of 0 Locations-------
详细的图示解析:

球面包含 7 TShapes。TShape代表了拓扑底层几何表示。其数据结构大致如下,应该有4条Edge,但是Draw的dump命令,只打印出三条边。

四条Edge分别对应四条PCurve。具体信息在,“Dump of 4 Curve2ds”。
Face对应一个球面几何“SphericalSurface”。
关于如何遍历访问,Face下的信息,此处不再赘述。
由此我们得出,任何曲面都是由闭合Wire围成,即使其存在退化边、缝合边。
2. Face的参数平面
三维任意曲面,都对应二维参数平面上的几何。求二维参数平面的方法为:
获得Face的所有Wire
判断那些Wire是外边界,那些是内边界;判断方法是比较wire所围成区域的面积,面积最大者为外边界,其余都是内边界
获取wire的edge对应的PCurve,将PCurve首尾连接,形成新的二维平面。
做布尔操作。
此处要注意获得的Wire是不是正确,详细见第3节。代码太长,此处仅给出关键步骤。
//读入igs文件,IGESControl_Reader reader;//TopExp_Explorer aWireExp(face, TopAbs_WIRE);for (aWireExp; aWireExp.More(); aWireExp.Next()) {//将wire存入容器}//找到外界GProp_GProps areaPro1;TopoDS_Face proFace1 = BRepBuilderAPI_MakeFace(w);BRepGProp::SurfaceProperties(proFace1, areaPro1);Standard_Real area1 = areaPro1.Mass();//得到面积,面积最大者是外边界//获取每条Wire对应Edge的PCurveTopExp_Explore wireE(wire,TopAbs_Edge);Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(aTempEdge, face, aPFirst, aPLast);//形成平面//布尔操作BRepAlgoAPI_Cut cut(face2d, aNewHoleFace);
结果如下:

3. Wire的检查与修复
在求Face对应的参数平面的时,出现了以下状况。当获取到内孔的wire的PCurve,二维wire形成了错误的Face。如下:

起初以为是容差原因,调了容差后没有影响。使用ShapeAnalysis_Wire 提供的方法,检查。发现是edge的Order出错,使用ShapeFix_Wire::FixReorder() 修复后正常。
ShapeAnalysis_Wire aCheckWire(aNewWire, aNewFace, aPrecision);// create a tool and load objects into itif (aCheckWire.CheckOrder()){std::cout << "Some edges in the wire need to be reordered\n"<< "Please ensure that all the edges are correctly ordered before further analysis\n";//修复Standard_Real aPrecision = 1e-04;ShapeFix_Wire aFixWire(theWire, aNewFace, aPrecision);aFixWire.FixReorder();TopoDS_Wire aNewWire = aFixWire.Wire();}if (aCheckWire.CheckSmall(aPrecision)){std::cout << "Wire contains edge(s) shorter than " << aPrecision << std::endl;}if (aCheckWire.CheckConnected()){std::cout << "Wire is disconnected\n";}if (aCheckWire.CheckSelfIntersection()){std::cout << "Wire has self-intersecting or intersecting adjacent edges\n";}
有了准确的参数平面之后,就可以参数法剖分任意曲面,任意实体的表面。
参考:
OCC Online Documentation