What class of object is responsible for visibility of display nodes when i click on visibility icon in subject hierarchy node browser?
What is the role of SubjectHierarchy plugin in selecting what display node will be displayed if there are many display node observed by a single scalar volume or model?
I try to add support for color bars, and after adding color bar display node to volume or model the behavior becomes very strange and possibly buggy.
Example for vtkMRMLScalarVolumeNode adds color bar display node, so volume node will have two display nodes (vtkMRMLScalarVolumeDisplayNode with index 0 and vtkMRMLColorBarDisplayNode with index 1), but when i click in subject hierarchy visibility icon the color bar display node is ignored and a volume rendering display node is added and i can see a volume rendering on a 3D view. A list nodes is subject hierarchy node also shows that a volume rendering display node was added.
// Create color bar and observe color bar by displayable node
vtkMRMLColorBarDisplayNode* colorBarNode = vtkMRMLColorBarDisplayNode::SafeDownCast(mrmlScene->AddNewNodeByClass("vtkMRMLColorBarDisplayNode"));
if (colorBarNode)
{
colorBarNode->SetVisibility(true);
dispNode->AddAndObserveDisplayNodeID(colorBarNode->GetID());
return colorBarNode;
}
Color bar for scalar volume by means of display node
Thank you for your efforts on this. You have arrived to some intricate details that are indeed not easy to figure out.
The click is processed by the showVolumeInAllViews method of the subject hierarchy plugin that owns the associated data node. For volumes, it is the qSlicerSubjectHierarchyVolumesPlugin.
Most of Slicer’s GUI only modifies the first display node of each displayable node. Volume node is an exception, because it often has multiple display nodes (one for slice display in 2D and 3D views; and another one for volume rendering in 3D views). qSlicerSubjectHierarchyVolumesPlugin handles the eye button clicks (which toggles visibility of all display nodes), but qSlicerSubjectHierarchyVolumeRenderingPlugin plugin adds some more visibility menu items (“Show in 3D views as volume rendering”, “Volume rendering options”) and the volumes plugin calls the volume rendering plugin to handle showing of the item in 3D views.
Volume rendering gets enabled because before your changes, if a display node was added for a volume that was not a vtkMRMLVolumeDisplayNode, it meant that it was a volume rendering display node. So, this condition was correct. However, now that we can have color bar display nodes, this logic is not correct anymore. You can fix it by implementing these:
Change vtkMRMLVolumeDisplayNode::SafeDownCast(displayNode) to !displayNode->IsA("vtkMRMLVolumeRenderingDisplayNode") so that the volume rendering plugin’s showItemInView is only called if there is already a vtkMRMLVolumeRenderingDisplayNode.
Add a section below that is very similar to the volume rendering, but it manages display of the scalar bar for the volume, by delegating the task to the qSlicerSubjectHierarchyScalarBarPlugin’s showItemInView method. If you haven’t added a qSlicerSubjectHierarchyScalarBarPlugin then you need to add it now. It should be relatively easy to create a new subject hierarchy plugin (you can start with copying and modifying Modules\Loadable\VolumeRendering\SubjectHierarchyPlugins) and this plugin is useful anyway, for example it can add menu options to quickly show/hide scalar bar; or control basic display properties of the scalar bar.
I will add the modifications for volumes and volume rendering.
Much more problem is adding a color bar display node to a model. The application is just crash if i add color bar to visible model. I will try to debug the cause of it. It could be subject hierarchy plugin, some widget in models module or even model displayable manager.