opencascade如何用一个面裁剪另外一个面
opencascade如何用一个面裁剪另外一个面
void trim_plane_by_plane_2(TopoDS_Shape aS1, TopoDS_Shape aS2) { BRepAlgoAPI_Section sec(aS1, aS2, false); sec.ComputePCurveOn1(true); sec.Approximation(true); sec.Build(); TopoDS_Shape aInterCurve = sec.Shape(); TopoDS_Face aFace = TopoDS::Face(aS1); BRepFeat_SplitShape ssplit(aS1); TopExp_Explorer ex; for (ex.Init(aInterCurve, TopAbs_EDGE, TopAbs_SHAPE); ex.More(); ex.Next()) { TopoDS_Edge aE = TopoDS::Edge(ex.Current()); TopoDS_Shape aF; if (sec.HasAncestorFaceOn1(aE, aF)) { TopoDS_Face aAncFace = TopoDS::Face(aF); if (aAncFace.IsSame(aFace)) ssplit.Add(aE, aFace); } } ssplit.Build(); TopTools_ListOfShape shapeList = ssplit.Modified(aFace); TopTools_ListIteratorOfListOfShape ite(shapeList); for (; ite.More(); ite.Next()) { TopoDS_Shape aS = ite.Value(); Handle(AIS_Shape) aiss = new AIS_Shape(aS); m_context->Display(aiss, true); } }
opencascade如何用一个面裁剪另外一个面(2)
void split_plane_by_plane(TopoDS_Shape tool_face, TopoDS_Shape object_tool) { // Build section by the split plane for the cylinder. BRepAlgoAPI_Section aSection(object_tool, tool_face, Standard_False); aSection.ComputePCurveOn1(Standard_True); aSection.Approximation(Standard_True); aSection.Build(); // Split the cylinder shape. BRepFeat_SplitShape aShapeSpliter(object_tool); for (TopExp_Explorer i(aSection.Shape(), TopAbs_EDGE); i.More(); i.Next()) { TopoDS_Shape anEdge = i.Current(); TopoDS_Shape aFace; if (aSection.HasAncestorFaceOn1(anEdge, aFace)) { TopoDS_Edge E = TopoDS::Edge(anEdge); TopoDS_Face F = TopoDS::Face(aFace); aShapeSpliter.Add(E, F); } } aShapeSpliter.Build(); // Rebuild left and right shape. BRep_Builder aBuilder; TopoDS_Compound aLeftCompound; TopoDS_Compound aRightCompound; aBuilder.MakeCompound(aLeftCompound); aBuilder.MakeCompound(aRightCompound); // Left shape. TopTools_MapOfShape aLeftShapeMap; const TopTools_ListOfShape& aLeftShapes = aShapeSpliter.Left(); for (auto i = aLeftShapes.cbegin(); i != aLeftShapes.cend(); i++) { aLeftShapeMap.Add(*i); aBuilder.Add(aLeftCompound, *i); display(aLeftCompound); } // Right shape. TopTools_IndexedMapOfShape aShapeMap; TopExp::MapShapes(aShapeSpliter.Shape(), TopAbs_FACE, aShapeMap); for (auto i = aShapeMap.cbegin(); i != aShapeMap.cend(); i++) { if (!aLeftShapeMap.Contains(*i)) { aBuilder.Add(aRightCompound, *i); display(aRightCompound); } } }
opencascade如何用一个面裁剪另外一个面(2)_hasancestorfaceon1-CSDN博客
voidsplit_plane_by_plane(TopoDS_Shape tool_face, TopoDS_Shape object_tool){// Build section by the split plane for the cylinder. BRepAlgoAPI_Section aSection(object_tool, tool_face, Standard_False); aSection.ComputePCurveOn1(Standard_True); aSection.Approximation(Standard_True); aSection.Build();// Split the cylinder shape. BRepFeat_SplitShape aShapeSpliter(object_tool);for(TopExp_Explorer i(aSection.Shape(), TopAbs_EDGE); i.More(); i.Next()){ TopoDS_Shape anEdge = i.Current(); TopoDS_Shape aFace;if(aSection.HasAncestorFaceOn1(anEdge, aFace)){ TopoDS_Edge E = TopoDS::Edge(anEdge); TopoDS_Face F = TopoDS::Face(aFace); aShapeSpliter.Add(E, F);}} aShapeSpliter.Build();// Rebuild left and right shape. BRep_Builder aBuilder; TopoDS_Compound aLeftCompound; TopoDS_Compound aRightCompound; aBuilder.MakeCompound(aLeftCompound); aBuilder.MakeCompound(aRightCompound);// Left shape. TopTools_MapOfShape aLeftShapeMap;const TopTools_ListOfShape& aLeftShapes = aShapeSpliter.Left();for(auto i = aLeftShapes.cbegin(); i != aLeftShapes.cend(); i++){ aLeftShapeMap.Add(*i); aBuilder.Add(aLeftCompound,*i);display(aLeftCompound);}// Right shape. TopTools_IndexedMapOfShape aShapeMap; TopExp::MapShapes(aShapeSpliter.Shape(), TopAbs_FACE, aShapeMap);for(auto i = aShapeMap.cbegin(); i != aShapeMap.cend(); i++){if(!aLeftShapeMap.Contains(*i)){ aBuilder.Add(aRightCompound,*i);display(aRightCompound);}}}