<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:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-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-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.apple-style-span
        {mso-style-name:apple-style-span;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span class=apple-style-span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'>On Sep 27, 2011, at 12:49 PM, Hong Yi wrote:</span></span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'><br><br><span class=apple-style-span>> Hello,</span><br><span class=apple-style-span>></span><br><span class=apple-style-span>> I am wondering whether there is a simple way to create a blue-white-red color map vtkLookupTable other than defining scalar to color mapping through color transfer function. If I set the hue range from 0.667 to 0, a rainbow blue to red colormap will be generated. What I want is not a rainbow colormap, but a blue-white-red color map which varies colors from blue through white to red. Any advice is very much appreciated.</span><br><span class=apple-style-span>></span><br><span class=apple-style-span>> Thanks,</span><br><span class=apple-style-span>></span><br><span class=apple-style-span>> Hong</span><br></span><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'> <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Hi Hong,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Here’s some code I use to set up color mappings. I was using it for another mapping but I dropped in red/white/blue and it worked ok. It’s from a class CaseSpaceDialog and there are a few objects that are class members that aren’t defined within the code presented here but could be, notably min and max (the min and max values of the data you’re color mapping, which need to be available prior to calling these methods), plus vtkScalarBarActor *legend, vtkLookupTable *lookupTable, vtkRenderer *ren, and numColors, which is just the total number of different color gradations you want: I set it to 100 for a reasonably continuous-looking color bar. The second method just calls the first one in a loop to generate the legend. I did some global replaces to generalize the way the code reads, so hopefully nothing went awry. Let me know if something’s broken or doesn’t make sense.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Steve<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:black'>-Steve Chall<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:black'> Senior Research Software Developer<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:black'> Renaissance Computing Institute (RENCI)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:black'> Phone: 919-681-9639<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:black'> Email: <a href="mailto:stevec@renci.org"><span style='color:blue'>stevec@renci.org</span></a></span><span style='font-family:"Arial","sans-serif"'><o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>///getColorCorrespondingToValue ////////////////////////////////////////////////</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>//</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// Assumes you've already generated min and max -- the extrema for the data</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// to which you're applying the color map. Then define the number of colorNodes</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// and make sure there's a row of three double values (representing r, g, and b</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// in a 0.0-1.0 range) for each node. Then call this method for with parameter </span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// val some double value between min and max inclusive. The corresponding rgb</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// values will be returned in the reference-to-double parameters r, g, and b. </span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>//</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>////////////////////////////////////////////////////////////////////////////////</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:blue'>void</span><span style='font-size:9.5pt;font-family:"Courier New"'> CaseSpaceDialog::getColorCorrespondingTovalue(<span style='color:blue'>double</span> val,<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> &r, <span style='color:blue'>double</span> &g, <span style='color:blue'>double</span> &b)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'>{<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>static</span> <span style='color:blue'>const</span> <span style='color:blue'>int</span> numColorNodes = 3;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> color[numColorNodes][3] =<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> 0.0, 0.0, 1.0, <span style='color:green'>// blue</span><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> 1.0, 1.0, 1.0, <span style='color:green'>// white</span><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> 1.0, 0.0, 0.0 <span style='color:green'>// red</span><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> };<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>for</span> (<span style='color:blue'>int</span> i = 0; i < (numColorNodes - 1); i++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> currFloor = min + ((<span style='color:blue'>double</span>)i / (numColorNodes - 1)) * range;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> currCeil = min + ((<span style='color:blue'>double</span>)(i + 1) / (numColorNodes - 1)) * range;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>if</span> ((val >= currFloor) && (val <= currCeil))<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> currFraction = (val - currFloor) / (currCeil - currFloor);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> r = color[i][0] * (1.0 - currFraction) + color[i + 1][0] * currFraction;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> g = color[i][1] * (1.0 - currFraction) + color[i + 1][1] * currFraction;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> b = color[i][2] * (1.0 - currFraction) + color[i + 1][2] * currFraction;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'>}<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>////initializeLegend////////////////////////////////////////////////////////////</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>//</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// Make sure min and max have been generated before calling this method.<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>//<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// Assumes that pointers legend and lookupTable are set to 0 if not already<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// instantiated.<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>// </span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:green'>////////////////////////////////////////////////////////////////////////////////</span><span style='font-size:9.5pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New";color:blue'>void</span><span style='font-size:9.5pt;font-family:"Courier New"'> CaseSpaceDialog::initializeLegend()<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'>{<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>if</span> (!legend)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend = vtkScalarBarActor::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> lookupTable = vtkLookupTable::New();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> lookupTable->SetScaleToLinear();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> lookupTable->SetRange(min, max);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> lookupTable->SetNumberOfTableValues(numColors);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> r, g, b;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>for</span> (<span style='color:blue'>int</span> i = 0; i < numColors; i++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> <span style='color:blue'>double</span> val = min + ((<span style='color:blue'>double</span>)i / numColors) * range;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> getColorCorrespondingTovalue(val, r, g, b);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> lookupTable->SetTableValue(i, r, g, b);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> lookupTable->Build();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->SetLookupTable(lookupTable);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->SetTitle(<span style='color:#A31515'>"Values"</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->SetOrientationToHorizontal();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->GetPositionCoordinate()->SetValue(0.814, 0.94);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->SetWidth(0.1515);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->SetHeight(0.05);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->GetTitleTextProperty()->ItalicOff();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> legend->GetLabelTextProperty()->ItalicOff();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'> ren->AddActor2D(legend);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'>}<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p></div></body></html>