Boolean mesh implementations are really hard to implement correctly and they often fail (even in very expensive commercial software). Unfortunately, VTK’s implementation is quite fragile and it often generates incorrect meshes for complex inputs (and sometimes even for quite simple inputs, too). You may try to slightly move around the meshes until there are no errors in the output mesh.
If you need a definitive solution that always produces correct results then one option is to convert the mesh to binary labelmap, perform Boolean operations on the labelmap, then convert the labelmap back to surface mesh. Disadvantage of this approach that original model points are not preserved and you may need a lot of memory if you need preserve mesh geometry very accurately. If you want to give it a try without implementing anything, then you can perform these steps in 3D Slicer’s Segment Editor module (load models, import them to segmentation, use Logical operators effect, export resulting segment to model).
If you use Python, then another option is to use Boolean mesh operations of Blender, which is reported to be quite robust and very fast. You can import Blender Python package and process VTK meshes as described here.
My program needs computation time within 1sec (without visual rendering, only needs surface model like stl format)
Now, I consider blender or using construct mesh manually…
anyway, thanks again
There is an alternative boolean operations implementation (Apache License, Version 2.0) by @Ron84 that may be more robust. It could be a good project for someone to compare the performance and accuracy of both, with the aim of potentially integrating this implementation into VTK proper.
Do you know how to remove both the inputs of port 0 and 1 in a vtkBooleanOperationPolyDataFIlter. I tried using RemoveAllInputs() but it only removed the data in port 0.
I followed your instruction which is described in github and installed vtk 8.2 with vtkbool.
I found vtkbool.dll and lib, but there is no python package for vtkbool
I checked again that my vtk is installed with python wrapped
I completed the work with C++ but I wonder why vtkbool python package is not installed.
Can you give me some help?
@Ron84 I could take a shot at making this a Remote Module. That way you could still use your version with VTK. Ii it’s OK with you I could start soon. I will fork your repo and add what I need to make it a remote module. Eventually, you could take my changes and offer this option.