Mon, 06/09/2008 - 16:30

Hi

I make my first steps with OpenCascade.

I tried to test with loaded STL file (B1 in the code) for intersection with a cube.

a) Is there an easy way to flip the solid orientation, so that a point far away from the centre is always outside?

b) what is the fastes way to test if some cube is intersecting with the loaded STL model (partly / full / no). The code below results always with an empty bops.Common().

Thanks very much for your help.

BRepClass3d_SolidClassifier sc(B1);

gp_Pnt pt(1e10,500,20.0);

TopoDS_Shell ashell = TopoDS::Shell(B1);

BRepBuilderAPI_MakeSolid solidmaker;

solidmaker.Add( ashell );

bool ok = solidmaker.IsDone();

TopoDS_Solid ss = solidmaker;

bool isInOutInverted = false;

sc.Perform( pt, 1e-8);

bool b = sc.Rejected();

if( !b)

{

TopAbs_State e = sc.State();

if(e==TopAbs_IN){

isInOutInverted = true;

}

}

gp_Pnt pb1(-500,-500,-20);

gp_Pnt pb2(520,520,40);

TopoDS_Solid solidbox = BRepPrimAPI_MakeBox (pb1, pb2);

solidmaker.Add( ashell );

if(solidmaker.IsDone() )

{

BRepAlgo_BooleanOperations bops;

bops.Shapes(solidbox, ss);

TopoDS_Shape result = bops.Common();

TopExp_Explorer expl(result, TopAbs_SHAPE);

int n=0;

for( ; expl.More(); expl.Next() )

{

++n;

}

}

Mon, 06/09/2008 - 17:18

a) To flip shape orietation use the method TopoDS_Shape::Orientation

b) The fastest way is to compute bounding box of your solid with BRepBndLib::Add

and use the method Bnd_Box::IsOut to check if two boxes are intersected or not.

Mon, 06/09/2008 - 19:10

Thanks a lot for the quick respond. a) works now well

b)

I need a function to decide if a given box (not the bounding box of the solid) intersects fully / partlly / or does not intersect with the solid ss. I tried this with by using BRepAlgo_BooleanOperations::Common and then inspect the result. But this does not work (when I inspect the result from a box which does not intersect, the bounding box of the result IsVoid() isn't true).

Is there a (fast) function to test if the solid intersects with a face? I could take the 6 sides of the box then.

Thanks Martin

Mon, 06/09/2008 - 19:24

Is your cube oriented along main axes as a bounding box? If so, then:

- If you want simply to check if a solid does not common with a box, use Bnd_Box::IsOut method.

- It may be the case when IsOut gives false, but actually there is no intersection. In this case use boolean Common operation. But for this you should have both valid solid objects (all faces are connected with shared edges, and each edge has exactly 2 adjacent faces), and both your shapes must be of type TopAbs_SOLID.