boolean operations on very simple shapes are very slow

Hi all,

I'm using OCC 5.2 to create a parts modeling tool using a CSG approach.
Thus, this modeling approach makes a lot of calls of boolean functions.
However in OCC boolean combinations seem to be time-consuming.
I am using other kernels like Parasolid, Granite, and Catia. In some cases, OCC is 15 times slower.

Perhaps it's due to the way I use the API in OCC.
Below, a sample code showing how fuse operation is slow :

/////=> Begin Of Code
// a box is fused 20 times with another one
// which has the same dimension and the same location.
TopoDS_Shape box, shape;
for (i = 0; i {
box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 20, 20, 20);
if (shape.IsNull())
shape = box;
else
shape = BRepAlgoAPI_Fuse(shape, box);
}
/////

On Windows XP - 2.53Ghz - 1Mo RAM, OCC takes 1 s 766 ms while Parasolid takes 94 ms (OCC is almost 19 times slower than Parasolid in this example)

Is it the good way or is there a work around?

Is it due to OCC default precision?
Is it possible to change it?

Does OpenCasCade team plan to improve boolean operations in the next release or it's not a priority?

Thanks in advance for many responses.

Jean-Robert

Gerhard Hofmann's picture

Hello Jean-Robert,
did you check, wether this is due to the fusion of identical shapes (boxes) as in your example or do you have the same performance difference when fusing boxes with different locations or sizes?
// box = BRepPrimAPI_MakeBox(gp_Pnt(i, i, i), 20, 20, 20);
I am just wondering!
best regards
Gerhard

jrsiezo's picture

Hello Gerhard,
Yes I checked it. I have the same performance if I translate each box with an offset of 1 along the 3 axis from the previous.
It's like this :

for (i = 0; i < max; i++)
{
box = BRepPrimAPI_MakeBox(gp_Pnt(i, i, i), 20, 20, 20);
if (shape.IsNull())
shape = box;
else
shape = BRepAlgoAPI_Fuse(shape, box);
}

Any idea ?

jrsiezo's picture

Hello Gerhard,
Yes I checked it. I have the same performance if I translate each box with an offset of 1 along the 3 axis from the previous.
It's like this :

for (i = 0; i < max; i++)
{
box = BRepPrimAPI_MakeBox(gp_Pnt(i, i, i), 20, 20, 20);
if (shape.IsNull())
shape = box;
else
shape = BRepAlgoAPI_Fuse(shape, box);
}

Any idea ?

Stephane Routelous's picture

you can try minimizing the number of fuse by fusing the boxes 2x2
then fusing the 2x2 with other 2x2.
etc....

jrsiezo's picture

Hello Stephane,

In fact it was just an example showing how 20 boolean operations could be slow in OCC.
Because of CSG way of modeling, I use boolean operations quite often.
I don't think that about 20 (or even 10) is a lot of calls for modeling a part.
However, I don't really understand fusing boxes 2x2 can minimize the number of fuse?

Stephane Routelous's picture

I remember, that a long time ago, I was doing an prototype with OpenCASCADE to basically cutting windows (boxes) in walls (prisms).
By tweaking the cut operation, I was able to have a lot better performances than cutting one by one.
(making a compound of all the boxes and cutting the prism with the compound. It was 1 cut instead of nbWindows cut).
I assume it is because the initialization/finalization steps are longer than the fusion itself.

I understand that in your case (because of a fusion), it does not reduce the number of boolean operations (note to myself : try to better read the messages before posting).

another hint : try to avoid coplanar faces, tangential faces, etc...
It will simplify the process.

HTH,

Stephane