I want to create python bindings for a c++ project that heavily depends on VTK, and possibly make a paraview plugin with it. What would be the best way to approach this given the current state of development and roadmap.
I think it would be best to make a separate library, i.e. import vtkdocoolsthings
but It would seem a waste not to be able to use VTK tooling to generate python wrappers?
This is a very important topic, as nowadays Python wrapping is a must (if a library is not Python-wrapped then it essentially does not exist) and all the developer groups working with VTK are facing this issue if they want to upgrade to VTK9.
We are looking into generalizing this mechanism by creating a set of CMake functions that can Python-wrap 3D Slicer and its 150+ extensions with minimal changes compared to VTK-8.2. These macros will be first maintained in a separate repository (maybe later can be maintained as part of VTK) and the plan is to make it usable to wrap any VTK-based projects. @jcfr may be able to give more details on the current status.
We can expand on this more if needed, but it does work (modulo some PATH settings we need on Windows, but that’s a dashboard issue, not a code issue as such).
I gotta say that my cmake scripts for vtk-dicom are not a great example for how to do this. They’re terribly convoluted, since they support half a dozen different configurations. For that very same reason, though, they expose things at a very low level.
For the curious, the important bits for externally wrapping vtk-dicom for VTK 9 are here, and the module file itself is here.
Is there an executable called vtkWrapHierarchy-9.0 in vtkBuild/bin
no
What happens if you do make WrapHierarchy in your vtkBuild directory?
Ok, this created a new file
$ls bin
bin/vtkWrapHierarchy-9.0*
However, now I got a new error
make[2]: *** No rule to make target '/home/devmessias/projects/fury//vtkBuild/lib/libvtkCommonCore-9.0.so.9.0.1', needed by 'lib/libvtkWrappable.so'. Stop
Note that we are working on providing examples (and later templates) that shows how to build VTK9-based packages that can be used by C++ applications that embed Python (3D Slicer, Paraview, etc.) and also distributed on PyPI. See more information about this effort here.
Ah! OK! Thanks! It looks like it will work now.
I have a doubt. I want to install this wrapper inside an anaconda environment.
However, when I do make install inside Examples/Modules/Wrapping
-- Install configuration: ""
-- Installing: /usr/local/lib/python3.8/site-packages/wrapping/vtkWrappable.so
CMake Error at cmake_install.cmake:47 (file):
file INSTALL cannot copy file
"/home/.../Examples/Modules/Wrapping/lib/python3.8/site-packages/wrapping/vtkWrappable.so"
to "/usr/local/lib/python3.8/site-packages/wrapping/vtkWrappable.so".
CMAKE_INSTALL_PREFIX=/home/devmessias/anaconda3 ok, this worked!
However, running the example gives a exception
$ python3 ../module/Testing/import_wrappable.py (base)
Traceback (most recent call last):
File "../module/Testing/import_wrappable.py", line 1, in <module>
from wrapping import vtkWrappable
ImportError: libvtkWrappingPythonCore-9.0.so.1: cannot open shared object file: No such file or directory