Boolean Operations : Common

Hi !
I'm trying to get the common parts shared by a cylinder and a box.
The location of the Cylinder is good, with good dimensions etc...
But I can't got what I expect !
Here is the code : (results in comments)

// Construction of the first shape
TopoDS_Compound pieceComp;
BRep_Builder bldp;
bldp.MakeCompound(pieceComp);
// this are array of Shapes. each surface a face of a cube.
for (unsigned int i=0; i {
bldp.Add(pieceComp,listShape(i));
}

//Sewing this compound
BRepOffsetAPI_Sewing sew(0.01);
sew.Add(pieceComp);
sew.Perform();
TopoDS_Shape pieceShape = sew.SewedShape();

// This analyzer says the pieceShape is VALID
BRepCheck_Analyzer analyzer(pieceShape);

// Construction of the second shape
BRepPrimAPI_MakeCylinder ccyl(info_.rayon(),1000);
TopoDS_Shape CylShape(ccyl.Shape());

// some transformations
gce_MakeRotation rotation (...);
BRepBuilderAPI_Transform outilTransDef(rotation);
outilTransDef.Perform(ccyl,Standard_False);
TopoDS_Shape TransfoShapeDef = outilTransDef.Shape();

gp_Trsf transfo;
...
TopoDS_Shape cylindreShape = outilTrans.Shape();

//And then the Boolean Operation

TopoDS_Shell shCylindre, shPiece;
TopoDS_Solid soCylindre, soPiece;
BRep_Builder bld;
bld.MakeShell(shCylindre);
bld.MakeShell(shPiece);
bld.MakeSolid(soCylindre);
bld.MakeSolid(soPiece);

bld.Add(shCylindre,cylindreShape);
bld.Add(soCylindre,shCylindre);

bld.Add(shPiece,pieceShape);
bld.Add(soPiece,shPiece);

BRepAlgoAPI_Common bc (cylindreShape, pieceShape); // this make a really strange result : a quarter disc
BRepAlgoAPI_Common bc (soCylindre, soPiece); // This makes application break down

TopoDS_Shape TrouPlatShape = bc.Shape();

Udo's picture

BRepAlgoAPI_Common bc (cylindreShape, pieceShape); // this make a really strange result : a quarter disc

I do not know the coordinates of the two shapes, but a quarter disc seems to be a possible result if the box would have one corner point in the middle of the cylinder and is moved inside of the cylinder volume.

BRepAlgoAPI_Common bc (soCylindre, soPiece); // This makes application break down

You make the solids before you added the shells:

bld.Add(shCylindre,cylindreShape);
bld.Add(soCylindre,shCylindre);

bld.Add(shPiece,pieceShape);
bld.Add(soPiece,shPiece);

bld.MakeSolid(soCylindre);
bld.MakeSolid(soPiece);

should work. But Why are you not using the primitives provided by OpenCASCADE?

Hope that helps,

Udo

PLN's picture

I agree , it was my first toughts, but when I displayed the two shapes the cylinder was well placed, I mean that one of its extremity was fully INSIDE the box
I don't use primitives cause I have to make this work in more general cases, the first shape can be a CAD object drawn by a user, more complicated than a simple box.

By the way, making the solids before doesn't change a thing...

I'll keep on trying.

It makes me mad caus it works more simply on previous version of OCC....

Thanx a lot !

Udo's picture

Ok, I thought that would be too simple...

Then it is probably a very similar promblem as the one that I am currently struggeling with. Are you shure that the two shapes are solids wit a closed shell?

Regards,

Udo

PLN's picture

yes
the analyser said VALID so...
and now I try with 2 primitives and it stills crash !...

Udo's picture

In my case the Analyser says that the shape is valid, too.

If I use BRepAlgo::IsValid(current_shape) it delivers true, but when I look at the shape it has some green edges in the viewer, which means that there are gaps in the wireframe. This does of course not explain why it crashes on primitives...

PLN's picture

sorry... primives works...
So the analyzer doesn't work fine ?

Udo's picture

No, probably it depends on what we are sending to the analyser. In your case you check a shell, not a solid. If you would check the solids the analyser would probably return false. Have you tried to used the sewing method without tolerance parameter? That seems to deliver diffrent results, at least in my case.