Import and export OFF or STL files to do mesh Boolean operations(Union, Difference, Intersection)

Hi,

I compiled the example Implicit Boolean(https://kitware.github.io/vtkexamples/site/Cxx/Filtering/ImplicitBoolean/) and it works fine for mesh Boolean operations. However, it uses the it’s own sphere, I want to import my own mesh data files which are in .OFF and STL format. I see that there are functions namely vtkSTLReader and vtkSTLWrite, but I am not able to use them. Is there any example that can tell me how to these functions to do boolean operations in C++? Also is there any function to do this in OFF format?

You can use vtkImplicitModeller to convert a mesh to an implicit function. It uses a structured grid representation internally, therefore it essentially resamples the original mesh at low resolution, so you will lose small details.

if you want to perform Boolean operation on meshes then I would recommend to use vtkbool remote module. VTK has built-in VTK Boolean mesh filters, but they are not robust (may crash or return invalid results for valid inputs).

I tried to use vtkbool you mentioned, but when I debug to test the boolean operation in C++, it occurred errors “Address access violation.”.Can you help analyze the reason? Thank you so much.

If you find that vtkbool reproducibly crashes when it is built with a recent VTK9 version (for example, the one that is in 3D Slicer’s Combine Models module in Sandbox extension) then you can report the issue. You need to provide the data sets, because most likely it is due to unexpected/not fully valid input meshes.

Thanks. It happened when I used VTK 8.1.1 + vs2013, but I changed to VTK 9.0.1 + vs2015, it was ok.