Registering a volume rendering default presets automatically

We have a diceCT preset in SlicerMorph for our contrast-enhanced microCTs of mouse embryos. I would like this preset to be automatically applied to volumes I drag into 3D viewer, like it currently does for MRHead (it chooses the MRI preset, without me specifying).

How can I accomplish this?

Simplest, not very clean solution: add an observer to the scene for node added events, whenever volume rendering display node is added then check if it belongs to your contrast-enhanced microCT type and if yes then change the preset.

Nicer solution: Add a subject hierarchy plugin that recognizes your “contrast-enhanced microCT” volume type (from value range, spacing value, etc. or any other attributes that the importer may set on the volume) and override the showItemInView method (e.g., call the default one but then change the volume rendering preset to your preferred one). It would take just a few ten lines of Python code, but unfortunately it seems that currently showItemInView is not Python-wrapped, so you would need to write the plugin in C++. It would be easy to add Python wrapping to showItemInView, and this design would be quite flexible and would also allow you to specify custom icon, context menu items, etc. for this type of volumes.

Another approach could be to change vtkSlicerVolumeRenderingLogic::SetRecommendedVolumeRenderingProperties to check the node attributes and if it finds a certain attribute (e.g., DefaultVolumeRenderingPreset) then use that as default preset for volume rendering. The attribute could be set by the importer or could be added in a callback function that is called whenever a new node is added to the scene.

Maybe the best solution would be to implement hanging protocols, where not just the volume rendering preset but view layout, window/level preset, etc. would be set up based on the type of the loaded data. For example, you could define a “Contrast-enhanced microCT” protocol that would be offered automatically when the input data matches requirements specified in the protocol. See more information here:

1 Like

I gave this a quick try, but at the time the volume rendering display node is added to the scene, the displayable node has not been assigned. Is there another way to get the associated node, or an event I could catch by monitoring the volume rendering display node?


Did you try a QTimer with a lambda? This may delay the execution of your code enough for your use case

Hope it helps

1 Like

Works perfectly, thanks @mau_igna_06!

1 Like