Accessing Segmentation Layer Visibility By View

Hi All,

I’m curious if there is a way to show particular segmentation nodes on each of four different views in a two over two layout programmatically. An example of doing this for background volumes would be as follows:

volumes_of_interest = [pre_T1, pre_ADC, post_T1, post_ADC]

viewNodes = slicer.mrmlScene.getNodesByClass('vtkMRMLSliceCompositeNode')
for i,viewNode in enumerate(viewNodes):

        viewNode.SetBackgroundVolumeID(self.volumesLoad[i].GetID())

In our use case we make unique segmentations on two different MRI sequences before and after an intervention. Being able to view and touch-up all four segmentations would be helpful.

I understand that Segmentations play by different rules. I tried exploring SetDisplayVisibility, but it seems to only act globally on all views.

Any suggestions are much appreciated.

Best,

Brett

You can add multiple segmentation display nodes to have one for each view. Then set view node ID and visibility in each display node.

What do you mean by specifically by a segmentation display node?

In the API vtkMRMLDisplayableNode doesn’t seem have a view node ID attribute and vtkMRMLSegmentationNode doesn’t seem to have a visibility attribute.

http://apidocs.slicer.org/master/classvtkMRMLSegmentationDisplayNode.html

Create one using slicer.mrmlScene.AddNewNodeByClass and add it to the segmentation node using its AddAndObserveDisplayNodeID method.

These are display node methods.

Example:

# Get segmentation node, for the rest, we assume that there are 3 segments, with default names/ids
segmentationNode=getNode('Segmentation')

# Get display node that is used by default for all views
segmentationDisplayNode1=segmentationNode.GetDisplayNode()

# Add one more display node
segmentationDisplayNode2=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationDisplayNode')
segmentationNode.AddAndObserveDisplayNodeID(segmentationDisplayNode2.GetID())

# Display node 1: show only in Red slice view, show only segment 3
segmentationDisplayNode1.SetViewNodeIDs(['vtkMRMLSliceNodeRed'])
segmentationDisplayNode1.SetSegmentVisibility('Segment_1',False)
segmentationDisplayNode1.SetSegmentVisibility('Segment_2',False)

# Display node 2: show only in Yellow nad Green slice views, show only segment 1
segmentationDisplayNode2.SetViewNodeIDs(['vtkMRMLSliceNodeYellow', 'vtkMRMLSliceNodeGreen'])
segmentationDisplayNode2.SetSegmentVisibility('Segment_2',False)
segmentationDisplayNode2.SetSegmentVisibility('Segment_3',False)
1 Like

Hi Andras,

This is really helpful! Thanks so much for providing the examples.

I also found this DisplayNode method that similarly achieves only showing segmentations in select views.

segmentationDisplayNode = segmentNode.GetDisplayNode()    
sliceNode = 'vtkMRMLSliceNodeRed'
segmentationDisplayNode.SetDisplayableOnlyInView(sliceNode.GetID())
1 Like