Documentation/4.1/Developers/Python scripting

From Slicer Wiki
Revision as of 21:41, 26 February 2011 by Pieper (talk | contribs) (Created page with '# do this before building slicer4 - or do "cd Slicer4-superbuild/; rm -rf python* ; make" sudo apt-get install libreadline6-dev cd Slicer4-superbuild # this should be done in s…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Home < Documentation < 4.1 < Developers < Python scripting
  1. do this before building slicer4 - or do "cd Slicer4-superbuild/; rm -rf python* ; make"

sudo apt-get install libreadline6-dev

cd Slicer4-superbuild

  1. this should be done in superbuild script
(cd ./VTK-build/Wrapping/Python;  ../../../Slicer-build/Slicer4 --launch ../../../python-build/bin/python setup.py install)


git clone git://github.com/ipython/ipython.git git checkout 0.10.2

(cd ./ipython;  ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)


svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint matplotlib-source

(cd ./matplotlib-source;  ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)


rm -rf matplotlib-source

./Slicer-build --launch xterm &

  1. in xterm:

./python-build/bin/ipython

import vtk import slicer mrml = slicer.vtkMRMLScene() vl = slicer.vtkSlicerVolumesLogic() vl.SetAndObserveMRMLScene(mrml) n = vl.AddArchetypeVolume('../Slicer4/Testing/Data/Input/MRHeadResampled.nhdr', 'CTC') i = n.GetImageData() print (i.GetScalarRange())

import vtk.util.numpy_support a = vtk.util.numpy_support.vtk_to_numpy(i.GetPointData().GetScalars()) print(a.min(),a.max())

import matplotlib import matplotlib.pyplot n, bins, patches = matplotlib.pyplot.hist(a, 50, facecolor='g', alpha=0.75) matplotlib.pyplot.show()