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 Slicer4 with Python ITK wrapping, make the following change:
  
Edit this file:    '''''[path]''/Slicer3/SuperBuild/External_Insight.cmake'''  
+
Edit this file:    '''''[path]''/Slicer4/SuperBuild/External_Insight.cmake'''  
  
 
*In the section CMAKE_ARGS, add the following arguments:
 
*In the section CMAKE_ARGS, add the following arguments:
Line 8: Line 8:
 
       -DUSE_WRAP_ITK:BOOL=ON
 
       -DUSE_WRAP_ITK:BOOL=ON
 
       -DWRAP_ITK_PYTHON:BOOL=ON
 
       -DWRAP_ITK_PYTHON:BOOL=ON
 +
      -DWRAP_ITK_JAVA:BOOL=OFF
 +
      -DWRAP_ITK_TCL:BOOL=OFF
 
</pre>
 
</pre>
  
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)
+
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:
 
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
 
*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:
+
*Leave the first line, but add the ITK bin directory. My WrapITK.pth looks like this:
 
<pre>
 
<pre>
/cmn/dev/Slicer3-SuperBuild/Insight-build/Wrapping/WrapITK/Python
+
/cmn/git/Slicer4-sb/Insight-build/Wrapping/WrapITK/Python
/cmn/dev/Slicer3-SuperBuild/Insight-build/bin
+
/cmn/dev/Slicer4-sb/Insight-build/bin
 
</pre>
 
</pre>
*Now copy/link WrapITK.pth into the '''Slicer''' python site-packages directory. For example:
+
*Now copy/link WrapITK.pth into the '''Slicer''' python site-packages directory, within the Slicer lib directory. For example:
 
<pre>
 
<pre>
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/Slicer4-sb/Insight-build/Wrapping/WrapITK.Python/WrapITK.pth /cmn/git/Slicer4-sb/Slicer-build/lib/site-packages/
 
</pre>
 
</pre>
 
'''Note that the full path to WrapITK.pth must be given for a correct link!'''
 
'''Note that the full path to WrapITK.pth must be given for a correct link!'''
Line 31: Line 33:
  
 
NB:  
 
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 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
 
* the example in the screenshot is from here: http://www.insight-journal.org/browse/publication/85

Latest revision as of 23:16, 2 July 2011

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

Slicer3PythonITK.png

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