[vtkusers] creating fiber bundles (python module)
    James Malcolm 
    malcolm at bwh.harvard.edu
       
    Mon Oct 12 23:01:53 EDT 2009
    
    
  
I want to start a new deterministic tractography module.
I think I know how to create the vtkPolyData lines, but I don't know how
to output a fiber bundle model with the python interface.
I've tried various methods; here are two.
  1) The first crashes Slicer 3 (Mac OSX)
  2) The second reports "unable to delete temporary model node ...".
The only difference is how I declare the output geometry type.
Could anyone give me a hint as to what I'm doing wrong?
  -jm
---- first method: crashes ------------------------------------------
XML = """<?xml version="1.0" encoding="utf-8"?>
<executable>
  <category>Tractography</category>
  <title>Python Streamline</title>
  <description>Streamline tractography.</description>
  <parameters>
    <label>IO</label>
    <description>Input/output parameters</description>
    <geometry type="fiberbundle">
      <name>ff</name> <channel>output</channel> <index>0</index>
      <label>Output Fiber bundle</label>
    </geometry>
  </parameters>
</executable>
"""
from Slicer import slicer
def Execute(ff):
    scene = slicer.MRMLScene
    pts = slicer.vtkPoints()
    lines = slicer.vtkCellArray()
    lines.InsertNextCell(3)
    lines.InsertCellPoint(0);  pts.InsertNextPoint( 1, 1, 1)
    lines.InsertCellPoint(1);  pts.InsertNextPoint( 0, 0, 0)
    lines.InsertCellPoint(2);  pts.InsertNextPoint(-1,-1,-1)
    pd = slicer.vtkPolyData()
    pd.SetPoints(pts)
    pd.SetLines(lines)
    pd.Update()
    ff = scene.GetNodeByID(ff)
    ff.SetAndObservePolyData(pd)
    return
---- second method: unable to delete temporary model node ---------------------------------
XML = """<?xml version="1.0" encoding="utf-8"?>
<executable>
  <category>Tractography</category>
  <title>Python Streamline</title>
  <description>Streamline tractography.</description>
  <parameters>
    <label>IO</label>
    <description>Input/output parameters</description>
    <geometry>
      <name>ff</name> <channel>output</channel> <index>0</index>
      <label>Output Fiber bundle</label>
    </geometry>
  </parameters>
</executable>
"""
from Slicer import slicer
def Execute(ff):
    scene = slicer.MRMLScene
    pts = slicer.vtkPoints()
    lines = slicer.vtkCellArray()
    lines.InsertNextCell(3)
    lines.InsertCellPoint(0);  pts.InsertNextPoint( 1, 1, 1)
    lines.InsertCellPoint(1);  pts.InsertNextPoint( 0, 0, 0)
    lines.InsertCellPoint(2);  pts.InsertNextPoint(-1,-1,-1)
    pd = slicer.vtkPolyData()
    pd.SetPoints(pts)
    pd.SetLines(lines)
    pd.Update()
    ff = scene.GetNodeByID(ff)
    ff.SetAndObservePolyData(pd)
    return
    
    
More information about the vtkusers
mailing list