Slicer3WrapITKPython
The recommended ITK wrapping is WrapITK. To build Slicer4 with Python ITK wrapping, make the following change:
Edit this file: [path]/Slicer4/SuperBuild/External_Insight.cmake
- In the section CMAKE_ARGS, add the following arguments:
-DINSTALL_WRAP_ITK_COMPATIBILITY:BOOL=ON -DUSE_WRAP_ITK:BOOL=ON -DWRAP_ITK_PYTHON:BOOL=ON -DWRAP_ITK_JAVA:BOOL=OFF -DWRAP_ITK_TCL:BOOL=OFF
Then save and make Slicer as usual. BE WARNED that WrapITK will take a long time to compile because of all the templating. Turning off Java and Tcl helps.
If this works, the wrapping should build against the auto-detected system Python. There are options which could be added above so that ITK build uses the Slicer python, but since ITK (Insight) builds first that may cause some problems. Maybe CMake will automatically detect the dependency but I haven't tried it yet... So, the easy way is just let WrapITK do it's thing first, then add ITK manually to the Slicer python:
- Edit Slicer3-SuperBuild/Insight-build/Wrapping/WrapITK/Python/WrapITK.pth
- Leave the first line, but add the ITK bin directory. My WrapITK.pth looks like this:
/cmn/git/Slicer4-sb/Insight-build/Wrapping/WrapITK/Python /cmn/dev/Slicer4-sb/Insight-build/bin
- Now copy/link WrapITK.pth into the Slicer python site-packages directory, within the Slicer lib directory. For example:
ln -s /cmn/dev/Slicer4-sb/Insight-build/Wrapping/WrapITK.Python/WrapITK.pth /cmn/git/Slicer4-sb/Slicer-build/lib/site-packages/
Note that the full path to WrapITK.pth must be given for a correct link!
Now start Slicer and gain Insight!
NB:
- by default Slicer4 Python doesn't import 'site'. This is required to get .pth files in site-packages. Add to slicerqt.py or slicerrc.py
- the first time "from itk import *" is called, Slicer/python will appear to hang for some time (+/- minutes). I assume this is because some templated calls are being unwound or files precompiled to pyc. There may also be some import errors, but they appear to only pertain to a small subset of ITK. Subsequent imports should be instantaneous.
- the example in the screenshot is from here: http://www.insight-journal.org/browse/publication/85