# Registering a volume rendering default presets automatically

**URL:** <https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964>\
**Category:** Support\
**Created:** [November 22, 2023, 5:59pm UTC](https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964 "2023-11-22T17:59:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [November 22, 2023, 5:59pm UTC](https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964/1 "2023-11-22T17:59:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 22, 2023, 7:41pm UTC](https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964/2 "2023-11-22T19:41:45Z")

</div>

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](https://discourse.slicer.org/t/hanging-protocol-for-displaying-pet-ct-images/28598#!), 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:

> [@Hanging protocol for displaying PET/CT images](https://discourse.slicer.org/t/hanging-protocol-for-displaying-pet-ct-images/28598#):
>
> Is is possible to add on a feature that saves a user’s preferred modality-specific viewing settings. I view PET/CT images regularly and it would be great to be able to have my view settings saved so I’m always viewing PET with PET-Heat in 0-20SUV, then CT in CT Abdomen Window without having to adjust this every single time I load a new case. Having custom view settings for a given user where it loads up the same way each time would be great!

---

<div class="post-metadata">

**Author:** ![smrolfe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/smrolfe/32/3659_2.png) [@smrolfe](https://discourse.slicer.org/u/smrolfe)\
**Post date:** [November 29, 2023, 8:35pm UTC](https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964/3 "2023-11-29T20:35:55Z")

</div>

> [@lassoan](#):
>
> 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.

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?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [November 29, 2023, 9:01pm UTC](https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964/4 "2023-11-29T21:01:32Z")

</div>

Hi

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

Hope it helps

---

<div class="post-metadata">

**Author:** ![smrolfe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/smrolfe/32/3659_2.png) [@smrolfe](https://discourse.slicer.org/u/smrolfe)\
**Post date:** [November 29, 2023, 9:28pm UTC](https://discourse.slicer.org/t/registering-a-volume-rendering-default-presets-automatically/32964/5 "2023-11-29T21:28:29Z")

</div>

> [@mau\_igna\_06](#):
>
> Did you try a QTimer with a lambda?

Works perfectly, thanks @mau_igna_06!
