TopoDS_Shape的複製

unicornsir發表於2024-07-23

TopoDS_Shape的複製有兩種方式

1) TopoDS_Shape newShape = oldShape;

2) BRepBuilderAPI_Copy tool;
tool.perform(oldShape,true,false); //! "false" since I'm not interested in copying the triangulation
newShape = tool.Shape();

兩者的不同在於shape資料的複製深度,

TopoDS_Shape newShape = oldShape;

這個是淺複製,及新圖形與老圖形共享相同的幾何資料,如果修改了新圖形,老圖形也隨之修改,因為它們的資料是透過智慧指標Handle(TopoDS_TShape)進行共享,而TopLoc_Location和TopAbs_Orientation擁有各自的引數,不進行共享。

BRepBuilderAPI_Copy tool; tool.perform(oldShape, true, false); // "false" since I'm not interested in copying the triangulation newShape = tool.Shape();

透過類BRepBuilderAPI_Copy 建立一個原始圖形的深複製,這意味著新圖形的幾何資訊與老圖形是相互對立的,第二個引數是控制Location是否複製(True為複製,False為共享),第三個引數為是否複製三角化資料(True為複製,False為不複製)This method uses the BRepBuilderAPI_Copy class to create a deep copy of the original shape. This means that a completely new geometric representation is created for the new shape, independent of the old shape. This allows you to modify the new shape without affecting the original one. The second parameter in the perform() function controls the copying of locations (True for copying, False for sharing). The third parameter controls the copying of the triangulation (True for copying, False for not copying).

相關文章