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.
Thanks.
Dennis G. Wed, 12/22/2010 - 12:13
Hello Sail Lee,
you could try to use the BRepBuilderAPI_Common class to find the common part in all halfspaces.
example:
// make half space solids
Handle(TopTools_HSequenceOfShape) halfSpaceSequence = new TopTools_HSequenceOfShape;
TopoDS_Shape aHalfSpace = BRepPrimAPI_MakeHalfSpace(aFace, aPnt).Solid();
halfSpaceSequence->Append(aHalfSpace);
...
// 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));
if(commonOperator.IsDone())
resultShape = commonOperator.Shape();
}
...
You should put the Boolean Operations in a try environment. The above code is not tested.
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();
//but in this way, the resultShape is a null shape
TopoDS_Shape roof;
BRepAlgoAPI_Common halfcommon(half1,half2);
if(halfcommon.IsDone())
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?
Wed, 12/22/2010 - 12:13
Hello Sail Lee,
you could try to use the BRepBuilderAPI_Common class to find the common part in all halfspaces.
example:
// make half space solids
Handle(TopTools_HSequenceOfShape) halfSpaceSequence = new TopTools_HSequenceOfShape;
TopoDS_Shape aHalfSpace = BRepPrimAPI_MakeHalfSpace(aFace, aPnt).Solid();
halfSpaceSequence->Append(aHalfSpace);
...
// 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));
if(commonOperator.IsDone())
resultShape = commonOperator.Shape();
}
...
You should put the Boolean Operations in a try environment. The above code is not tested.
Good luck
Dennis
Wed, 01/05/2011 - 10:40
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);
if(common.IsDone())
resultShape = common.Shape();
BRepAlgoAPI_Common common2(resultShape,half2);
if(common2.IsDone())
resultShape = common2.Shape();
//but in this way, the resultShape is a null shape
TopoDS_Shape roof;
BRepAlgoAPI_Common halfcommon(half1,half2);
if(halfcommon.IsDone())
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?