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"><<a href="mailto:gish.777@gmail.com">gish.777@gmail.com</a>></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'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<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();</div><div> polydata->SetPoints(points);</div><div><br></div><div> vtkSmartPointer<vtkDoubleArray> weights = vtkSmartPointer<vtkDoubleArray>::New();</div>
<div> weights->SetNumberOfValues(PoValues.GetSize());</div><div> for(int i=0; i< PoValues.GetSize();i++){</div><div> weights->SetValue(i, PoValues[i]);</div><div> }</div><div> // polydata->GetPointData()->SetScalars(weights);</div>
<div> </div><div> vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =</div><div> vtkSmartPointer<vtkVertexGlyphFilter>::New();</div><div>#if VTK_MAJOR_VERSION <= 5</div><div> glyphFilter->SetInputConnection(polydata->GetProducerPort());</div>
<div>#else</div><div> glyphFilter->SetInputData(polydata);</div><div>#endif</div><div> glyphFilter->Update();</div><div> </div><div> // Create a plane to cut</div><div> vtkSmartPointer<vtkPlane> plane =</div>
<div> vtkSmartPointer<vtkPlane>::New();</div><div> plane->SetOrigin(polydata->GetCenter());</div><div> plane->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<vtkSurfaceReconstructionFilter> surf = </div><div> vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();</div><div><br></div><div> surf->SetInput(polydata);</div><div> //</div>
<div>
vtkSmartPointer<vtkContourFilter> cf = vtkSmartPointer<vtkContourFilter>::New();</div><div> cf->SetInputConnection(surf->GetOutputPort());</div><div> cf->Update();</div><div> vtkPolyData* outputPolyData = cf->GetOutput();</div>
<div><br></div><div> double bounds[6];</div><div> outputPolyData->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 << "minz: " << minz << std::endl;</div><div> std::cout << "maxz: " << maxz << std::endl;</div><div> </div><div> // Create the color map</div><div>
vtkSmartPointer<vtkLookupTable> colorLookupTable = vtkSmartPointer<vtkLookupTable>::New();</div><div> colorLookupTable->SetTableRange(minz, maxz);</div><div> colorLookupTable->SetHueRange(0.0,0.667);</div>
<div> colorLookupTable->SetNumberOfColors(16);</div><div><br></div><div> colorLookupTable->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<vtkUnsignedCharArray> colors = </div><div> vtkSmartPointer<vtkUnsignedCharArray>::New();</div><div> colors->SetNumberOfComponents(3);</div>
<div> colors->SetName("Colors");</div><div> for(int i = 0; i < outputPolyData->GetNumberOfPoints(); i++)</div><div> {</div><div> double p[3];</div><div> outputPolyData->GetPoint(i,p);</div>
<div> </div><div> double dcolor[3];</div><div> colorLookupTable->GetColor(p[2], dcolor);</div><div> unsigned char color[3];</div><div> for(unsigned int j = 0; j < 3; j++)</div><div> {</div><div> color[j] = static_cast<unsigned char>(255.0 * dcolor[j]);</div>
<div> }</div><div><br></div><div> colors->InsertNextTupleValue(color);</div><div> }</div><div> </div><div> outputPolyData->GetPointData()->SetScalars(colors);</div><div> </div><div> // Create a mapper and actor</div>
<div> vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</div><div> mapper->SetInputConnection(/*reverse->GetOutputPort()*/cf->GetOutputPort());</div><div> mapper->ScalarVisibilityOn();</div>
<div> mapper->SetLookupTable(colorLookupTable);</div><div> // mapper->SetScalarRange(polydata->GetScalarRange());</div><div> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();</div>
<div> //actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque</div><div> actor->SetMapper(mapper);</div><div> </div><div> //Create a renderer, render window, and interactor</div><div> vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();</div>
<div> vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();</div><div> renderWindow->AddRenderer(renderer);</div><div> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();</div>
<div> renderWindowInteractor->SetRenderWindow(renderWindow);</div><div><br></div><div> //Add the actor to the scene</div><div> renderer->AddActor(actor);</div><div> renderer->SetBackground(.3, .6, .3); // Background color green</div>
<div> </div><div> //Render and interact</div><div> renderWindow->Render();</div><div> renderWindowInteractor->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>