Refresh volume rendering

Hi developpers,

I am writing a scripted module with python to hide the volume and only display slices into the 3d view using following functions :
red = slicer.util.getNode(‘vtkMRMLSliceNodeRed’)

volRenLogic = slicer.modules.volumerendering.logic()
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode)

ROI_node = displayNode.GetROINode()

It is working but the result is not automatically updated. I need to change the zoom or translate the volume to update the view. Do you know how avoid that in python ?
Thank you !

Display is only updated when your python script execution is completed. If you want to enforce re-rendering of views while a script is running, call slicer.util.forceRenderAllViews().

Thank you for your answer.
I have the following error :
AttributeError: ‘module’ object has no attribute ‘forceRenderAllViews’

I downloaded the last release version. The function is now avalaible.
Nevertheless the problem is still here.
If I first hide the 3D volume, then try to display it using the previous functions, only the ROI is displayed and I need to click on the 3D viewand move the mouse to update the volume display.

Could you provide a code snippet that reproduces the issue from an empty scene? (downloads a sample data set, sets up visualization, etc. - you can find examples to start from in the script repository)

Hello, I found a solution updating the display like that :

viewNode = slicer.util.getNode(‘View1’)

Thank you

Hello all,
I though my problem was solved but I have a quite similar problem :

I am changing the zoom and position of the camera using “camera.Dolly” and “camera.SetPosition” functions but the 3D view is not automatically updated (only the background is displayed).
The volume is only displayed when I click and move the mouse on the “View1” screen

Do you know how can I avoid it ?


You can use MRML interface of the camera (get the camera node and adjust position, focal point, etc.), which works as you expect.

If you go one level lower and manipulate VTK rendering objects directly, then you need to do all the necessary steps at that level, including resetting camera clipping planes, when you change the camera position. For example, this works for me:

# Load some sample data and show it using volume rendering
import SampleData
volumeNode = SampleData.SampleDataLogic().downloadMRHead()
volRenLogic = slicer.modules.volumerendering.logic()
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode)

# Get camera node
view =
threeDViewNode = view.mrmlViewNode()
cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDViewNode)

# Move camera using low-level VTK interface

Thank you so much, the ResetClippingRange() function was missing.

1 Like