Display Colour Legend for Surface

Hello,

I’m working on an extension (in python) where I have a surface mesh with attributes that I’m colouring the mesh based on attribute value. I would like to add a colour bar/legend programmatically with the values corresponding to my colours.
Something similar to this: Change Color map and add color scale
Except through the colours module I can only seem to create a colour map for my foreground/background images and not for my vtkMRMLModelNode object.

First time posting, so I hope I’m providing sufficient detail - thanks in advance for any support!
Connor

For displayed model node you can use “Models” module with “Scalars” and “Color Legend” sub-sections.

image

Major features of “Color Legend” is described here:

2 Likes

If you want to display color legend to a model node then this should be sufficient:

slicer.modules.colors.logic().AddDefaultColorLegendDisplayNode(modelNode)

You can find a complete example of displaying a model node with a custom colormap and a color legend in the script repository.

2 Likes

Thank you for the help. Unfortunately I keep getting the error, even when following the full example you posted:

Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘vtkSlicerColorsModuleLogicPython.vtkSlicerColorLog’ object has no attribute ‘AddDefaultColorLegendDisplayNode’

I am running the last stable release of Slicer (4.11), do I need to be running 4.13? To make sure it wasn’t just my modelNode doing something weird, I tried this with a simple PET dataset and got the same error.

Any suggestions?

Yes, you need to use the latest Slicer Preview Release. This feature has been added recently.

1 Like