[vtkusers] Create a color map using polyData in VTK

Gishara Indeewarie gish.777 at gmail.com
Fri Feb 3 02:19:37 EST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120203/998d5d88/attachment.htm>


More information about the vtkusers mailing list