Event when node visibility is changed

Hi,

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

The vtkCommand::ModifiedEvent is envoked when you change visibility of a corresponding display node.

For example

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

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).

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

You can observe the vtkMRMLDisplayableNode::DisplayModifiedEvent of the displayable node to get notified about display property changes (when a display node is added or modified).

1 Like

thank you, vtkMRMLDisplayableNode::DisplayModifiedEvent works fine for me

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?

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.

2 Likes

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.

1 Like