opencascade官網文檔學習之OCCT-Shape healing (3)分析 TopoDS_Shape
Analysis 分析
Analysis of shape validity 形狀有效性分析
ShapeAnalysis軟件包提供了用于分析拓撲形狀的工具。在執行修復工具之前,沒有必要通過這些工具檢查形狀,因為這些工具用于在修復工具內部執行修復之前的分析。但是,如果您愿意,這些工具可以獨立于修復工具用于檢測某些形狀問題。
可以通過以下方式完成:
- 創建一個分析工具;
- 通過形狀對其進行初始化,并設置公差,如果必要,將檢測到問題;
- 檢查您感興趣的問題。
1 TopoDS_Face theFace = ...; 2 // create a tool for analyzing an edge 3 ShapeAnalysis_Edge aCheckEdge; 4 for (TopExp_Explorer anExp (theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) 5 { 6 TopoDS_Edge anEdge = TopoDS::Edge (anExp.Current()); 7 if (!aCheckEdge.HasCurve3d (anEdge)) 8 { 9 std::cout << "Edge has no 3D curve\n"; 10 } 11 }
Analysis of orientation of wires on a face 分析face上的wires的朝向
可以借助ShapeAnalysis::IsOuterBound方法檢查面是否具有外部邊界
1 TopoDS_Face theFace = ...; // analyzed face 2 if (!ShapeAnalysis::IsOuterBound (theFace)) 3 { 4 std::cout << "Face has not outer boundary\n"; 5 }
Analysis of wire validity 分析wire的有效性
類ShapeAnalysis_Wire用于分析wire。它提供了探索wire特性和檢查其是否符合Open CASCADE Technology要求的功能。這些功能包括:
- 檢查wire上的edge的順序,
- 檢查對于small edge(長度小于給定值)的存在,
- 檢查邊緣曲線 edge curves的一致性,
- 檢查退化邊緣的存在或缺失,
- 檢查是否存在自相交邊和相交邊(邊的相交被理解為其2D曲線的相交)
- 檢查缺少的邊以填充曲面參數空間中的間隙,
- 分析導線方向(定義表面的外部或內部邊界),
- 分析添加到現有導線的形狀(邊緣或導線)的方向。
請注意,除第一個檢查操作外的所有檢查操作都是基于對導線中的邊進行排序的假設。因此,如果檢測到wire未排序,則有必要在調用其他檢查操作之前對其進行排序。例如,這可以在ShapeFix_Wire::FixOrder()方法的幫助下完成。
該工具應使用wire、面(或具有位置的曲面)或精度進行初始化。一旦工具初始化,就可以執行必要的檢查操作。為了一次獲得wire上的所有信息,提供了全局方法Perform。它調用所有其他API檢查操作來檢查每個單獨的案例。
API方法只檢查相應的案例,可以分析它們返回的值和狀態,以了解是否檢測到案例。
此類中的一些方法是:
- CheckOrder檢查wire中的邊的順序是否正確
- CheckConnected檢查邊是否斷開連接;
- CheckSmall檢查是否存在比給定值短的邊;
- CheckSelfIntersection檢查是否存在自相交邊或相鄰相交邊。如果相交是由于不相鄰的邊而發生的,則不會檢測到。
此類維護狀態管理。每個API方法都存儲其最后一次執行的狀態,可以通過Status...()方法查詢 。此外,每個API方法都返回一個布爾值,當檢測到正在分析的案例時(設置ShapeExtend_DONE狀態),該值為True,否則為False。
1 TopoDS_Wire theWire = ...; 2 Standard_Real aPrecision = 1e-04; 3 ShapeAnalysis_Wire aCheckWire (theWire, theFace, aPrecision); 4 // create a tool and load objects into it 5 if (aCheckWire.CheckOrder()) 6 { 7 std::cout << "Some edges in the wire need to be reordered\n" 8 << "Please ensure that all the edges are correctly ordered before further analysis\n"; 9 return; 10 } 11 if (aCheckWire.CheckSmall (aPrecision)) 12 { 13 std::cout << "Wire contains edge(s) shorter than " << aPrecision << std::endl; 14 } 15 if (aCheckWire.CheckConnected()) 16 { 17 std::cout << "Wire is disconnected\n"; 18 } 19 if (aCheckWire.CheckSelfIntersection()) 20 { 21 std::cout << "Wire has self-intersecting or intersecting adjacent edges\n"; 22 }
Analysis of edge validity 邊的有效性分析
類ShapeAnalysis_Edge用于分析邊。它提供了以下功能來處理邊:
- 查詢幾何表示(給定面或曲面上的三維曲線和曲線)
- 查詢拓撲子形狀(邊界頂點),
- 檢查重疊邊,
- 分析曲線一致性:
- 3D曲線和2D曲線的相互定向(同方向或相反方向),
- 3D和2D曲線與頂點的對應關系。
此類支持上述狀態管理
1 TopoDS_Face theFace = ...; 2 // create a tool for analyzing an edge 3 ShapeAnalysis_Edge aCheckEdge; 4 for (TopExp_Explorer anExp (theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) 5 { 6 TopoDS_Edge anEdge = TopoDS::Edge (anExp.Current()); 7 if (!aCheckEdge.HasCurve3d (anEdge)) 8 { 9 std::cout << "Edge has no 3D curve\n"; 10 } 11 Handle(Geom2d_Curve) aPCurve; 12 Standard_Real aPFirst = 0.0, aPLast = 0.0; 13 if (aCheckEdge.PCurve (anEdge, theFace, aPCurve, aPFirst, aPLast, Standard_False)) 14 { 15 // print the pcurve and its range on the given face 16 std::cout << "Pcurve range [" << aPFirst << ", " << aPLast << "]\n"; 17 } 18 Standard_Real aMaxDev = 0.0; 19 if (aCheckEdge.CheckSameParameter (anEdge, aMaxDev)) 20 { 21 // check the consistency of all the curves in the edge 22 std::cout << "Incorrect SameParameter flag\n"; 23 } 24 std::cout << "Maximum deviation " << aMaxDev << ", tolerance" 25 << BRep_Tool::Tolerance (anEdge) << std::endl; 26 }
1 // check the overlapping of two edges 2 TopoDS_Edge theEdge1 = ...; 3 TopoDS_Edge theEdge2 = ...; 4 Standard_Real theDomainDist = 0.0; 5 6 ShapeAnalysis_Edge aCheckEdge; 7 Standard_Real aTolOverlap = 0.0; 8 if (aCheckEdge.CheckOverlapping (theEdge1, theEdge2, aTolOverlap, theDomainDist)) 9 { 10 std::cout << "Edges are overlapped with tolerance = " << aTolOverlap << std::endl; 11 std::cout << "Domain of overlapping =" << theDomainDist << std::endl; 12 }