Get the current volume node rendered in the Red Yellow Green view

Hello

I’m trying to get the current volume rendered in the RYG views (from a Dicom).
On the screen, i have 2 volume:

image

For now, i already got all the vtkMRMLScalarVolumeNode in a VtkCollection, but i cannot find a way to get witch one is visible on the RYG.
Since we cannot set visible multiple volumes, i try a basic solution:

#currentNode is a vtkMRMLScalarVolumeNode
currentNode.GetScalarVolumeDisplayNode().GetDisplayableNode().GetDisplayVisibility()

I expected this to return “1” for the volume rendered in the scene, 0 for all others, but it always return 1.

Does anyone have a solution ?

Hi, you can use this to set a volume as background
slicer.util.setSliceViewerLayers(background=currentNode)
Edit: i misread you want to get the displayed one

Hi,

This is not what i want
The result expected is something like (pseudo code)
currentNodeRenderedInTheRYGViews = slicer.util.getFocusedVolume()

or

for all scalarVolumeNode
  if(node.isDisplayed)
    return node

For now i just got the list of all scalarVolumes (red circle on the screen), but only one of them is displayed in these view, the one i want.

“Edit” Yes, that’s it :wink:

See this example in the script repository for how to get/set foreground and background volume node in each slice view (you just need to replace Set…Volume… by Get…Volume…):

layoutManager = slicer.app.layoutManager()
for sliceViewName in layoutManager.sliceViewNames():
    compositeNode = layoutManager.sliceWidget(sliceViewName).sliceLogic().GetSliceCompositeNode()
    volumeNodeID = compositeNode.GetBackgroundVolumeID()
    print(sliceViewName + ": " +volumeNodeID)

That’s totally what i wanted to do !
I didn’t know that was called “background”, so i dont paid attention to it

Thanks for your help lassoan

1 Like