I would like to automatically enable Maximum Intensity Projection (MIP) when switching to the MyPreset2 preset.
Do I need to add a ViewNode, a VolumeRenderingDisplayNode, or some other configuration in the MRML file? If not, what is the best way to associate MIP with specific presets?
It would make more sense to include raycast technique in the volume rendering preset. I’ve added an issue to track this task. But to reduce API churn, we probably will not change this until we need to make other significant changes/improvements to rendering presets. A grant proposal was submitted for improving volume rendering presets, so if it is successful (or if other funding sources come in) then this will all be implemented.
Thank you @lassoan for the clarification and for adding this to the issue tracker.
I plan to implement a workaround using a Python function onPresetChanged in my module within my extension. The function would trigger when the preset changes, allowing me to manually set the raycast technique for specific presets. For example:
def onPresetChanged(presetName):
if presetName == "MyPreset2":
# Switch views to MIP mode
for viewNode in slicer.util.getNodesByClass("vtkMRMLViewNode"):
viewNode.SetRaycastTechnique(slicer.vtkMRMLViewNode.MaximumIntensityProjection)
Is there a way to integrate such a function so that it is automatically triggered when a preset is changed?
is not working in my case. The presetComboBox is returning None, so it seems the PresetComboBox is either not found or not available in my setup.
I’ve tried listing all child objects under slicer.util.mainWindow() but couldn’t locate it there. Could it be named differently or located somewhere else, like within the Volume Rendering module widget? Any additional pointers would be appreciated!
Thank you for the help! I managed to get it working with this approach:
def OnPresetChanged(ID: str):
"""Automatically switch to MIP when a preset is changed."""
vrLogic = slicer.modules.volumerendering.logic()
presetsScene = vrLogic.GetPresetsScene()
vrNodes = presetsScene.GetNodesByClass("vtkMRMLVolumePropertyNode")
for i in range(vrNodes.GetNumberOfItems()):
node = vrNodes.GetItemAsObject(i)
if node.GetID() == ID:
raycastTechnique = "Max" if node.GetName().lower().endswith("max") else "Composite"
SetRaycastTechnique(raycastTechnique)
break
w = slicer.util.getModuleWidget("VolumeRendering")
presetComboBox = w.findChild(slicer.qSlicerVolumeRenderingPresetComboBox, "PresetComboBox")
presetComboBox.connect("currentNodeIDChanged(QString)", OnPresetChanged)
I made sure that the presets I want to activate MIP for have “Max” at the end of their names. This works well, but I’m sure there’s a cleaner or more efficient way to achieve this. Let me know if you have any suggestions!