Halfspace problem

Hello everyone
I'm new to OpenCascade,anybody know how to construct a close polyhedron by a series of halfspace(plane)?
Just like the 3D Nef Polyhedra algorithm in CGAL with is too slow.


Dennis G.'s picture

Hello Sail Lee,

you could try to use the BRepBuilderAPI_Common class to find the common part in all halfspaces.


// make half space solids
Handle(TopTools_HSequenceOfShape) halfSpaceSequence = new TopTools_HSequenceOfShape;
TopoDS_Shape aHalfSpace = BRepPrimAPI_MakeHalfSpace(aFace, aPnt).Solid();

// find common part of all half spaces
TopoDS_Shape resultShape = halfSpaceSequence->Value(1);
for(int i=2; i<=halfSpaceSequence->Length(); i++)
BRepAlgoAPI_Common commonOperator(resultShape, halfSpaceSequence->Value(i));
resultShape = commonOperator.Shape();

You should put the Boolean Operations in a try environment. The above code is not tested.

Good luck


chazi0828's picture

Thanks for reply.I tried your code,but the result is not correct.
My test code is :
//make a box
TopoDS_Shape box = BRepPrimAPI_MakeBox(gp_Pnt(-50,-50,-50),gp_Pnt(50,50,50));
//make two halfspace
TopoDS_Face face1 = BRepBuilderAPI_MakeFace(gp_Pln(0,1,1,-40));
TopoDS_Shape half1 = BRepPrimAPI_MakeHalfSpace(face1,gp_Pnt(0,0,-100)).Solid();

TopoDS_Face face2 = BRepBuilderAPI_MakeFace(gp_Pln(0,-1,1,-40));
TopoDS_Shape half2 = BRepPrimAPI_MakeHalfSpace(face2,gp_Pnt(0,0,-100)).Solid();

TopoDS_Shape resultShape;

//in this way ,i got a correct result
BRepAlgoAPI_Common common(box,half1);
resultShape = common.Shape();

BRepAlgoAPI_Common common2(resultShape,half2);
resultShape = common2.Shape();

//but in this way, the resultShape is a null shape
TopoDS_Shape roof;
BRepAlgoAPI_Common halfcommon(half1,half2);
roof = halfcommon.Shape();
resultShape = BRepAlgoAPI_Common(box,roof).Shape();

So , it seems that BRepAlgoAPI_Common is not applicable to get the common part of halfspaces,am i right?
Any body know how to solve this problem?