For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Unexpected results in boolean operations. And how exactly do I validate shapes before and after these operations?

Liordino Neto's picture


I'm trying to do a Cut operation between two groups of shapes (let's call these groups A and B) in several ways and obtaining different results. I believe that in some cases they should really be different, but sometimes I understand that they should be equal and so the results are not exactly what I expect. I already tried to perform the Cut operation on these ways:

  1. By obtaining a TopoDS_Shape for each shape and Fusing them (with BRepAlgoAPI_Fuse) into a single TopoDS_Shape, one time for each group. This way I obtain two groups, and at the end perform a Cut operation (A - B with BRepAlgoAPI_Cut) between them. This gives me the expected results;
  2. The same operation as 1, but setting a Fuzzy value of 0.e-5 and BOPAlgo_GlueOff on the Fuse and Cut operations. This gives me the same result as 1 (which is what I expected) with a slightly better performance.
  3. Instead of using BRepAlgoAPI_Fuse to obtain a single TopoDS_Shape they are added to a TopoDS_Compound, grouped as A and B, like before. In the end I have two groups and also performa a Cut operation with BRepAlgoAPI_Cut (A - B). This process have a much better performance, but give unexpected results.
  4. The same operation as 2, but setting a Fuzzy value of 0.e-5 and BOPAlgo_GlueOff on the final Cut operation. This gives the same result as 3.
  5. Get the fused shapes for A and B just like the operation performed in 1, but instead of doing the cut with BRepAlgoAPI_Cut perform the Cells Builder Algorithm like that (I addapted the code to make it more readable):
    BOPAlgo_CellsBuilder aCBuilder;
    BOPCol_ListOfShape aLSToTake;
    BOPCol_ListOfShape aLSToAvoid;
    /* GET A AND B */
    aCBuilder.AddToResult(aLSToTake, aLSToAvoid, 1, Standard_False);
    AMinusB = aCBuilder.Shape();

    This also gives me the expected results, and have the best performance when compared with the other approaches that also give the correct results;

  6. The same approach as 5, but adding the shapes to a TopoDS_Compound instead of fusing them into a TopoDS_Shape for each group. In the end the same operation is performed with the BOPAlgo_CellsBuilder. Like the other approaches where I used a TopoDS_Compound, here I got a result different them what I expected, despite the better performance.

I have to try yet one more approach: Cells Builder algorithm using only the BOPAlgo_CellsBuilder and BOPCol_ListOfShape types, without TopoDS_Shape or TopoDS_Compound.

Some questions:

  • How should I calculate a Fuzzy value to use, if that's the case?
  • Why a Cut operation between not fused TopoDS_Compounds gives different results when compared with the same operation between fused TopoDS_Shapes? The TopoDS_Compounds have the same shapes as the TopoDS_Shapes, only not fused into a single one, and this happened independent of the method used (BRepAlgoAPI or BOPAlgo_CellsBuilder).

I'm using OCC 7.2.0, and attached some images that I hope can make it easier to understand what I wrote.

Thanks in advance!