We have implemented MRML as a set of VTK
classes. There is a vtkMrmlNode
class, which is the superclass of specific types
of nodes, such as vtkMrmlVolumeNode
. There is a vtkMrmlTree
class, derived from
vtkCollection
, to be a collection of MRML nodes. This tree class contains member
functions for traversing the tree, adding and deleting nodes, and writing the
entire scene as a MRML file. This is achieved by calling the Write()
member function
of each node. (There should also be a Read()
function, but we currently have the
parsing implemented in Tcl, since that's so easy.)
Here is an example of creating and writing a MRML tree:
#Construct MRML nodes after parsing the file
vtkMrmlVolumeNode skin
skin SetName Skin
skin SetPrefix models/Skin.vtk
skin SetOpacity 0.7
skin SetColor Tan
vtkMrmlColorNode tan
tan SetName Tan
tan SetDiffuseColor 1.0 0.8 0.7
# Construct tree
vtkMrmlTree tree
tree AddNode model
tree AddNode tan
# Traverse tree
tree InitTraversal
set node [tree GetNextItem]
while {$node != ""} {
puts "name='[$node GetName]'"
set node [tree GetNextItem]
}
# Write MRML file
tree Write "scene.xml"
To assist developers who would like to use MRML, we offer our Tcl parser and VTK classes.