I am sorry, I have not set the range properly in the table and in the mapper. Sorry again.<br><br><div class="gmail_quote">On Mon, Feb 6, 2012 at 12:53 PM, Gishara Indeewarie <span dir="ltr">&lt;<a href="mailto:gish.777@gmail.com">gish.777@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi all,</div><div><br></div><div>I have created a shape with different colors using color lookup table according to the example below:</div>
<div><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Color_a_mesh_by_height" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Color_a_mesh_by_height</a>
</div><div><br></div><div>It is working well, but I can&#39;t see where is set the scalar values to colors. Below is my code.</div><div><br></div><div><div>vtkPoints *points = newPts;//ReadCFDData2();</div><div><span style="white-space:pre-wrap">        </span></div>

<div>  vtkSmartPointer&lt;vtkPolyData&gt; polydata = vtkSmartPointer&lt;vtkPolyData&gt;::New();</div><div>  polydata-&gt;SetPoints(points);</div><div><br></div><div>  vtkSmartPointer&lt;vtkDoubleArray&gt; weights = vtkSmartPointer&lt;vtkDoubleArray&gt;::New();</div>

<div>  weights-&gt;SetNumberOfValues(PoValues.GetSize());</div><div>  for(int i=0; i&lt; PoValues.GetSize();i++){</div><div>  weights-&gt;SetValue(i, PoValues[i]);</div><div>  }</div><div> // polydata-&gt;GetPointData()-&gt;SetScalars(weights);</div>

<div> </div><div>  vtkSmartPointer&lt;vtkVertexGlyphFilter&gt; glyphFilter =</div><div>    vtkSmartPointer&lt;vtkVertexGlyphFilter&gt;::New();</div><div>#if VTK_MAJOR_VERSION &lt;= 5</div><div>  glyphFilter-&gt;SetInputConnection(polydata-&gt;GetProducerPort());</div>

<div>#else</div><div>  glyphFilter-&gt;SetInputData(polydata);</div><div>#endif</div><div>  glyphFilter-&gt;Update();</div><div> </div><div>  // Create a plane to cut</div><div>  vtkSmartPointer&lt;vtkPlane&gt; plane =</div>

<div>    vtkSmartPointer&lt;vtkPlane&gt;::New();</div><div>  plane-&gt;SetOrigin(polydata-&gt;GetCenter());</div><div>  plane-&gt;SetNormal(1,1,1);</div><div><br></div><div>  </div><div>  // Construct the surface and create isosurface.<span style="white-space:pre-wrap">        </span></div>

<div>  vtkSmartPointer&lt;vtkSurfaceReconstructionFilter&gt; surf = </div><div>    vtkSmartPointer&lt;vtkSurfaceReconstructionFilter&gt;::New();</div><div><br></div><div>  surf-&gt;SetInput(polydata);</div><div> //</div>
<div>
  vtkSmartPointer&lt;vtkContourFilter&gt; cf =  vtkSmartPointer&lt;vtkContourFilter&gt;::New();</div><div>  cf-&gt;SetInputConnection(surf-&gt;GetOutputPort());</div><div>  cf-&gt;Update();</div><div>   vtkPolyData* outputPolyData = cf-&gt;GetOutput();</div>

<div><br></div><div>  double bounds[6];</div><div>  outputPolyData-&gt;GetBounds(bounds);</div><div> </div><div>  // Find min and max z</div><div>  double minz = bounds[4];</div><div>  double maxz = bounds[5];</div><div>
 </div>
<div>  std::cout &lt;&lt; &quot;minz: &quot; &lt;&lt; minz &lt;&lt; std::endl;</div><div>  std::cout &lt;&lt; &quot;maxz: &quot; &lt;&lt; maxz &lt;&lt; std::endl;</div><div> </div><div>  // Create the color map</div><div>

  vtkSmartPointer&lt;vtkLookupTable&gt; colorLookupTable = vtkSmartPointer&lt;vtkLookupTable&gt;::New();</div><div>  colorLookupTable-&gt;SetTableRange(minz, maxz);</div><div>  colorLookupTable-&gt;SetHueRange(0.0,0.667);</div>

<div>  colorLookupTable-&gt;SetNumberOfColors(16);</div><div><br></div><div>  colorLookupTable-&gt;Build();</div><div>  //unsigned char *op;</div><div>  //vtkScalarsToColors::MapScalarsThroughTable(newScalars,op);</div><div>

 </div><div>  // Generate the colors for each point based on the color map</div><div>  vtkSmartPointer&lt;vtkUnsignedCharArray&gt; colors = </div><div>    vtkSmartPointer&lt;vtkUnsignedCharArray&gt;::New();</div><div>  colors-&gt;SetNumberOfComponents(3);</div>

<div>  colors-&gt;SetName(&quot;Colors&quot;);</div><div>  for(int i = 0; i &lt; outputPolyData-&gt;GetNumberOfPoints(); i++)</div><div>    {</div><div>    double p[3];</div><div>    outputPolyData-&gt;GetPoint(i,p);</div>

<div> </div><div>    double dcolor[3];</div><div>    colorLookupTable-&gt;GetColor(p[2], dcolor);</div><div>    unsigned char color[3];</div><div>    for(unsigned int j = 0; j &lt; 3; j++)</div><div>      {</div><div>      color[j] = static_cast&lt;unsigned char&gt;(255.0 * dcolor[j]);</div>

<div>      }</div><div><br></div><div>    colors-&gt;InsertNextTupleValue(color);</div><div>    }</div><div> </div><div>  outputPolyData-&gt;GetPointData()-&gt;SetScalars(colors);</div><div> </div><div>  // Create a mapper and actor</div>

<div>  vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapper = vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();</div><div>  mapper-&gt;SetInputConnection(/*reverse-&gt;GetOutputPort()*/cf-&gt;GetOutputPort());</div><div> mapper-&gt;ScalarVisibilityOn();</div>

<div>  mapper-&gt;SetLookupTable(colorLookupTable);</div><div> // mapper-&gt;SetScalarRange(polydata-&gt;GetScalarRange());</div><div>  vtkSmartPointer&lt;vtkActor&gt; actor = vtkSmartPointer&lt;vtkActor&gt;::New();</div>

<div>   //actor-&gt;GetProperty()-&gt;SetColor(1.0, 0.8941, 0.7686); // bisque</div><div>  actor-&gt;SetMapper(mapper);</div><div> </div><div>  //Create a renderer, render window, and interactor</div><div>  vtkSmartPointer&lt;vtkRenderer&gt; renderer = vtkSmartPointer&lt;vtkRenderer&gt;::New();</div>

<div>  vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow = vtkSmartPointer&lt;vtkRenderWindow&gt;::New();</div><div>  renderWindow-&gt;AddRenderer(renderer);</div><div>  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor = vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();</div>

<div>  renderWindowInteractor-&gt;SetRenderWindow(renderWindow);</div><div><br></div><div>  //Add the actor to the scene</div><div>  renderer-&gt;AddActor(actor);</div><div>  renderer-&gt;SetBackground(.3, .6, .3); // Background color green</div>

<div> </div><div>  //Render and interact</div><div>  renderWindow-&gt;Render();</div><div>  renderWindowInteractor-&gt;Start();</div></div><div><br></div><div>Can anyone tell me where should I map the scalar values to colors in the above code?</div>

<div><br></div><div>Thanks.</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div></div><font color="#666666">Gish</font><br>