# Event when node visibility is changed

**URL:** https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013
**Category:** Development
**Created:** [December 11, 2021, 2:41am UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013 "2021-12-11T02:41:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [December 11, 2021, 2:41am UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/1 "2021-12-11T02:41:29Z")

</div>

Hi,

Can’t find an event that is triggered when node visibility is changed. Does `vtkMRMLDisplayableNode` triggers such event?

---

<div class="post-metadata">

### Author: ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)
#### Post date: [December 11, 2021, 3:59am UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/2 "2021-12-11T03:59:22Z")

</div>

The vtkCommand::ModifiedEvent is envoked when you change visibility of a corresponding [display node](http://apidocs.slicer.org/master/classvtkMRMLDisplayNode.html).

For example

```auto
vtkMRMLDisplayNode* dispNode = scalarVolumeNode->GetDisplayNode(); // get vtkMRMLScalarVolumeDisplayNode
if (dispNode)
{
  dispNode->VisibilityOff();
  // do some work
  dispNode->VisibilityOn();
}

```

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [December 11, 2021, 2:28pm UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/3 "2021-12-11T14:28:53Z")

</div>

Thank you for the help, I didn’t know that.

I guess if displayable node doesn’t have the display node then I can’t add an observer watches the visibility of my displayable node?

I just tried as you proposed and it seems that `displayableNode->GetDisplayNode();` sometimes returns `nullptr` even if the `displayableNode` is on the scene and it is shown (as in my case).

---

<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: [December 11, 2021, 3:25pm UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/4 "2021-12-11T15:25:21Z")

</div>

> [@keri](#):
>
> I just tried as you proposed and it seems that `displayableNode->GetDisplayNode();` sometimes returns `nullptr` even if the `displayableNode` is on the scene and it is shown (as in my case).

A node cannot be displayed without a display node. It will not appear in any views.

> [@keri](#):
>
> Can’t find an event that is triggered when node visibility is changed. Does `vtkMRMLDisplayableNode` triggers such event?

You can observe the [vtkMRMLDisplayableNode::DisplayModifiedEvent](http://apidocs.slicer.org/master/classvtkMRMLDisplayableNode.html#a3b90d8fb984ac35e8ac919d6371a1ca1a8482bd3445607cf6ec6590466edd5436) of the displayable node to get notified about display property changes (when a display node is added or modified).

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [December 11, 2021, 8:57pm UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/5 "2021-12-11T20:57:19Z")

</div>

thank you, `vtkMRMLDisplayableNode::DisplayModifiedEvent` works fine for me

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [December 25, 2021, 2:14am UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/6 "2021-12-25T02:14:51Z")

</div>

I just figured out that if I try to `vtkMRMLScalarVolumeNode::SetDisplayVisibility(0)` (from both Python and C++) I’m still able to see that volume node is displayed in 3D view and in Slice views.

Is there something special with scalar volume nodes? Or how can I manage the visibility of volume nodes?

---

<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: [December 29, 2021, 4:36am UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/7 "2021-12-29T04:36:20Z")

</div>

Yes, volumes are a special case for historic reasons based on common uses and hardware/software limitations. Slice views are handled by slice composite nodes (background and foreground cross-fading only) and 3D view is based on volume rendering nodes (only one could be visible at a time). We might generalize this in the future and make volumes more like other displayables.

---

<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: [January 2, 2022, 2:06am UTC](https://discourse.slicer.org/t/event-when-node-visibility-is-changed/21013/8 "2022-01-02T02:06:49Z")

</div>

I would just add that recent Slicer Preview Releases can render any number of volumes in 3D views. For correct 3D compositing you need to [choose the experimental “VTK Multi-Volume” rendering method](https://slicer.readthedocs.io/en/latest/user_guide/modules/volumerendering.html#panels-and-their-use).
