[vtkusers] Create a color map using polyData in VTK

Gishara Indeewarie gish.777 at gmail.com
Fri Feb 3 12:30:23 EST 2012


Thanks David and Bill. Even I change the color of the actor to none, I got
only one color I set in the lookup table. I can't test my application right
now. Can you please tell me why we need triangulation in the given example?

http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Color_a_mesh_by_height

 I am just a beginner in this, so please bear with me.

On Fri, Feb 3, 2012 at 7:14 PM, Bill Lorensen <bill.lorensen at gmail.com>wrote:

> Change
>  mapper->ScalarVisibilityOff();
> to
>  mapper->ScalarVisibilityOn();
>
> When ScalarVisibility is off, the color of the actor is used. If it is
> On, the scalar data mapped through the lookup table will be used.
>
>
> 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
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
>



-- 
Gish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120203/f2d12b2d/attachment.htm>


More information about the vtkusers mailing list