Difference between revisions of "Projects/Slicer3/2007 Project Week Python support in Slicer3"

From NAMIC Wiki
Jump to: navigation, search
Line 10: Line 10:
 
* Mario Negri Institute: Luca Antiga
 
* Mario Negri Institute: Luca Antiga
  
 +
{|
 +
|[[Image:PythonModuleInterface.png|thumb|512px]]
 +
|[[Image:PythonModuleOutput.png|thumb|512px]]
 +
|}
 +
 +
<div style="margin: 20px;">
 +
 +
<div style="width: 27%; float: left; padding-right: 3%;">
 +
 +
<h1>Objective</h1>
 +
To extend Python support in Slicer3.
 +
 +
 +
</div>
 +
 +
<div style="width: 27%; float: left; padding-right: 3%;">
 +
 +
<h1>Approach, Plan</h1>
 +
 +
* Python scripting language inside Slicer3 to write short, useful scripts for processing
 +
 +
* Python execution model. A Python class required to have
 +
** a method that spits out the description of the instance variables to be exposed on the GUI, the CLI module way (in this case, instance variables could be wrapped vtk objects or wrapped MRML nodes)
 +
** a standard method (e.g. Execute()) that runs the class main functionality
 +
** Slicer would take care of building the GUI and setting the state of the object on the basis of the XML description before calling Execute.
 +
 +
</div>
 +
 +
<div style="width: 40%; float: left;">
  
 
<h1>Progress</h1>
 
<h1>Progress</h1>
Line 44: Line 73:
 
     outputVolume.SetIJKToRASMatrix ( matrix )
 
     outputVolume.SetIJKToRASMatrix ( matrix )
 
     return
 
     return
 
[[Image:PythonModuleInterface.png]]
 
[[Image:PythonModuleOutput.png]]
 
 
<div style="margin: 20px;">
 
 
<div style="width: 27%; float: left; padding-right: 3%;">
 
 
<h1>Objective</h1>
 
To extend Python support in Slicer3.
 
 
 
</div>
 
 
<div style="width: 27%; float: left; padding-right: 3%;">
 
 
<h1>Approach, Plan</h1>
 
 
* Python scripting language inside Slicer3 to write short, useful scripts for processing
 
 
* Python execution model. A Python class required to have
 
** a method that spits out the description of the instance variables to be exposed on the GUI, the CLI module way (in this case, instance variables could be wrapped vtk objects or wrapped MRML nodes)
 
** a standard method (e.g. Execute()) that runs the class main functionality
 
** Slicer would take care of building the GUI and setting the state of the object on the basis of the XML description before calling Execute.
 
 
</div>
 
 
<div style="width: 40%; float: left;">
 
  
  

Revision as of 14:09, 29 June 2007

Home < Projects < Slicer3 < 2007 Project Week Python support in Slicer3
Python-logo.png


Key Investigators

  • GE: Dan Blezek
  • Isomics: Steve Pieper
  • Mario Negri Institute: Luca Antiga
PythonModuleInterface.png
PythonModuleOutput.png

Objective

To extend Python support in Slicer3.


Approach, Plan

  • Python scripting language inside Slicer3 to write short, useful scripts for processing
  • Python execution model. A Python class required to have
    • a method that spits out the description of the instance variables to be exposed on the GUI, the CLI module way (in this case, instance variables could be wrapped vtk objects or wrapped MRML nodes)
    • a standard method (e.g. Execute()) that runs the class main functionality
    • Slicer would take care of building the GUI and setting the state of the object on the basis of the XML description before calling Execute.

Progress

  • Implemented Python Modules
    • Can put .py files in the CommandLine Module path
    • If the Python module provides an XML description, and an Execute function, will be added as a CommandLine Module
  • ToDo
    • Check-in (needs USE_PYTHON guards)
    • Progress reporting
    • Simplify the API
    • Automate command line parsing using XML description
def Execute ( inputVolume, outputVolume, conductance=1.0, timeStep=0.0625, iterations=1 ):
   print "Executing Python Demo Application!"
   # For the moment, be sure to cast...
   conductance = float ( conductance )
   timeStep = float ( timeStep )
   iterations = int ( iterations )
   Slicer = __import__ ( "Slicer" );
   slicer = Slicer.Slicer()
   scene = slicer.MRMLScene
   print "Input: ", inputVolume
   print "Output: ", outputVolume
   inputVolume = scene.GetNodeByID ( inputVolume );
   outputVolume = scene.GetNodeByID ( outputVolume );
   
   filter = slicer.vtkITKGradientAnisotropicDiffusionImageFilter.New()
   filter.SetInput ( inputVolume.GetImageData() )
   filter.Update()
   outputVolume.SetAndObserveImageData(filter.GetOutput())
   matrix = slicer.vtkMatrix4x4.New()
   inputVolume.GetIJKToRASMatrix ( matrix )
   outputVolume.SetIJKToRASMatrix ( matrix )
   return




References