<div dir="ltr"><div>Apologies for the long e-mail but this particular code change submitted for</div><div> review does entail a change to vtkObject.h. Hence the need for all you</div><div> developers to be comfortable with such a change. Alternatively you may be</div>
<div> able to suggest a better method of achieving this.</div><div><br></div><div>There has been a request to have the ability to directly set colors using color</div><div> names in vtkLookupTable and other classes. I must admit that after working on</div>
<div> converting lots of TCL to Python tests, I felt the need for it too!</div><div><br></div><div>The current ways of setting colors by names are exemplified by:</div><div>TestNamedColorsIntegration.cxx</div><div>TestNamedColorsIntegration.py</div>
<div>These work but are not very elegant.</div><div><br></div><div>In order to overcome these limitations and make setting of colors more</div><div> intuitive for users, I have put the following up for review:</div><div><br>
</div><div> <a href="http://review.source.kitware.com/11412">http://review.source.kitware.com/11412</a></div><div><br></div><div>Once again thanks to David Thompson for suggesting this approach.</div><div><br></div><div>This approach does require a change to vtkObject.h, by introducing a function:</div>
<div> virtual void SetProperty1(vtkVariantArray*)</div><div>The upside of this is that, because it has a variant array as a parameter, there</div><div> will be other uses for this function in the future, most probably setting</div>
<div> parameters in a similar fashion to what has been done here.</div><div><br></div><div>The rationale for this implementation is as follows:</div><div><br></div><div>VTK uses a single inheritance model and is modularized so the logical thing is</div>
<div> to introduce a virtual SetProperty1 function, implement it in the</div><div> appropriate classes e.g. vtkLookUpTable and call this from vtkNamedColors.</div><div><br></div><div>This would mean that in our code we can do things like:</div>
<div>nc.SetColor(lut,"TableValue",1,"DarkGreen");</div><div>which under the hood implements:</div><div>lut->SetTableValue(1,0,1,0,1);</div><div><br></div><div>You can see implementations in:</div><div>
TestSetColorsByName.cxx</div><div>TestSetColorsByName.py.</div><div><br></div><div>So, in summary, we have an approach for setting colors by name by doing the</div><div> following:</div><div>1) Implement the classes including vtkNamedColors,</div>
<div>2) Call SetColor in vtkNamedColors passing the address of the object you want</div><div> to set the color in, the name of the property and the color to set.</div><div><br></div><div>Other approaches tried:</div><div>
<br></div><div>A) Not changing the VTK API. The only way is to implement interface classes</div><div> that, when constructed, take an instance of vtkNamedColors and</div><div> e.g vtkLookupTable. Then you implement a function to set by color name.</div>
<div> This approach generates a bit of extra coding by by the programmer and is</div><div> a really kludgey (in my opinion). You also have to implement this for the</div><div> other classes that have set color functions. Also, whenever you write a new</div>
<div> application, you have to do the same thing all over again.</div><div><br></div><div>B) Introducing pointers to the classes that set colors in vtkNamedColors:</div><div> This will not work for two reasons:</div><div>
1) The modular nature of VTK introduces cyclic dependencies - to resolve</div><div> this would require a lot of code reorganization and reduce the</div><div> modularity of VTK. Not a good thing!</div><div>
2) vtkRenderer is a factory and concrete implementations happen</div><div> after instantiation.</div><div><br></div><div>C) (Not tried) It may be possible to add helper classes and have the color</div><div> owning classes create them. A virtual class would have to be added to</div>
<div> vtkCommonCore. This approach does not allow you to use your own instance</div><div> of vtkNamedcolors as classes of interest e.g. vtkLookupTable need to</div><div> define SetColor methods that will need to define an instance of the helper</div>
<div> and then obtain a color with it.</div><div><br></div><div style>Regards</div><div style> Andrew</div><div style><br></div><div><br></div>-- <br>___________________________________________<br>Andrew J. P. Maclean<br>
<br>___________________________________________
</div>