For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Failure to Cut box with halfspace that doesn't intersect box.

Michael Priestman's picture

I'm having a problem with the BRepAlgoAPI_Cut operation. I'm trying to cut a box with a planar halfspace (i.e. just a single unbounded plane). The matter of the halfspace is entirely above the box, therefore the "cut" operation should do nothing and just return the box.

However, an exception is thrown in TopTools_IndexedMapOfShape::FindKey() (see call stack below), and so the entire operation fails with an error status of 101. The exception is thrown because the map is empty yet the caller is asking for the item with key 1.

I also get the same problem when I move the plane to be entirely below the box (in which case the box should be completely clipped).

Here is the code used to reproduce the problem:

// Build a box.

TopoDS_Shape theBox = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), gp_Pnt(5, 3, 8));

// Build a halfspace with the matter located "above" the plane.

gp_Ax3 ax(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 0.3, 1.0));
TopoDS_Face occ_face = BRepBuilderAPI_MakeFace(gp_Pln(ax));
BRepPrimAPI_MakeHalfSpace mhs(occ_face, gp_Pnt(0.0, 0.0, 20.0));
TopoDS_Shape theHalfSpace = mhs.Solid();

// Cut the box with the halfspace. Should result in the box being returned.

BRepAlgoAPI_Cut my_cut(theBox, theHalfSpace);
Standard_Integer error = my_cut.ErrorStatus();
TopoDS_Shape ShapeCut = my_cut.Shape();

And here is the call stack showing exactly where the exception was thrown.

KERNEL32! 7c81eb33()
MSVCRTD! _CxxThrowException@8 + 57 bytes
Standard_OutOfRange::Throw() line 48
Standard_Failure::Reraise(char * const 0x100a4d38) line 76
Standard_OutOfRange::Raise(char * const 0x100a4d38) line 43
TopTools_IndexedMapOfShape::FindKey(const int 1) line 269 + 29 bytes
TopTools_IndexedMapOfShape::operator()(const int 1) line 91
BOPTools_StateFiller::ClassifyShapeByRef(const TopoDS_Shape & {...}, const TopoDS_Shape & {...}) line 126 + 10 bytes
BOPTools_SolidStateFiller::DoNonSections(const int 2) line 296 + 25 bytes
BOPTools_SolidStateFiller::Do() line 127
BOP_ShellSolid::Prepare() line 595
BOP_SolidSolid::DoWithFiller(const BOPTools_DSFiller & {...}) line 145
BRepAlgoAPI_BooleanOperation::Build() line 361
BRepAlgoAPI_Cut::BRepAlgoAPI_Cut(const TopoDS_Shape & {...}, const TopoDS_Shape & {...}) line 23
CTopologyOperationsDoc::OnCut() line 153 + 22 bytes

This looks like a bug in OpenCascade to me. I'm using version 5.2. Can anyone help with this issue?