# CGAL interoperability

**URL:** https://discourse.vtk.org/t/cgal-interoperability/5985
**Category:** Support
**Created:** [June 13, 2021, 9:45am UTC](https://discourse.vtk.org/t/cgal-interoperability/5985 "2021-06-13T09:45:54Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![bistek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bistek/32/2344_2.png) [@bistek](https://discourse.vtk.org/u/bistek)
#### Post date: [June 13, 2021, 9:45am UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/1 "2021-06-13T09:45:54Z")

</div>

Hello, is somebody aware of good examples on processing VTK objects - e.g. polydata triangulated surfaces - with CGAL tools - e.g. remeshing, Boolean operations, topology. I would be particularly interested in a way to directly access the VTK objects data structure, avoiding creating new CGAL objects etc.

If examples are available in Python, even better!

Thanks!

---

<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: [June 14, 2021, 1:33pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/2 "2021-06-14T13:33:00Z")

</div>

CGAL uses a restrictive license (GPL). Most companies prohibit using GPL licensed libraries and try to avoid relying on libraries with commercial license. Many researchers choose to not depend on GPL libraries either because it can make collaboration with companies or potential commercialization efforts very difficult.

Since VTK has free, non-restrictive license and can do many things of what CGAL does, I don’t think there is a strong interest in mixing VTK with CGAL among VTK developers or heavy VTK users.

---

<div class="post-metadata">

### Author: ![DavidMiraut](https://discourse.vtk.org/user_avatar/discourse.vtk.org/davidmiraut/32/3329_2.png) [@DavidMiraut](https://discourse.vtk.org/u/DavidMiraut)
#### Post date: [June 14, 2021, 1:35pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/3 "2021-06-14T13:35:13Z")

</div>

Besides, I guess CGAL and VTK object models are pretty different. You would need some non-trivial conversion tool in order to interact in both “directions”, or saving intermediate results in standard mesh file formats (like STL or similar).

---

<div class="post-metadata">

### Author: ![DavidMiraut](https://discourse.vtk.org/user_avatar/discourse.vtk.org/davidmiraut/32/3329_2.png) [@DavidMiraut](https://discourse.vtk.org/u/DavidMiraut)
#### Post date: [June 14, 2021, 3:24pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/4 "2021-06-14T15:24:01Z")

</div>

Apparently you could use meshio python package ([GitHub - nschloe/meshio: input/output for many mesh formats](https://github.com/nschloe/meshio)) to convert CGAL structures to .vtk file format.  
Perhaps, pylgamesh ([GitHub - nschloe/pygalmesh: A Python frontend to CGAL's mesh generators.](https://github.com/nschloe/pygalmesh)) has enough CGAL functionality for you. In that case, meshio interface is already integrated.  
Be careful with licence, as Andras Lasso pointed.  
Most of CGAL packages are GPL, and whole pylgamesh too:  
[pygalmesh/LICENSE at main · nschloe/pygalmesh · GitHub](https://github.com/nschloe/pygalmesh/blob/main/LICENSE)

---

<div class="post-metadata">

### Author: ![bistek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bistek/32/2344_2.png) [@bistek](https://discourse.vtk.org/u/bistek)
#### Post date: [June 14, 2021, 4:07pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/5 "2021-06-14T16:07:47Z")

</div>

Hello and thanks very much to everybody! The reason why I would like to use also CGAL is that VTK, being focused more on visualisation, is apparently missing some algorithms for more advanced meshing, topological and Boolean processing etc (see e.g. the polygon mesh processing [CGAL 5.2.2 - Polygon Mesh Processing: User Manual](https://doc.cgal.org/latest/Polygon_mesh_processing/index.html)).

But maybe there are other and easier solutions.

---

<div class="post-metadata">

### Author: ![bistek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bistek/32/2344_2.png) [@bistek](https://discourse.vtk.org/u/bistek)
#### Post date: [June 14, 2021, 4:18pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/6 "2021-06-14T16:18:45Z")

</div>

For instance intersection between two polydata surfaces seems to be still problematic, based on what I find on [#4769](https://discourse.vtk.org/t/obtaining-the-curve-of-intersection-in-vtk/4769https://discourse.vtk.org/t/obtaining-the-curve-of-intersection-in-vtk/4769), [#1476](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476), [#4747](https://discourse.vtk.org/t/intersection-of-3d-mesh-with-polydata-return-only-intersecting-mesh-region/4747), while vtkCutter works but you need an implicit surface as in [#706](https://discourse.vtk.org/t/intersect-polydata-with-an-implicit-function/706).

Thanks!

---

<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: [June 14, 2021, 4:53pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/7 "2021-06-14T16:53:50Z")

</div>

Boolean mesh operations in VTK proper indeed do not work, but you can use [vtkBool](https://github.com/zippy84/vtkbool) instead, which is very robust. We made vtkBool available in 3D Slicer’s Python environment, but as VTK remote module infrastructure matures, we’ll make sure this and other packages will be available in Python.

---

<div class="post-metadata">

### Author: ![bistek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bistek/32/2344_2.png) [@bistek](https://discourse.vtk.org/u/bistek)
#### Post date: [June 15, 2021, 6:00am UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/8 "2021-06-15T06:00:29Z")

</div>

Hello, I do not understand if vtkbool is really usable. On GitHub there are open issues citing problems with VTK 9, the Python wrapper, and processing meshes (exactly what I’d like to do).

On the other hand I have found an example on interfacing VTK and CGAL for meshes that seems pretty straightforward [here](https://github.com/CGAL/cgal-paraview-plugins).

I’ll try myself but I was wondering if you have any experience with that.

Thanks!

---

<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: [June 16, 2021, 2:55pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/9 "2021-06-16T14:55:40Z")

</div>

All polygonal mesh Boolean operations have problems, especially when they get non-manifold mesh as input. We have been testing vtkbool on very complicated meshes and it works quite well (see for example [this](https://github.com/SlicerIGT/SlicerBoneReconstructionPlanner) project). We rarely find any issues and most importantly, there is a developer that you can communicate with and willing to look at problematic meshes. You can try this in a few minutes, using a convenient GUI, by installing 3D Slicer, installing the Sandbox extension from its Extensions manager (takes 3 clicks), drag-and-drop your surface meshes into the application, and use “Combine models” module:

[![](https://discourse.vtk.org/uploads/default/original/2X/c/ccd7bd4ef1a3e29a6ffa20b02a4b52c977ab4227.jpeg "Combine patient and CAD models in 3D Slicer using union/intersection/difference operations") ](https://www.youtube.com/watch?v=2MOAk2oNbKw)

I don’t think that currently vtkbool provides packages on PyPI and conda for recent VTK versions, but we are working towards this. For now, you can use 3D Slicer’s GUI and/or Python environment.

---

<div class="post-metadata">

### Author: ![bistek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bistek/32/2344_2.png) [@bistek](https://discourse.vtk.org/u/bistek)
#### Post date: [June 16, 2021, 3:05pm UTC](https://discourse.vtk.org/t/cgal-interoperability/5985/10 "2021-06-16T15:05:50Z")

</div>

Thanks! I’ll come back with results of my tests.
