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)
最新推荐文章于 2024-02-04 23:23:32 发布