BRepAlgoAPI_Common produces no geometry

Forums: 

Hi everyone,

I have 2 breps and i would like to get their intersection (see image attatched). The shapes are valid closed solids and they do intersect. However the result is a topods_compound that does not contain any geometry. Does anyone have any tips how to fix this?

The report says "BOPAlgo_AlertBadPositioning", but I could not find any info on how to fix that. I also attatch both shapes as step files (to upload them i had to change their extention to .txt, but they work the same)

Here is my code:

from OCC.Extend.DataExchange import read_step_file
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Common
from OCC.Core.BRepCheck import BRepCheck_Analyzer
from OCC.Core.ShapeAnalysis import ShapeAnalysis_FreeBounds

bottomBrep = read_step_file('export/BRepAlgoAPI_Common/20240116_114252_emptyCompound_bottomBrep.txt')
topBrep = read_step_file('export/BRepAlgoAPI_Common/20240116_114252_emptyCompound_topBrep.txt')

commonFunction = BRepAlgoAPI_Common(bottomBrep, topBrep)
commonFunction.Build()
common = commonFunction.Shape()

#ckecking
print(f'Has Generated: {commonFunction.HasGenerated()}')
print(f'HasErrors(): {commonFunction.HasErrors()}')
print(f'GetReport().DumpToString(): {commonFunction.GetReport().DumpToString()}')
analyzer = BRepCheck_Analyzer(bottomBrep)
print('bottomValid: ', analyzer.IsValid())
analyzer = BRepCheck_Analyzer(topBrep)
print('topValid: ', analyzer.IsValid())
free_bounds = ShapeAnalysis_FreeBounds(bottomBrep)
print('bottomBrep has free edges: ', not free_bounds.GetClosedWires().IsNull())
free_bounds = ShapeAnalysis_FreeBounds(topBrep)
print('topBrep has free edges: ', not free_bounds.GetClosedWires().IsNull())

The printed results of checking:

Has Generated: False
HasErrors(): False
GetReport().DumpToString(): BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning
BOPAlgo_AlertBadPositioning

bottomValid:  True
topValid:  True
bottomBrep has free edges:  False
topBrep has free edges:  False
Thomas Delorme's picture

Hey, I have been having a similar problem lately. It occurs when I try to do a common operation between a box and a custom mesh (a staircase) that I built with a list of triangles, the BRepBuilderAPI_MakePolygon, BRepBuilderAPI_MakeFace, BRep_Builder.MakeShell(shell) and BRepBuilderAPI_MakeSolid.

My custom mesh seems fine when I used it alone. However, I lose a lot of triangles when I try to do a common operation with a cube which is just as big a the mesh.

Did you ever find a solution to your problem?

Best regards.

gkv311 n's picture

Daiva Daiva wrote:

the result is a topods_compound that does not contain any geometry. Does anyone have any tips how to fix this?

Your shapes have touching faces, which are known to be problematic within Boolean operations. For such use case, Fuzzy Boolean Operations might make operations more robust. For this, you need to specify fuzzy value to BRepAlgoAPI_Common::SetFuzzyValue(), something like:

commonFunction = BRepAlgoAPI_Common(bottomBrep, topBrep)
commonFunction.SetFuzzyValue(0.001);
commonFunction.Build()
common = commonFunction.Shape()

in your code. Within Draw Harness it helps to get result on your input shapes.

pload MODELING XDE VISUALIZATION
testreadstep bottomBrep.stp b
testreadstep topBrep.stp t
bcommon r1 b t
nbshapes r1
# not good - empty result

bfuzzyvalue 0.001
bcommon r1 b t
nbshapes r2
# OK we have some results with Fuzzy value

vinit View1
vdisplay -dispMode 0 b t
vsetcolor b BLUE
vsetcolor t GREEN
vfit
vdisplay -dispMode 1 r2
vsetcolor r2 RED

Attachments: