Trying to implement custom scalar volume node

Hi,

As I don’t fully understand how custom nodes should be written I describe my progress and probably if someone has an advice I would appreciate.

I’m working on custom node inherited from vtkMRMLScalarVolumeNode.

As an example I use vtkMRMLAstroVolumeNode. I’m able to display my node but it can’t be saved. When I click on Save button I can see my node in the table but in fact the node is not saved (the appropriate file is not created). I guess responsible for that is vtkMRMLCustomStorageNode?

Now I need to add some information to the node (for example the path to the file where the original data resides and the parameters that were applied when data was loaded) that should be seen in Data module -> Node information and also this should be saved when saving the scene (I guess using vtkMRMLDisplayableNode::WriteXML) and read when loading the scene. Is it ok if I add this data to the node Attributes?

To display this information I should reimplement PrintSelf() method (there should not be much problems)

To write/read I should reimplement WriteXML() and ReadXMLAttributes(). Is it the information about my node that should be written to the Scene.mrml file?

My custom node can be found there

Apparently PrintSelf(), WriteXML() and ReadXMLAttributes() are pretty simple to implement using vtkMRML macros. The task is solved.

The only thins has left to do is to save the binary (scalars) data from node.

To fix the issue with saving volume node inherited from vtkMRMLScalarNode I just needed my custom storage node to inherit from vtkMRMLVolumeArchetypeStorageNode instead of more general vtkMRMLStorageNode.

I’m able to save/load custom volumes now

2 Likes

Volume nodes are quite generic, so most likely you don’t need to create custom variants. If you want to save into a new file format then you need a custom storage node. For storing special display properties you can use custom node attributes in existing volume display node classes, but for some sophisticated features adding a new display node class might be necessary.

1 Like

Yes thank you, for now I just created custom scalar volume and added some information (attributes) that I write to XML file and PrintSelf.

I don’t need to use new file formats and thus I just inherited from VolumeStorage and VolumeDisplay nodes mostly to get experience of registering nodes, get known with read/write functions. I think this will help me to better understand Slicer. My custom storage node and display node works exactly the same way as regular volume storage and volume display nodes

It can be useful to create this custom node as a learning exercise. If you don’t end up needing anything else than storing custom attributes then you can revert to using a regular scalar volume node and use Get/Set Attribute. All custom attributes are stored in the scene.

1 Like

Have not thought that I can simply add attributes via set attribute, that probably would be enough.