Slicer3WrapITKPython
The recommended ITK wrapping is WrapITK. To build Slicer3 with Python ITK wrapping, make the following change:
Edit this file: [path]/Slicer3/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
Then save and make Slicer as usual. BE WARNED that WrapITK will take a long time to compile because of all the templating (>2 hrs on new&fast computer)
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
- The first line should be ok, but must also add the ITK bin directory. My WrapITK.pth looks like this:
/cmn/dev/Slicer3-SuperBuild/Insight-build/Wrapping/WrapITK/Python /cmn/dev/Slicer3-SuperBuild/Insight-build/bin
- Now copy/link WrapITK.pth into the python site-packages directory. For example:
ln -s /cmn/dev/Slicer3-SuperBuild/Insight-build/Wrapping/WrapITK.Python/WrapITK.pth /cmn/dev/Slicer3-SuperBuild/python-build/lib/python2.6/site-packages/
Note that the full path to WrapITK.pth must be given for a correct link!
Now start Slicer and gain Insight!
NB: 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.