<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">></span>
<o:p></o:p></p>
<p class="MsoNormal">There has been a request to have the ability to directly set colors using color<o:p></o:p></p>
<p class="MsoNormal"> names in vtkLookupTable and other classes. I must admit that after working on<o:p></o:p></p>
<p class="MsoNormal"> converting lots of TCL to Python tests, I felt the need for it too!<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><<o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Modifying vtkObject just so that you can set colours in Lookuptables strikes me as shockingly bad.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I vote no on principal.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">JB<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> vtk-developers-bounces@vtk.org [mailto:vtk-developers-bounces@vtk.org]
<b>On Behalf Of </b>Andrew Maclean<br>
<b>Sent:</b> 14 June 2013 11:05<br>
<b>To:</b> VTK Developers<br>
<b>Subject:</b> [vtk-developers] Setting color properties directly by name in VTK.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">Apologies for the long e-mail but this particular code change submitted for<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> review does entail a change to vtkObject.h. Hence the need for all you<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> developers to be comfortable with such a change. Alternatively you may be<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> able to suggest a better method of achieving this.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">There has been a request to have the ability to directly set colors using color<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> names in vtkLookupTable and other classes. I must admit that after working on<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> converting lots of TCL to Python tests, I felt the need for it too!<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">The current ways of setting colors by names are exemplified by:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">TestNamedColorsIntegration.cxx<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">TestNamedColorsIntegration.py<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">These work but are not very elegant.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">In order to overcome these limitations and make setting of colors more<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> intuitive for users, I have put the following up for review:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> <a href="http://review.source.kitware.com/11412">http://review.source.kitware.com/11412</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">Once again thanks to David Thompson for suggesting this approach.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">This approach does require a change to vtkObject.h, by introducing a function:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> virtual void SetProperty1(vtkVariantArray*)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">The upside of this is that, because it has a variant array as a parameter, there<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> will be other uses for this function in the future, most probably setting<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> parameters in a similar fashion to what has been done here.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">The rationale for this implementation is as follows:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">VTK uses a single inheritance model and is modularized so the logical thing is<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> to introduce a virtual SetProperty1 function, implement it in the<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> appropriate classes e.g. vtkLookUpTable and call this from vtkNamedColors.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">This would mean that in our code we can do things like:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">nc.SetColor(lut,"TableValue",1,"DarkGreen");<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">which under the hood implements:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">lut->SetTableValue(1,0,1,0,1);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">You can see implementations in:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">TestSetColorsByName.cxx<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">TestSetColorsByName.py.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">So, in summary, we have an approach for setting colors by name by doing the<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"> following:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">1) Implement the classes including vtkNamedColors,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">2) Call SetColor in vtkNamedColors passing the address of the object you want<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   to set the color in, the name of the property and the color to set.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">Other approaches tried:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">A) Not changing the VTK API. The only way is to implement interface classes<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   that, when constructed, take an instance of vtkNamedColors and<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   e.g vtkLookupTable. Then you implement a function to set by color name.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   This approach generates a bit of extra coding by by the programmer and is<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   a really kludgey (in my opinion). You also have to implement this for the<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   other classes that have set color functions. Also, whenever you write a new<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   application, you have to do the same thing all over again.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">B) Introducing pointers to the classes that set colors in vtkNamedColors:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   This will not work for two reasons:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">     1) The modular nature of VTK introduces cyclic dependencies - to resolve<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">        this would require a lot of code reorganization and reduce the<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">        modularity of VTK. Not a good thing!<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">     2) vtkRenderer is a factory and concrete implementations happen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">        after instantiation.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">C) (Not tried) It may be possible to add helper classes and have the color<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   owning classes create them. A virtual class would have to be added to<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   vtkCommonCore. This approach does not allow you to use your own instance<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   of vtkNamedcolors as classes of interest e.g. vtkLookupTable need to<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   define SetColor methods that will need to define an instance of the helper<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   and then obtain a color with it.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">Regards<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">   Andrew<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
<p class="MsoNormal" style="margin-left:36.0pt">-- <br>
___________________________________________<br>
Andrew J. P. Maclean<br>
<br>
___________________________________________ <o:p></o:p></p>
</div>
</div>
</body>
</html>