I was trying to display a color legend in some custom slice views when I noticed that it was not showing as I expected. Is there a certain set of conditions to make sure the color legend shows in the other non-standard slice views.
I start Slicer 5.2.1 (and latest Slicer Preview 5.3.0-2023-02-10), set layout to Four-Up, close Slicer, restart Slicer then run the below snippet
slicer.app.layoutManager().setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutThreeOverThreeView)
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
mrHead = sampleDataLogic.downloadMRHead()
color_legend_display_node = slicer.modules.colors.logic().AddDefaultColorLegendDisplayNode(mrHead)
color_legend_display_node.SetVisibility(True)
I observe the following where the color legend is showing in the Red/Yellow/Green slice views, but not in the Red+/Yellow+/Green+ slice views.
Then if I close Slicer so that it remembers the “Three over three” layout, relaunch Slicer and run the same script I observe the following where the color legend is showing in all the slice views as I would expect:
@Mik , since you did some of the recent color legend rework, do you know what is going on here?
Mik
(Mikhail Polkovnikov)
February 13, 2023, 12:25pm
3
Definitely a bug. SliceCompositeNode is invalid for a new slice views in color legend displayable manager.
For a fast fix:
Enable Toggle slice visibility in 3D view
in slice controller widget
or
Python script below
layoutManager = slicer.app.layoutManager()
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutThreeOverThreeView)
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
mrHead = sampleDataLogic.downloadMRHead()
for sliceViewName in layoutManager.sliceViewNames():
view = layoutManager.sliceWidget(sliceViewName).sliceView()
sliceNode = view.mrmlSliceNode()
sliceLogic = slicer.app.applicationLogic().GetSliceLogic(sliceNode)
sliceLogic.StartSliceNodeInteraction(slicer.vtkMRMLSliceNode.SliceVisibleFlag)
sliceNode.SetSliceVisible(True)
sliceLogic.EndSliceNodeInteraction()
color_legend_display_node = slicer.modules.colors.logic().AddDefaultColorLegendDisplayNode(mrHead)
color_legend_display_node.SetVisibility(True)
After that the color legends are visible and available for editing.
I hope it helps.
I assume then that this commit is likely the culprit for requiring slice visibility to be on?
Color legend is shown if color legend display is enabled for the volume, the vol… ume is shown in a slice view, and that slice view is visible in the 3D view.
Co-authored-by: Andras Lasso <lasso@queensu.ca>
Mik
(Mikhail Polkovnikov)
February 13, 2023, 2:21pm
5
Quite possible. I haven’t tested color legends with nonstandard slice views.
Issue now being tracked at:
opened 05:11PM - 13 Feb 23 UTC
type:bug
## Summary
As originally mentioned at https://discourse.slicer.org/t/issue-di… splaying-color-legend-in-other-slice-views/27784, the color legend display is not working as expected in some of the other slice views other than Red/Yellow/Green.
## Steps to reproduce
```python
# Start Slicer so that on startup it is the Four-Up Layout
slicer.app.layoutManager().setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutThreeOverThreeView)
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
mrHead = sampleDataLogic.downloadMRHead()
color_legend_display_node = slicer.modules.colors.logic().AddDefaultColorLegendDisplayNode(mrHead)
color_legend_display_node.SetVisibility(True)
```
If you start Slicer where it begins in the the Three-over-three layout, then the color legend display shows as expected. Something about the views on startup has some impact here.
## Expected behavior
The color legend display should turn on/off for the specified volume in all slice views that the volume is displayed in. It should not be tied to Slice visibility in 3D either.
## Current workaround
```python
slicer.app.layoutManager().setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutThreeOverThreeView)
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
mrHead = sampleDataLogic.downloadMRHead()
# Workaround - set slice view visibles before turning on color legend display
layoutManager = slicer.app.layoutManager()
for sliceViewName in layoutManager.sliceViewNames():
view = layoutManager.sliceWidget(sliceViewName).sliceView()
sliceNode = view.mrmlSliceNode()
sliceNode.SetSliceVisible(True)
color_legend_display_node = slicer.modules.colors.logic().AddDefaultColorLegendDisplayNode(mrHead)
color_legend_display_node.SetVisibility(True)
```
## Environment
- Slicer version: Slicer-5.3.0-2022-02-10 and Slicer 5.2.1.
- Operating system: Windows
lassoan
(Andras Lasso)
February 13, 2023, 5:49pm
7
@Mik It would be great if you could try to fix this. I’ve added a comment to the issue about potential approaches.
Mik
(Mikhail Polkovnikov)
February 24, 2023, 3:46pm
8
Fix is ready to review and tests.