Incorrect boundary of the intersection between two hexahedrons

Would anyone know how to solve this problem, please?

I am using the vtkBooleanOperationPolyDataFilter class to produce the boundary of the intersection between two hexahedrons. Both hexahedrons are triangulated surfaces as required by this class.

The first hexahedron (white) is defined by the following corners:

corners_1 = [
    (0, 0, 0), (300, 0, 0), (300, 300, 0), (0, 300, 0),
    (0, 0, 100), (300, 0, 100), (300, 300, 100), (0, 300, 100)
]

And the second hexahedron (red) is defined by the following corners:

corners_2 = [
    (200, 200, z), (400, 200, z), (400, 400, z), (200, 400, z),
    (200, 200, 90), (400, 200, 90), (400, 400, 90), (200, 400, 90)
]

When I use z = 30, the vtkBooleanOperationPolyDataFilter class produces a correct result:

But when I use z = 40, this class produces an incorrect result:

Why is this happening? How can I solve this problem? If anyone can help me, I will be grateful.

My code: intersection.pyw (2.1 KB)

VTK’s built-in Boolean operators are known to suffer from these kind of problems, but the vtkbool remote module is supposed to work well.

1 Like

@lassoan, thank you! :pray: :slightly_smiling_face:

Hello,

Check whether your geometry meets the requirements to work well with vtkBooleanOperationPolyDataFilter:

Quoting the documentation (https://vtk.org/doc/nightly/html/classvtkBooleanOperationPolyDataFilter.html):

Computes the boundary of the union, intersection, or difference volume computed from the volumes defined by two input surfaces. The two surfaces do not need to be manifold, but if they are not, unexpected results may be obtained. The resulting surface is available in the first output of the filter. The second output contains a set of polylines that represent the intersection between the two input surfaces.

Warning
This filter is not designed to perform 2D boolean operations, and in fact relies on the inputs having no co-planar, overlapping cells.

(emphasis added)

regards,

Paulo

Hi @Paulo_Carvalho, both hexahedrons meet the requirements of the vtkBooleanOperationPolyDataFilter class. Thank you.

1 Like

We experienced many times that VTK’s Boolean operations fail for completely valid inputs. We ended up doing all Boolean operations by converting meshes to binary labelmaps, but for certain tasks it would be much better to work directly on meshes.

It would be nice if vtkbool module could be available Python, so that we could easily give it a try. By any chance, is it already available in PyPI?

Hi @lassoan! Converting meshes to binary labelmaps? Hummm… an interesting solution! :thinking: Unfortunately, vtkbool is not available in PyPI and https://www.lfd.uci.edu/~gohlke/pythonlibs/. I’m building VTK and vtkbool now. :wink:

1 Like