SetColor() in scripting lost all light reflection effect

Whenever I set up color using modelNode.GetDisplayNode().SetColor() in Slicer Pytho console or a python script, the model appeared to lose all the light reflection and material effects.

If I just click the color table, and “OK” to select the same select, the color then became normal.

Did I miss anything in setting the color? Thanks!

You should use the more specific rendering-related fields like diffuse color, specular color etc.

1 Like

I went through all the settings, including SetShading(), SetDiffuse, SetSpecular, SetAmbient, and SetLighting, but none of it worked.

Interestingly, when I used SetColor directly in a function in the logic() class, the shading and lighting effects displayed normally.

SetColor is supposed to only change the color, and not the lighting properties. I just tried and it works as expected, so something is different on your side. What Slicer version do you use? What extensions are installed? If you use custom code, what does it do? Do you get any errors/warnings in the log? And whatever information you consider useful…

It looks like you have called SetColor(0, 0, 255) instead of the correct SetColor(0, 0, 1).

VTK (and therefore Slicer) specifies color and opacity components uses floating point numbers between 0 and 1 to . It is sometimes useful to be able to set color intensity slightly above 100%, but 25500% is way too high, threfore all that you see is the flat ambient color. When you interact with the GUI, it normalizes the value ranges between 0-100%, that’s why after that everything looks normal again.

2 Likes

@cpinter @lassoan

Yes, I did do SetColor(0, 0, 255). Sorry I did not describe my issue clearly. I did not realize that was the problem. SetColor() with value between 0 to 1 solved my problem. Thanks!