Change image without changing zoom and positions of sliders

I have a scripted module that looks like this.


In the example shown, the user has zoomed in on both the red and the yellow slices, and the red & yellow slice slider positions are off center.
The user is about to display a different image by choosing that image from the dropdown menu. Image selection from the dropdown menu prompts my scripted module to call
slicer.util.setSliceViewerLayers(background=self.inputSelector.currentNodeID)
so that the image chosen by the user will be displayed. However, it appears that this line of code automatically resets the zoom and slice slider positions to their default values.
Is there any way I can call
slicer.util.setSliceViewerLayers(background=self.inputSelector.currentNodeID)
without resetting zoom and slider positions, so that the user doesn’t lose track of the region they have zoomed into whenever they switch images?

Thanks,
Rohan

I’m not completely sure that this doesn’t change any other setting, but as far as I remember it doesn’t.

sliceCompositeNodes = slicer.util.getNodesByClass('vtkMRMLSliceCompositeNode')
for sliceCompositeNode in sliceCompositeNodes:
  sliceCompositeNode.SetBackgroundVolumeID(newVolumeNode.GetID())

Thank you, this way of switching image displayed does what I need.

1 Like