[vtkusers] Create a color map using polyData in VTK
David Doria
daviddoria at gmail.com
Fri Feb 3 07:36:50 EST 2012
On Fri, Feb 3, 2012 at 2:19 AM, Gishara Indeewarie <gish.777 at gmail.com>wrote:
> Hi all,
>
> I have a set of points (x,y,z) and the values of each point. I have
> created a surface according to the following example.
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filters/SurfaceFromUnorganizedPoints
>
>
> And I want to create a color map by giving colors to each point according
> to the value of each point.
> My problem is that I can't see the color map in my example. All I see is
> the surface with a plain color.
> The code is as below:
>
> vtkPoints *points = newPts;//ReadCFDData2();
> vtkSmartPointer<vtkPolyData> polydata
> = vtkSmartPointer<vtkPolyData>::New();
> polydata->SetPoints(points);
>
> vtkSmartPointer<vtkDoubleArray> weights =
> vtkSmartPointer<vtkDoubleArray>::New();
> weights->SetNumberOfValues(PoValues.GetSize());
> for(int i=0; i< PoValues.GetSize();i++){
> weights->SetValue(i, PoValues[i]);
> }
> polydata->GetPointData()->SetScalars(weights);
>
> vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
> vtkSmartPointer<vtkVertexGlyphFilter>::New();
> #if VTK_MAJOR_VERSION <= 5
> glyphFilter->SetInputConnection(polydata->GetProducerPort());
> #else
> glyphFilter->SetInputData(polydata);
> #endif
> glyphFilter->Update();
>
> // Create a plane to cut
> vtkSmartPointer<vtkPlane> plane =
> vtkSmartPointer<vtkPlane>::New();
> plane->SetOrigin(polydata->GetCenter());
> plane->SetNormal(1,1,1);
>
>
> // Construct the surface and create isosurface.
> vtkSmartPointer<vtkSurfaceReconstructionFilter> surf =
> vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
>
> surf->SetInput(polydata);
> //
> vtkSmartPointer<vtkContourFilter> cf =
> vtkSmartPointer<vtkContourFilter>::New();
> cf->SetInputConnection(surf->GetOutputPort());
>
> // Create the color map
> vtkSmartPointer<vtkLookupTable> colorLookupTable =
> vtkSmartPointer<vtkLookupTable>::New();
> colorLookupTable->SetNumberOfColors(64);
> colorLookupTable->SetHueRange( 0.0,0.667);
> colorLookupTable->SetTableRange(0,3);
> colorLookupTable->Build();
>
> // Create a mapper and actor
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
>
> mapper->SetInputConnection(/*reverse->GetOutputPort()*/cf->GetOutputPort());
> mapper->ScalarVisibilityOff();
> mapper->SetLookupTable(colorLookupTable);
>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque
> actor->SetMapper(mapper);
>
> //Create a renderer, render window, and interactor
> vtkSmartPointer<vtkRenderer> renderer
> = vtkSmartPointer<vtkRenderer>::New();
> vtkSmartPointer<vtkRenderWindow> renderWindow
> = vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
> = vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
>
> //Add the actor to the scene
> renderer->AddActor(actor);
> renderer->SetBackground(.3, .6, .3); // Background color green
>
> //Render and interact
> renderWindow->Render();
> renderWindowInteractor->Start();
>
> Please explain me where I have gone wrong. Thanks a lot.
>
> --
> Gish
>
Why are you setting a color on the actor if you want the lookup table to
provide the colors?
actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque ?
Here is a working example of using a color map:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Color_a_mesh_by_height
See if that helps.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120203/c22b951f/attachment.htm>
More information about the vtkusers
mailing list