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

**URL:** https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918
**Category:** Support
**Created:** [October 19, 2021, 1:35pm UTC](https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918 "2021-10-19T13:35:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Sumil\_Sood](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sumil_sood/32/4085_2.png) [@Sumil\_Sood](https://discourse.vtk.org/u/Sumil_Sood)
#### Post date: [October 19, 2021, 1:35pm UTC](https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918/1 "2021-10-19T13:35:56Z")

</div>

Hi,

I compiled the example Implicit Boolean([https://kitware.github.io/vtkexamples/site/Cxx/Filtering/ImplicitBoolean/](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?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 21, 2021, 5:39pm UTC](https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918/2 "2021-10-21T17:39:55Z")

</div>

You can use [vtkImplicitModeller](https://vtk.org/doc/nightly/html/classvtkImplicitModeller.html) 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](https://github.com/zippy84/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).

---

<div class="post-metadata">

### Author: ![Koly](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@Koly](https://discourse.vtk.org/u/Koly)
#### Post date: [January 12, 2022, 2:36am UTC](https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918/3 "2022-01-12T02:36:42Z")

</div>

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.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/2990ed236394389ecb59ba8f42467b1c4ff428de.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 18, 2022, 5:42am UTC](https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918/4 "2022-01-18T05:42:58Z")

</div>

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](https://github.com/zippy84/vtkbool/issues). You need to provide the data sets, because most likely it is due to unexpected/not fully valid input meshes.

---

<div class="post-metadata">

### Author: ![Koly](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@Koly](https://discourse.vtk.org/u/Koly)
#### Post date: [January 24, 2022, 2:12am UTC](https://discourse.vtk.org/t/import-and-export-off-or-stl-files-to-do-mesh-boolean-operations-union-difference-intersection/6918/5 "2022-01-24T02:12:59Z")

</div>

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