Splitting a shell into two shells by a plane

edoelas

CAD practitioner
Hi, I am using BRepAlgoAPI_Splitter to split a shell by a plane. This is the code we are using:

C++:
    // Object
    TopTools_ListOfShape objectShapes = myShell;

    // Tools
    TopTools_ListOfShape toolShapes;
    gp_Pnt planePoint(pos.x, pos.y, pos.z);
    gp_Dir planeNormal(dir.x, dir.y, dir.z);
    const Handle(Geom_Surface) planeSurface = new Geom_Plane(planePoint, planeNormal);
    TopoDS_Face planeFace;
    BRep_Builder builder;
    builder.MakeFace(planeFace, planeSurface, 0.001);
    toolShapes.Append(planeFace);
    
    // Splitter
    BRepAlgoAPI_Splitter splitter;
    splitter.SetArguments(objectShapes);
    splitter.SetTools(toolShapes);
    splitter.Build();

    // result
    TopoDS_Shape splitShape = splitter.Shape();

The problem is that splitShape is a TopoDS_Shell. If I analyze the shell I can see that the faces have been split but what I need is two different shells, not one shell with split faces. Right now we are dividing the shell checking if it is in front or behind the plane. It seems to work, but I don't think is the best way.
Thanks!
 

blobfish

CAD community veteran
It seems to work, but I don't think is the best way.
Maybe:
use BRepPrimAPI_MakeHalfSpace to turn you plane into a solid. Then run 2 boolean operations. Both with the shell as the argument and the halfspace as the tool. The first boolean operation is a cut and the second is a common. If concerned about performance, maybe the BOPAlgo_PaveFiller from the first boolean operation can be used in the second.
 

Quaoar

Administrator
Staff member
The problem is that splitShape is a TopoDS_Shell. If I analyze the shell I can see that the faces have been split but what I need is two different shells, not one shell with split faces. Right now we are dividing the shell checking if it is in front or behind the plane. It seems to work, but I don't think is the best way.
Thanks!
Since BRepAlgoAPI_Splitter does not provide such an interface, I'd say it's fine that you're doing such filtering by yourself.
 

Quaoar

Administrator
Staff member
Back in the day, I had to develop a somewhat similar algorithm based on BRepFeat_SplitShape (that was tio split a ship hull at its waterline). It was full of crappy code checking for each individual face to belong to the upper or inner halfspace. Having BRepAlgoAPI_Splitter is already quite a leap over what you could otherwise implement :)
 
Top