Difference between revisions of "Slicer3:2DPlotting"
(→Desgin) |
|||
Line 4: | Line 4: | ||
==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. This widget observes one plot manager node (vtkMRMLXYPlotManagerNode), and repaint the graph when it receives UpdateGraphEvent from the plot manager node. |
− | * | + | *vtkMRMLXYPlotManagerNode: 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. | ||
Revision as of 03:43, 21 August 2009
Home < Slicer3:2DPlottingContents
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. This widget observes one plot manager node (vtkMRMLXYPlotManagerNode), and repaint the graph when it receives UpdateGraphEvent from the plot manager node.
- vtkMRMLXYPlotManagerNode: 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.
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.