# Intuitive volume presets

**URL:** <https://discourse.slicer.org/t/intuitive-volume-presets/20227>\
**Category:** Development\
**Created:** [October 19, 2021, 10:24am UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227 "2021-10-19T10:24:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 19, 2021, 10:24am UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/1 "2021-10-19T10:24:49Z")

</div>

Following [Make volume presets more accessible · Issue #5951 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/issues/5951)

I implemented the following solution using the right click menu of the slice views:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/a/aa7feb4942727abed0ddcb0c912625993b5179ca.jpeg)

Is this something you consider useful? If yes I would need to implement the logic and have some questions.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 19, 2021, 6:31pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/2 "2021-10-19T18:31:09Z")

</div>

That does look very handy. Perhaps it should be a pull-aside submenu to save space, which is pretty easy to do with a context menu.

---

<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:** [October 19, 2021, 7:20pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/3 "2021-10-19T19:20:18Z")

</div>

I second that request. In fact would be an expansion of the Adjust Window/Level, perhaps?

---

<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:** [October 20, 2021, 5:13am UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/4 "2021-10-20T05:13:49Z")

</div>

Very nice, thanks for working on this.

> [@pieper](#):
>
> Perhaps it should be a pull-aside submenu to save space, which is pretty easy to do with a context menu.

Fully agree that would have been my first suggestion, too.

> [@muratmaga](#):
>
> I second that request. In fact would be an expansion of the Adjust Window/Level, perhaps?

It could make sense to add it there, but unfortunately Qt does not allow making checkable an action that has a submenu (that’s why we have “Interaction” checkable action and “Interaction options” submenu in two separate items).

One more thing that would be really cool would be to grab the current foreground/background image from the slice view, and create small icons with the window/level value applied. Rendering the images could take maybe a tenth of a second, so you could do it when the user clicked on the submenu (on [aboutToShow](https://doc.qt.io/qt-5/qmenu.html#aboutToShow) signal). You could also make these icons bigger than the default menu icons (maybe 2x larger) so that details can be seen better.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 20, 2021, 8:22am UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/5 "2021-10-20T08:22:54Z")

</div>

Thank you all for the feedback.  
I´ll try to implement a pull-aside submenu and maybe Icons (a really cool idea) later.  
What would be the best practice to involve the actual setPreset() action?  
There is a

```auto
void qSlicerScalarVolumeDisplayWidget::setPreset(const QString& presetName)

```

in the Volumes module, should I use that and how could I call it from

```auto
qSlicerSubjectHierarchyViewContextMenuPlugin

```

?  
Thank you.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 21, 2021, 10:53am UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/6 "2021-10-21T10:53:39Z")

</div>

This is the prototype for a pull-aside submenu:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/b/2b1ec2bd45c34b50e493150a509c99f933e32a69.png)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 21, 2021, 12:13pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/7 "2021-10-21T12:13:59Z")

</div>

Nice 👍

Maybe the menu text could be “Window/level presets” to better match the wording above.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 21, 2021, 1:40pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/8 "2021-10-21T13:40:58Z")

</div>

Ok will do that, but would need a hint on how to actually set the levels from the SLOT function. Should this be done via the Volumes module? I found out how to get a pointer to the “Volumes” module in C++, but did not find suitable “Volumes” methods to invoke.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 21, 2021, 1:59pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/9 "2021-10-21T13:59:39Z")

</div>

Unfortunately that feature is [hard-coded](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Volumes/Widgets/qSlicerScalarVolumeDisplayWidget.cxx#L406-L476) in the GUI currently. Best would be to re-factor this feature so it can be re-used, ideally with the option for modules/extensions to register presets like we do for color tables and volume rendering. Simplest would be to move the guts of the method linked above into `vtkSlicerVolumesLogic` but there could be other options too (e.g. put it into mrml volume display nodes).

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 21, 2021, 2:49pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/10 "2021-10-21T14:49:04Z")

</div>

> [@pieper](#):
>
> move the guts of the method linked above into `vtkSlicerVolumesLogic`

Thanks Steve, will try that.

---

<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:** [October 21, 2021, 8:12pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/11 "2021-10-21T20:12:06Z")

</div>

> [@pieper](#):
>
> Best would be to re-factor this feature so it can be re-used, ideally with the option for modules/extensions to register presets like we do for color tables and volume rendering. Simplest would be to move the guts of the method linked above into `vtkSlicerVolumesLogic`

Agreed. Maintaining the list in the Volumes module logic would be a great. For now, the presets can be hardcoded in the logic and we can add API to register new presets later.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [October 22, 2021, 8:56pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/12 "2021-10-22T20:56:51Z")

</div>

I am slowly getting there.  
My main problems are today: How to get a reference to the ScalarVolumeNode loaded in one of the slices and how to detect they are grayscale, because I would not want to offer the color presets in this case.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 22, 2021, 9:08pm UTC](https://discourse.slicer.org/t/intuitive-volume-presets/20227/13 "2021-10-22T21:08:19Z")

</div>

Since you know which sliceView the menu is on you can use the `sliceWidget`'s `sliceLogic()` method and then you can get the vtkMRMLSlicerCompositeNode [from the `sliceLogic`](https://apidocs.slicer.org/master/classvtkMRMLSliceLogic.html#ab4dfadf75a3b378c8e46c09ab68cfbbc) and that has the IDs of the nodes for the layers. You can then use the IDs to get the nodes from the scene and use their `IsA` methods to check what class they are and only put up the menu items if they are in valid classes.
