Difference between revisions of "Slicer3WrapITKPython"

From NAMIC Wiki
Jump to: navigation, search
Line 1: Line 1:
 
The recommended ITK wrapping is WrapITK. To build Slicer3 with Python ITK wrapping, make the following change:
 
The recommended ITK wrapping is WrapITK. To build Slicer3 with Python ITK wrapping, make the following change:
  
Edit [path]/Slicer3/SuperBuild/External_Insight.cmake  
+
Edit this file:    '''''[path]''/Slicer3/SuperBuild/External_Insight.cmake'''
  
 
*In the section CMAKE_ARGS, add the following arguments:
 
*In the section CMAKE_ARGS, add the following arguments:
Line 24: Line 24:
 
ln -s /cmn/dev/Slicer3-SuperBuild/Insight-build/Wrapping/WrapITK.Python/WrapITK.pth /cmn/dev/Slicer3-SuperBuild/python-build/lib/python2.6/site-packages/
 
ln -s /cmn/dev/Slicer3-SuperBuild/Insight-build/Wrapping/WrapITK.Python/WrapITK.pth /cmn/dev/Slicer3-SuperBuild/python-build/lib/python2.6/site-packages/
 
</pre>
 
</pre>
Note that you must give the full path to WrapITK.pth
+
'''Note that the full path to WrapITK.pth must be given for a correct link!'''
  
Now start Slicer and gain Insight!
+
Now start Slicer and gain Insight!  
 +
 
 +
[[image:Slicer3PythonITK.png]]
 +
 
 +
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.

Revision as of 20:58, 15 October 2010

Home < 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!

Slicer3PythonITK.png

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.