Volumes module : GetActiveVolumeNode always returns the first node

While trying to get the selected node in the Volumes module,


does not seem to behave as expected.

If we load 2 scalar volumes, GetActiveVolumeNode().GetID() always returns ‘vtkMRMLScalarVolumeNode1’, even if the second loaded volume is selected (expecting then vtkMRMLScalarVolumeNode2).

I suppose it’s a bug that needs a fix, or I have a wrong understanding of the function.

Using 4.13.0-2021-05-09 r29893 / 824c6d8 home built on Arch Linux .


Good catch. We’ll remove this method, this is just a remnant of decade-old infrastructure that has been long removed, but apparently not completely.

Although there is an “active volume” stored in the selection node (slicer.app.applicationLogic().GetSelectionNode().GetActiveVolumeID(), which is set whenever a volume is loaded and propagated to be displayed in the viewers) it is not used for anything else (and therefore may be removed in the future), probably because it would be way too limiting to have only a single “active” volume in the scene.

What would you like to use an “active volume” for? What is your end goal?

The fundamental problem to overcome :
I need to load 512x512x2100+ DICOM volumes and view it with Volume Rendering. Zooming in some volumes reaches a too near limit. If the volume is centred, this limit is much farther. Unfortunately, I don’t have such a volume at hand to post as a sample. And even so, an anonymized DICOM volume is centred by default. So it’s not possible to demonstrate here.
N.B. I am using a recent and quite performing graphics adaptor (Radeon RX 6700 XT), so that’s not the bottleneck leading to the zooming limit.

The single step where I need a UI :
Get hold of a selected volume node in a module; it can be any module. I may also write a custom module with just a node selector and a button; it would be an overkill in my view.

So I thought of getting the active node in the Volumes module, and pass it to functions in slierrc.py via a keyboard shortcut. It would :

  • centre the volume
  • apply preferred window/level values
  • show the volume as background in slice views
  • fit the volume in the slice views
  • go to the Volume Rendering module
  • set the MRML volume node
  • show the node in the 3D view
  • apply a preferred preset

All these occur straightaway with a shortcut. I just saw that even if no volume node is active in the Volumes Module, GetActiveVolumeNode() returns the last loaded volume via ‘Add data’, and not volumes loaded via the DICOM module.

If there is no way of getting the active node in the Volumes module, I’ll end up writing an intermediate module and access it quickly via the toolbar.

Thanks for considering.

Another option could be a subject hierarchy plugin (such as this example). The user would right-click on the volume of interest in the Data module and select your custom action.

These actions are performed in recent Slicer Preview Releases when you drag-and-drop a volume from the Data module into a view (except setting window/level values, which are set when you load the volume). What is missing/inconsistent is that the volume is not centered in 3D view when you click the eye icon (it is centered in slice views but not in 3D) - I’ll fix this.

If you want to apply a custom operation to all volumes that you load then you can do this automatically whenever a volume is loaded.

If you want to do it for only certain volumes and there is no other input than the selected volume then you can register a right-click menu action in the subject hierarchy. You can also add a subject hierarchy plugin that takes ownership of all volumes (by returning high confidence value in canOwnSubjectHierarchyItem method) and implements a custom behavior for clicking the eye icon (by overriding setDisplayVisibility method). You can search in the Slicer’s source code for *SubjectHierarchyPlugin.py for examples.

You don’t need a module for either of these, you can just add them to the startup script.

If you need some additional input parameters then it is worth adding new scripted module with a simple GUI.

The right click menu in the Subject Hierarchy plugin would be most appropriate. I’ll dig through this ASAP.

Thanks for your input.