Adjusting "Shift" Volume Rendering Display using Python

Hi,

I am trying to visualize a volume using Python and volume rendering.
When I render the volume, it is rather dark. I know I can solve this by moving the “Shift” bar under Display in Volume Rendering. Now I tried doing this by using Python, and I used the following code:

volRenLogic = slicer.modules.volumerendering.logic()
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(node)
layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)
threeDView = threeDWidget.threeDView()
threeDView.resetFocalPoint()

volRenWidget = slicer.modules.volumerendering.widgetRepresentation()
volumePropertyNode = displayNode.GetVolumePropertyNode()

volumePropertyNodeWidget = slicer.util.findChild(volRenWidget, ‘VolumePropertyNodeWidget’)
volumePropertyNodeWidget.setMRMLVolumePropertyNode(volumePropertyNode)
volumePropertyNodeWidget.moveAllPoints(x, 0, false)

It does visualize the volume (which is a CT scan), but when I try to apply the shift change, no visible changes are applied to the visualized volume. It does not matter what i fill in at x, but nothing seems to work, I do not get any Error messages either, it just straight up does not show the changes I made. I have tried searching these forums for a suitable answer, but i did not find anything that would completely solve this issue, and I hope anyone can help me out on this.

I would also be interested to learn how to do this programmatically, and similarly, centre the volume rendering (as you would with the crosshair icon in the UI).

Here is how you center the 3D view programmatically: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#center-the-3d-view-on-the-scene

1 Like

Thanks Mike, that solves the centring problem!