# Accessing Segmentation Layer Visibility By View

**URL:** <https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [December 16, 2018, 3:31am UTC](https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090 "2018-12-16T03:31:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [December 16, 2018, 3:31am UTC](https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090/1 "2018-12-16T03:31:10Z")

</div>

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

---

<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 16, 2018, 1:56pm UTC](https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090/2 "2018-12-16T13:56:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [December 16, 2018, 2:52pm UTC](https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090/3 "2018-12-16T14:52:30Z")

</div>

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.

---

<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 16, 2018, 3:11pm UTC](https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090/4 "2018-12-16T15:11:05Z")

</div>

> [@bsmarine](#):
>
> What do you mean by specifically by a segmentation display node

[http://apidocs.slicer.org/master/classvtkMRMLSegmentationDisplayNode.html](http://apidocs.slicer.org/master/classvtkMRMLSegmentationDisplayNode.html)

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

> [@bsmarine](#):
>
> In the API vtkMRMLDisplayableNode doesn’t seem have a view node ID attribute and vtkMRMLSegmentationNode doesn’t seem to have a visibility attribute.

These are display node methods.

Example:

```auto
# 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)

```

---

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [December 26, 2018, 4:35am UTC](https://discourse.slicer.org/t/accessing-segmentation-layer-visibility-by-view/5090/5 "2018-12-26T04:35:46Z")

</div>

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())
```
