Quantcast

Create a color map using polyData in VTK

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Create a color map using polyData in VTK

gishu
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.
 
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create a color map using polyData in VTK

David Doria-2-3
On Fri, Feb 3, 2012 at 2:19 AM, Gishara Indeewarie <[hidden email]> 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.
 
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 

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create a color map using polyData in VTK

Bill Lorensen
In reply to this post by gishu
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 <[hidden email]> 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
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create a color map using polyData in VTK

gishu
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?


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

On Fri, Feb 3, 2012 at 7:14 PM, Bill Lorensen <[hidden email]> 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 <[hidden email]> 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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create a color map using polyData in VTK

David Doria-2-3
n Fri, Feb 3, 2012 at 12:30 PM, Gishara Indeewarie <[hidden email]> wrote:
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?


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

You do not need the triangulation. That example is demonstrating both how to create a surface from a set of points as well as how to apply the color mapping.

David

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create a color map using polyData in VTK

gishu
Thanks a lot David. 

On Fri, Feb 3, 2012 at 11:03 PM, David Doria <[hidden email]> wrote:
n Fri, Feb 3, 2012 at 12:30 PM, Gishara Indeewarie <[hidden email]> wrote:
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?


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

You do not need the triangulation. That example is demonstrating both how to create a surface from a set of points as well as how to apply the color mapping.

David



--
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
Loading...