CGAL interoperability

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!

1 Like

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.

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).

Apparently you could use meshio python package (GitHub - nschloe/meshio: input/output for many mesh formats) to convert CGAL structures to .vtk file format.
Perhaps, pylgamesh (GitHub - nschloe/pygalmesh: A Python frontend to CGAL's mesh generators.) 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

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).

But maybe there are other and easier solutions.

For instance intersection between two polydata surfaces seems to be still problematic, based on what I find on #4769, #1476, #4747, while vtkCutter works but you need an implicit surface as in #706.

Thanks!

Boolean mesh operations in VTK proper indeed do not work, but you can use 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.

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.

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

Thanks!

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 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:

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.

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