<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.2%2FDevelopers%2FMRML</id>
	<title>Documentation/4.2/Developers/MRML - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.2%2FDevelopers%2FMRML"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.2/Developers/MRML&amp;action=history"/>
	<updated>2026-04-12T13:22:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.2/Developers/MRML&amp;diff=32698&amp;oldid=prev</id>
		<title>UpdateBot: Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.2/Developers/MRML&amp;diff=32698&amp;oldid=prev"/>
		<updated>2013-06-14T07:41:08Z</updated>

		<summary type="html">&lt;p&gt;Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 07:41, 14 June 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Slicer MRML Overview =&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Slicer MRML Overview =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.2/Developers/MRML&amp;diff=28844&amp;oldid=prev</id>
		<title>UpdateBot: Nightly -&gt; 4.2</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.2/Developers/MRML&amp;diff=28844&amp;oldid=prev"/>
		<updated>2012-10-31T22:01:17Z</updated>

		<summary type="html">&lt;p&gt;Nightly -&amp;gt; 4.2&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Slicer MRML Overview =&lt;br /&gt;
&lt;br /&gt;
*MRML Library provides API for managing medical image data types (Volumes, Models, Transforms, Fiducials, Cameras, etc) and their visualization. &lt;br /&gt;
*Each data type is represented by a special MRML node. &lt;br /&gt;
*MRML Scene is a collection of MRML nodes. &lt;br /&gt;
*Slicer MRML data model is implemented independent of the visualization and algorithmic components of the system. &lt;br /&gt;
*Other Slicer components (Logic and GUI) observe changes in MRML scene and individual nodes and process change MRML events.&lt;br /&gt;
&lt;br /&gt;
For more details on MRML architecture see [http://www.na-mic.org/Wiki/images/e/e3/Slicer_3-alpha-2006-04-03.ppt Architecture Slides].&lt;br /&gt;
&lt;br /&gt;
= MRML Scene =&lt;br /&gt;
&lt;br /&gt;
*MRML Scene manages MRML nodes : add, delete, find, find by type, etc.&lt;br /&gt;
*MRML Scene provides persistence of MRML nodes (reading/writing to/from XML file). &lt;br /&gt;
*MRML  Scene provides Undo/Redo mechanism that restores a previous state of the scene and individual nodes.&lt;br /&gt;
&lt;br /&gt;
= MRML Nodes =&lt;br /&gt;
 &lt;br /&gt;
*The MRML nodes are designed to store the state of the Slicer application, both raw data and visualization parameters.&lt;br /&gt;
&lt;br /&gt;
There following is a set of core MRLN nodes that store the state of core Slicer modules:&lt;br /&gt;
&lt;br /&gt;
* vtkMRMLCameraNode&lt;br /&gt;
* vtkMRMLClipModelsNode&lt;br /&gt;
* vtkMRMLSliceCompositeNode&lt;br /&gt;
* vtkMRMLSliceNode&lt;br /&gt;
* vtkMRMLColorNode&lt;br /&gt;
* vtkMRMLTransformNode&lt;br /&gt;
* vtkMRMLLinearTransformNode&lt;br /&gt;
* vtkMRMLTransformableNode&lt;br /&gt;
* vtkMRMLFiducialListNode&lt;br /&gt;
* vtkMRMLModelNode&lt;br /&gt;
* vtkMRMLModelDisplayNode&lt;br /&gt;
* vtkMRMLStorageNode&lt;br /&gt;
* vtkMRMLModelStorageNode&lt;br /&gt;
* vtkMRMLVolumeNode&lt;br /&gt;
* vtkMRMLScalarVolumeNode&lt;br /&gt;
* vtkMRMLVectorVolumeNode&lt;br /&gt;
* vtkMRMLTensorVolumeNode&lt;br /&gt;
* vtkMRMLDiffusionTensorVolumeNode&lt;br /&gt;
* vtkMRMLDiffusionWeightedVolumeNode&lt;br /&gt;
* vtkMRMLVolumeDisplayNode&lt;br /&gt;
* vtkMRMLVectorVolumeDisplayNode&lt;br /&gt;
* vtkMRMLDiffusionTensorVolumeDisplayNode&lt;br /&gt;
* vtkMRMLDiffusionWeightedVolumeDisplayNode&lt;br /&gt;
* vtkMRMLVolumeHeaderlessStorageNode&lt;br /&gt;
* vtkMRMLVolumeArchetypeStorageNode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt; &lt;br /&gt;
*MRML nodes are organized into C++ class hierarchies, all derived from vtkMRMLNode class. &lt;br /&gt;
*For example vtkMRMLTransformableNode is the parent class of Volume, Model, Fiducial, and Transformation nodes; vtkVolumeNode is a parent of vtkMRMLScalarVolumeNode and vtkMRMLVectorVolumeNode&lt;br /&gt;
*All MRML nodes have to implement certain standard API: ReadAttributes, WriteAttributes, Copy, etc.&lt;br /&gt;
{|&lt;br /&gt;
|[[Image: Slicer3_MRML_Node_Hier.jpg|thumb|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= MRML node attributes =&lt;br /&gt;
&lt;br /&gt;
MRML nodes can store custom attributes as (attribute name; attribute value) pairs.&lt;br /&gt;
&lt;br /&gt;
To avoid name clashes custom modules that adds attributes to nodes should prefix the attribute name with the module's name and the '.' character. Example: the DoseVolumeHistogram module can use attribute names such as DoseVolumeHistogram.StructureSetName, DoseVolumeHistogram.Unit, DoseVolumeHistogram.LineStyle.&lt;br /&gt;
&lt;br /&gt;
= References to MRML Nodes =&lt;br /&gt;
&lt;br /&gt;
*Some MRML nodes have references to other nodes. &lt;br /&gt;
*Transformable Node has a reference to a Transformation node. Transformation node has a reference to its parent Transformation node. &lt;br /&gt;
*References are stored by node ID.&lt;br /&gt;
*Use vtkSetReferenceStringMacro to set reference ID (it registers reference with the scene).&lt;br /&gt;
*Access methods should check if the referenced node is still in the MRML scene using its ID.&lt;br /&gt;
{|&lt;br /&gt;
|[[Image: Slicer3_MRML_Trans_Ref.jpg|thumb|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= MRML Events and Observers =&lt;br /&gt;
&lt;br /&gt;
*Changes in MRML scene and individual nodes propagate to other observing nodes, GUI and Logic objects via vtk events and command-observer mechanism.&lt;br /&gt;
*Use vtk AddObserver() and InvokeEvent() methods. vtkSetMacro generates ModifiedEvent.&lt;br /&gt;
*The command-observer mechanism for MRML is implemented using  helper vtkObserverManager, class, MRML Observer macros, and ProcessMRMLEvents method.&lt;br /&gt;
*Observers should store a registered pointer to a MRML node to prevent callbacks on a deleted object. &lt;br /&gt;
{|&lt;br /&gt;
|[[Image: Slicer3_MRML_Observ.jpg|thumb|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*MRML observer macros are defined in Libs/MRML/vtkMRMLNode.h&lt;br /&gt;
*vtkSetMRMLObjectMacro - registers MRML node with another vtk object (another MRML node, Logic or GUI). No observers added.&lt;br /&gt;
*vtkSetAndObserveMRMLObjectMacro - registers MRML node and adds an observer for vtkCommand::ModifyEvent. &lt;br /&gt;
*vtkSetAndObserveMRMLObjectEventsMacro - registers MRML node and adds an observer for a specified set of events. &lt;br /&gt;
*SetAndObserveMRMLScene[Events]() method is used in GUI and Logic to observe Modify, NewScene, NodeAdded, etc. events.&lt;br /&gt;
*ProcessMRMLEvents method should be implemented in MRML nodes, Logic, and GUI classes in order to process events from the observed nodes.&lt;br /&gt;
&lt;br /&gt;
= Creating Custom MRML Node Classes=&lt;br /&gt;
&lt;br /&gt;
*Custom MRML nodes provide persistent storage for the module parameters. &lt;br /&gt;
*Custom MRML nodes should be registered with the MRML scene using RegisterNodeClass() so they can be saved and restored from a scene file. &lt;br /&gt;
*Classes should implement the following methods: &lt;br /&gt;
*CreateNodeInstance() – similar to VTK New() method only not static. &lt;br /&gt;
*GetNodeTagName() – return a unique XML tag for this node. &lt;br /&gt;
*ReadXMLAttributes() – reads node attributes from XML file as name-value pairs. &lt;br /&gt;
*WriteXML() – writes node attributes to output stream (as in interpolate=&amp;quot;1&amp;quot; ).&lt;br /&gt;
*Copy() – copies node attributes. &lt;br /&gt;
&lt;br /&gt;
*If the node has references to other nodes the following additional methods should be implemented: &lt;br /&gt;
 –UpdateReferenceID() - updates the stored reference to another node. &lt;br /&gt;
 –UpdateScene()- updates other nodes in the scene depending on this node or updates this node if it depends on other nodes when the scene is read in. &lt;br /&gt;
   This method is called automatically by XML parser after all nodes are created. &lt;br /&gt;
*An example of a custom MRML node implementation: vtkMRMLGradientAnisotropicDiffusionFilterNode in Modules/GradientAnisotropicDiffusionFilter directory. &lt;br /&gt;
*To add node to the MRML scene: &lt;br /&gt;
 –In the code: use standard vtk New() and add node to the scene using vtkMRMLScene::AddNode(vtkMRMLNode *)&lt;br /&gt;
 –By user request: use vtkSlicerNodeSelectorWidget that creates a new node from the module’s UI.&lt;br /&gt;
&lt;br /&gt;
= FAQ =&lt;br /&gt;
== How to add into the scene==&lt;br /&gt;
* Generic pattern &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 vtkMRML???Node* nodeToAdd = vtkMRML???Node::New();&lt;br /&gt;
 ...&lt;br /&gt;
 mrmlScene-&amp;gt;AddNode(nodeToAdd);&lt;br /&gt;
 nodeToAdd-&amp;gt;Delete();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* Add a polydata to the scene&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 vtkNew&amp;lt;vtkMRMLModelNode&amp;gt; modelNode;&lt;br /&gt;
 modelNode-&amp;gt;SetPolyData(polyData);&lt;br /&gt;
 mrmlScene-&amp;gt;AddNode(modelNode.GetPointer());&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* Load a polyData from file&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 vtkSlicerModelsLogic* modelsLogic = ...;&lt;br /&gt;
 //modelsLogic-&amp;gt;SetMRMLScene(mrmlScene);&lt;br /&gt;
 modelsLogic-&amp;gt;AddModel(polyDataFileName);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
==Views==&lt;br /&gt;
* Change the volumes in the 2D views ([https://github.com/fedorov/ChangeTrackerPy/blob/master/Wizard/Helper.py#L82 source])&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 appLogic = slicer.app.applicationLogic()&lt;br /&gt;
 selectionNode = appLogic.GetSelectionNode()&lt;br /&gt;
 selectionNode.SetReferenceActiveVolumeID(bg)&lt;br /&gt;
 selectionNode.SetReferenceSecondaryVolumeID(fg)&lt;br /&gt;
 appLogic.PropagateVolumeSelection()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Undo/Redo Mechanism =&lt;br /&gt;
&lt;br /&gt;
*Undo/Redo is based on saving and restoring the state of MRML nodes in the Scene. &lt;br /&gt;
*MRML scene can save snapshot of all nodes into a special Undo and Redo stacks. &lt;br /&gt;
*The Undo and Redo stacks store copies of nodes that have changed from the previous snapshot. The node that have not changed are stored by a reference (pointer). &lt;br /&gt;
*When an Undo is called on the scene, the current state of Undo stack is copied into the current scene and also into Redo stack. &lt;br /&gt;
*  All Undoable operations must store their data as MRML nodes&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|[[Image: Slicer3_MRML_Undo.jpg|thumb|400px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Developer controls at what point the snapshot is saved by calling SaveStateForUndo method on the MRML scene. &lt;br /&gt;
–SaveStateForUndo() - saves the state of all nodes in the scene &lt;br /&gt;
&amp;lt;br /&amp;gt;–SetActiveScene(vtkMRMLScene *) - saves the state of the specified node. &lt;br /&gt;
&amp;lt;br /&amp;gt;–SetActiveScene(vtkCollection*) - saves the state of the specified collection of nodes. &lt;br /&gt;
*SaveStateForUndo() should be called in GUI/Logic classes before changing the state of MRML nodes. This is usually done in the ProcessGUIEvents method that processes events from the user interactions with GUI widgets. &lt;br /&gt;
*SaveStateForUndo() should not be called while processing transient events such as continuous events sent by KW UI while dragging a slider (for example vtkKWScale::ScaleValueStartChangingEvent). &lt;br /&gt;
&lt;br /&gt;
The following methods on the MRML scene are used to manage Undo/Redo stacks:&lt;br /&gt;
&lt;br /&gt;
* vtkMRMLScene::Undo() – restore the previously saved state of the MRML scene.&lt;br /&gt;
* vtkMRMLScene::Redo() – restore the previously undone state of the MRML scene.&lt;br /&gt;
* vtkMRMLScene::SetUndoOff() – ignore following SaveStateForUndo calls (usefull when making multiple changes to the scene/nodes that does not need to be undone). &lt;br /&gt;
* vtkMRMLScene::SetUndoOn() – enable following SaveStateForUndo calls.&lt;br /&gt;
* vtkMRMLScene::ClearUndoStack() – clears the undo history.&lt;br /&gt;
* vtkMRMLScene::ClearRedoStack() – clears the redo history.&lt;br /&gt;
&lt;br /&gt;
= Other Useful References =&lt;br /&gt;
&lt;br /&gt;
== MRML API Documentation ==&lt;br /&gt;
&lt;br /&gt;
The detailed documentation of MRML API can be found in [http://slicer.org/doc/html/classes.html Slicer {{documentation/version}} Doxygen pages]&lt;br /&gt;
&lt;br /&gt;
== Slice view pipeline ==&lt;br /&gt;
&lt;br /&gt;
VTK/MRML pipeline for the 2D slice views: [[File:SliceView.pptx]].&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
&lt;br /&gt;
See Data Model notes in [http://wiki.na-mic.org/Wiki/index.php/AHM_2006:ProjectsSlicerDataModel AHM 2006 Programming week project].&lt;br /&gt;
&lt;br /&gt;
== Path-based MRML proposal ==&lt;br /&gt;
&lt;br /&gt;
Mike's proposal for a [[Slicer3:MRML3_Path|path-based MRML3 representation]], based on extending the Coordinate Space Manager ideas to the entire MRML3 tree&lt;br /&gt;
&lt;br /&gt;
== Slicer Daemon ==&lt;br /&gt;
&lt;br /&gt;
The goal of the [[Slicer3:Slicer_Daemon|Slicer Daemon]] project is to allow remote editing of the MRML data model by external programs over a socket.&lt;br /&gt;
&lt;br /&gt;
== EventBroker Discussion ==&lt;br /&gt;
&lt;br /&gt;
The [[Slicer3:EventBroker|Event Broker]] is a proposal to improve the way events are managed inside slicer.&lt;br /&gt;
&lt;br /&gt;
= Slicer 2.6 MRML =&lt;br /&gt;
&lt;br /&gt;
== Data Represented in MRML in Slicer 2.6 ==&lt;br /&gt;
&lt;br /&gt;
* Volumes&lt;br /&gt;
** IJK-&amp;gt;RAS (VTK-&amp;gt;RAS)&lt;br /&gt;
** Scalar Types&lt;br /&gt;
** Multicomponent (RGB, Displacement Vector)&lt;br /&gt;
** Tensor Volumes&lt;br /&gt;
** Label Maps&lt;br /&gt;
** Reference to Lookup Table&lt;br /&gt;
&lt;br /&gt;
* Models&lt;br /&gt;
** vtkPolyData&lt;br /&gt;
*** Named Field Data (scalars, vectors, labels) at points and cells (FreeSurferReaders)&lt;br /&gt;
*** Polylines with tensor point data (DTMRI Module)&lt;br /&gt;
** Color, Clipping State, Visibility, Scalar Visibility, LookupTable&lt;br /&gt;
&lt;br /&gt;
* Transforms&lt;br /&gt;
** Matrix4x4&lt;br /&gt;
&lt;br /&gt;
* Lookup Tables&lt;br /&gt;
** vtkLookupTable info&lt;br /&gt;
&lt;br /&gt;
* Fiducials&lt;br /&gt;
** Position, Quaternion&lt;br /&gt;
** Name, Selection State, Type (endoscopic, normal)&lt;br /&gt;
** Glyph Size, Text Size&lt;br /&gt;
&lt;br /&gt;
* Fiducial Lists&lt;br /&gt;
** Name, Slze, Color, Selection State&lt;br /&gt;
&lt;br /&gt;
* Colors&lt;br /&gt;
** Name, Label#, Diffuse/Ambient/Specular&lt;br /&gt;
&lt;br /&gt;
* Model Groups&lt;br /&gt;
&lt;br /&gt;
* Application State (not to be carried to Slicer3 MRML)&lt;br /&gt;
* Locator (not to be carried to Slicer3 MRML)&lt;br /&gt;
* Module Specific Parameters (not to be carried to Slicer3 MRML)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Operations On MRML Scene ==&lt;br /&gt;
&lt;br /&gt;
* Load from File&lt;br /&gt;
* Save to File&lt;br /&gt;
* Traverse Nodes in Tree&lt;br /&gt;
* Insert Node&lt;br /&gt;
* Delete Node&lt;br /&gt;
* Register Tree Observer&lt;br /&gt;
* Update MRML&lt;br /&gt;
* Get Transformations (e.g. IJK to World through transform tree)&lt;br /&gt;
&lt;br /&gt;
* Data Type Specific Operations&lt;br /&gt;
** Get/Set Node MetaData&lt;br /&gt;
** Get/Set Data (e.g. as vtkImageData)&lt;br /&gt;
&lt;br /&gt;
== General References on XML ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikibooks.org/wiki/XML:_Managing_Data_Exchange A wikibook on XML] &lt;br /&gt;
&lt;br /&gt;
The [http://en.wikibooks.org/wiki/XML:_Managing_Data_Exchange/The_many-to-many_relationship#ID.2FIDRE section on ID/IDREF implementations], which are similar to what we use in MRML.&lt;/div&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
</feed>