Difference between revisions of "Slicer3:2DPlotting"

From Slicer Wiki
Jump to: navigation, search
Line 1: Line 1:
=Introduction=
+
==Introduction==
Development of 2D plotting in 3D Slicer is in progress as part of 4D Analysis Module Project. The goal is to provide a capability to plot time series data e.g. time-intensity plot, cardiac signal etc. This page describes the design, status and small tutorials.
+
Development of 2D plotting in 3D Slicer is in progress as part of 4D Analysis Module Project. The goal is to provide a widget and data structures to plot time series data e.g. time-intensity plot, cardiac signal etc, on 3D Slicer including C++ codes and Python module/console. This page describes the overview of the work and some tutorials.
  
=Desgin=
+
==Desgin==
 
The 2D plotting is implemented as a set of classes consisting of
 
The 2D plotting is implemented as a set of classes consisting of
 
*vtkSliceerXYPlotWidget: A widget class to display a graph.
 
*vtkSliceerXYPlotWidget: A widget class to display a graph.
 
*vtkMRMLPlotManagerNode: A MRML node class to store graph property as well as pointers to vtkMRMLArrayPlotNode objects
 
*vtkMRMLPlotManagerNode: A MRML node class to store graph property as well as pointers to vtkMRMLArrayPlotNode objects
 
*vtkMRMLArrayPlotNode: A MRML node class to hold line property and a pointer to vtkMRMLDoubleArrayNode, which hold array data to be plotted.
 
*vtkMRMLArrayPlotNode: A MRML node class to hold line property and a pointer to vtkMRMLDoubleArrayNode, which hold array data to be plotted.
 
  
 
{|
 
{|
 
|[[Image:Slicer3_2DPlotting_Diagram.png|thumb|400px|The diagram of 2D plotting classes.]]
 
|[[Image:Slicer3_2DPlotting_Diagram.png|thumb|400px|The diagram of 2D plotting classes.]]
 
|}
 
|}
 +
 +
==Install==
 +
Currently, the 2D plotting functionality is part of 4D Analysis Module and you need to build the module manually. Please refer 4D Analysis Module for detailed instruction.
 +
 +
==Tutorial==
 +
Here is a small instruction to use the plotting function from Python interface.
 +
 +
0. Open '''4D Analysis''' module in '''4D''' section of the module menu. The XY plot widget is in '''Intensity Plot'''  Tab.
 +
 +
1. Open Python interactor from "Window" menu.
 +
 +
2. Import packages and get MRML scene:
 +
>> import Slicer
 +
>> import numpy
 +
>> scene = Slicer.slicer.MRMLScene
 +
 +
3. Create a DoubleArray to store a dummy curve data. Suppose we have 11 time points (we need 3 components for each time point to store time, value and standard deviation).
 +
>> darray = Slicer.slicer.vtkDoubleArray()
 +
>> darray.SetNumberOfComponents(3)
 +
>> darray.SetNumberOfTuples(11)
 +
 +
4. Substitute dummy values into the array.
 +
>> a[:, 0] = numpy.arange(0, 1.0, 0.1) * numpy.pi
 +
>> a[:, 1] = numpy.sin(a[:, 0])
 +
>> a[:, 2] = 1
 +
 +
5. Create an MRML node to hold the array data.
 +
>> arrayNode = Slicer.slicer.vtkMRMLDoubleArrayNode()
 +
>> scene.AddNode(arrayNode)
 +
>> arrayNode.SetArray(darray)
 +
 +
6. Create an array plot node.
 +
>> arrayPlotNode = Slicer.slicer.vtkMRMLArrayPlotNode()
 +
>> scene.AddNode(arrayPlotNode)
 +
 +
7. Obtain the plot manager node, which has already been loaded in the 4D Analysis module. We assume that there is only one manager node in 3D Slicer.
 +
>> pmnode = scene.GetNodeByID('vtkMRMLXYPlotManagerNode1')
 +
>> pmnode.AddPlotNode(arrayPlotNode)
 +
 +
8. Add the array plot node to the plot manager node.
 +
>> pmnode.AddPlotNode(arrayPlotNode)
 +
 +
9. Refresh the widget.
 +
>> pmnode.Refresh()
 +
 +
After Refresh() function call, the XY plot widget show the sin curve.

Revision as of 03:36, 21 August 2009

Home < Slicer3:2DPlotting

Introduction

Development of 2D plotting in 3D Slicer is in progress as part of 4D Analysis Module Project. The goal is to provide a widget and data structures to plot time series data e.g. time-intensity plot, cardiac signal etc, on 3D Slicer including C++ codes and Python module/console. This page describes the overview of the work and some tutorials.

Desgin

The 2D plotting is implemented as a set of classes consisting of

  • vtkSliceerXYPlotWidget: A widget class to display a graph.
  • vtkMRMLPlotManagerNode: A MRML node class to store graph property as well as pointers to vtkMRMLArrayPlotNode objects
  • vtkMRMLArrayPlotNode: A MRML node class to hold line property and a pointer to vtkMRMLDoubleArrayNode, which hold array data to be plotted.
The diagram of 2D plotting classes.

Install

Currently, the 2D plotting functionality is part of 4D Analysis Module and you need to build the module manually. Please refer 4D Analysis Module for detailed instruction.

Tutorial

Here is a small instruction to use the plotting function from Python interface.

0. Open 4D Analysis module in 4D section of the module menu. The XY plot widget is in Intensity Plot Tab.

1. Open Python interactor from "Window" menu.

2. Import packages and get MRML scene:

>> import Slicer
>> import numpy
>> scene = Slicer.slicer.MRMLScene

3. Create a DoubleArray to store a dummy curve data. Suppose we have 11 time points (we need 3 components for each time point to store time, value and standard deviation).

>> darray = Slicer.slicer.vtkDoubleArray()
>> darray.SetNumberOfComponents(3)
>> darray.SetNumberOfTuples(11)

4. Substitute dummy values into the array.

>> a[:, 0] = numpy.arange(0, 1.0, 0.1) * numpy.pi
>> a[:, 1] = numpy.sin(a[:, 0])
>> a[:, 2] = 1

5. Create an MRML node to hold the array data.

>> arrayNode = Slicer.slicer.vtkMRMLDoubleArrayNode()
>> scene.AddNode(arrayNode)
>> arrayNode.SetArray(darray)

6. Create an array plot node.

>> arrayPlotNode = Slicer.slicer.vtkMRMLArrayPlotNode()
>> scene.AddNode(arrayPlotNode)

7. Obtain the plot manager node, which has already been loaded in the 4D Analysis module. We assume that there is only one manager node in 3D Slicer.

>> pmnode = scene.GetNodeByID('vtkMRMLXYPlotManagerNode1')
>> pmnode.AddPlotNode(arrayPlotNode)

8. Add the array plot node to the plot manager node.

>> pmnode.AddPlotNode(arrayPlotNode)

9. Refresh the widget.

>> pmnode.Refresh()

After Refresh() function call, the XY plot widget show the sin curve.