Hi everyone!
I am trying to create a python scripted module using Sequences extension and I have an issue to modify the color of the models in a sequence: I would like to have different color for each model contained in the sequence created.
Here are the two codes that I tried:
First try: Change of the models’ colors before adding them to the sequence.
sequence = slicer.mrmlScene.AddNode(slicer.vtkMRMLSequenceNode())
sequencebrowser = slicer.mrmlScene.AddNode(slicer.vtkMRMLSequenceBrowserNode())
model0 = slicer.util.loadModel(“path/to/model0.vtk”,True)[1]
model1 = slicer.util.loadModel(“path/to/model1.vtk”,True)[1]
displayNode0 = model0.GetDisplayNode()
displayNode0.SetColor(1,0,0)
displayNode1 = model1.GetDisplayNode()
displayNode1.SetColor(1,1,0)
sequence.SetDataNodeAtValue(model0, “0”)
sequence.SetDataNodeAtValue(model1, “1”)
sequencebrowser.AddSynchronizedSequenceNodeID(sequence.GetID())
→ The models in the sequence stay gray: that’s probably due to the copy of the models in the sequence which didn’t copy the display nodes of the models.
Second try: Change of the models’ colors after adding them to the sequence.
sequence = slicer.mrmlScene.AddNode(slicer.vtkMRMLSequenceNode())
sequencebrowser = slicer.mrmlScene.AddNode(slicer.vtkMRMLSequenceBrowserNode())
model0 = slicer.util.loadModel(“path/to/model0.vtk”,True)[1]
model1 = slicer.util.loadModel(“path/to/model1.vtk”,True)[1]
model00 = sequence.SetDataNodeAtValue(model0, “0”)
model01 = sequence.SetDataNodeAtValue(model1, “1”)
displayNode0 = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelDisplayNode())
displayNode0.SetColor(1, 0, 0)
displayNode0.VisibilityOff()
displayNode1 = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelDisplayNode())
displayNode1.SetColor(1, 1, 0)
displayNode1.VisibilityOff()
model00.SetAndObserveDisplayNodeID(displayNode0.GetID())
model01.SetAndObserveDisplayNodeID(displayNode1.GetID())
model00.HideFromEditorsOn()
model01.HideFromEditorsOn()
slicer.mrmlScene.AddNode(model00)
slicer.mrmlScene.AddNode(model01)
sequencebrowser.AddSynchronizedSequenceNodeID(sequence.GetID())
I checked the existence of the display node in one of the model added to the sequence.
print sequence.GetDataNodeAtValue(“0”).GetDisplayNode()
vtkMRMLModelDisplayNode (0x1310b1600)
ID: vtkMRMLModelDisplayNode6
Debug: Off
Modified Time: 877045
Name: ModelDisplay_2
Description: (none)
SingletonTag: (none)
HideFromEditors: 1
Selectable: 1
Selected: 0
Indent: 0
Color: 0x1310b1848
SelectedColor: 0x1310b1878
SelectedAmbient: 0.4
SelectedSpecular: 0.5
Opacity: 1
Ambient: 0
Diffuse: 1
Specular: 0
Power: 1
Visibility: 1
ScalarVisibility: 0
VectorVisibility: 0
TensorVisibility: 0
InterpolateTexture:0
ScalarRangeFlag: 2
AutoScalarRange: 1
BackfaceCulling: 1
Clipping: 0
SliceIntersectionVisibility: 0
SliceIntersectionThickness: 1
ScalarRange: 0, 1
ColorNodeID: (none)
ActiveScalarName: (none)
print sequence.GetDataNodeAtValue(“0”).GetDisplayNode().GetColor()
(1.0, 0.0, 0.0)
→ Even if it seems that the display nodes exist, the models in the sequence also stay gray.
Do you have any idea of what is wrong? Any help will be appreciated! Thanks in advance!
Laura