[vtkusers] Re: How to change the color of cube?

Christopher.Moore at noaa.gov Christopher.Moore at noaa.gov
Thu Sep 2 14:12:40 EDT 2004


Hi Wang,

You see no white or black on the cube because the default vtkLookupTable 
associated with vtkPolyDataMapper uses a Hue/Saturation/Value ramp with a 
Hue range from 0.0 to 0.667, giving a color range from red to blue.

You have three choices:

1) change the ramps for hue (or saturation, or value) to give a different 
color map, for instance "black to white".

2) insert specific colors into the LookupTable, instead of ramps.

3) color the cube by a single color.

Here's how to do each:

1) add this LookupTable to your code between Mapper and Actor for a 
different ramp (black to white):

  // Now we'll look at it.
  vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
      cubeMapper->SetInput(cube);
      cubeMapper->SetScalarRange(0,7);

  vtkLookupTable *lut = vtkLookupTable::New();
      lut->SetHueRange(0.0, 0.0);
      lut->SetSaturationRange(0.0, 0.0);
      lut->SetValueRange(0.0, 1.0);

      cubeMapper->SetLookupTable(lut);

  vtkActor *cubeActor = vtkActor::New();
      cubeActor->SetMapper(cubeMapper);

2) add this LookupTable to your code to map specific colors to the scalar 
range (this is a brown-green-white range to map terrain data):

  vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
      cubeMapper->SetInput(cube);
      cubeMapper->SetScalarRange(0,7);

  vtkLookupTable *lut = vtkLookupTable::New();
      lut->SetNumberOfColors(11);
      lut->Build();
      lut->SetTableValue(0, 25./255., 53./255., 40./255., 1);
      lut->SetTableValue(1, 54./255., 73./255., 56./255., 1);
      lut->SetTableValue(2, 111./255., 108./255., 94./255., 1);
      lut->SetTableValue(3, 156./255., 137./255., 90./255., 1);
      lut->SetTableValue(4, 170./255., 153./255., 138./255., 1);
      lut->SetTableValue(5, 181./255., 169./255., 113./255., 1);
      lut->SetTableValue(6, 142./255., 83./255., 35./255., 1);
      lut->SetTableValue(7, 99./255., 41./255., 9./255., 1);
      lut->SetTableValue(8, 62./255., 20./255., 3./255., 1);
      lut->SetTableValue(9, 1.0, 1.0, 1.0, 1);
      lut->SetTableValue(10, 1.0, 1.0, 1.0, 1);

      cubeMapper->SetLookupTable(lut);

  vtkActor *cubeActor = vtkActor::New();
      cubeActor->SetMapper(cubeMapper);

3) This is how to simply color the cube black:

  vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
      cubeMapper->SetInput(cube);
      //      cubeMapper->SetScalarRange(0,7);
      cubeMapper->ScalarVisibilityOff();

  vtkActor *cubeActor = vtkActor::New();
      cubeActor->SetMapper(cubeMapper);
      cubeActor->GetProperty()->SetColor(0, 0, 0);

Cheers,
Chris

__________________________________________________________________
Christopher Moore                email: Christopher.Moore at noaa.gov


> Date: Thu, 02 Sep 2004 11:57:23 +0800
> From: "wang minyou" <wmy1024 at hotmail.com>
> Subject: [vtkusers] How to change the color of cube?
> To: vtkusers at vtk.org
> Message-ID: <BAY17-F32K3l7IMbtfA0009de4e at hotmail.com>
> Content-Type: text/plain; charset=gb2312; format=flowed
> 
> I use vtkPolydata to create a cube, but it only can display pure colors but 
> not blank 
> or white. Any one can help me to achieve that?
> Thank you in advance!
> 
> My relevant codes:







More information about the vtkusers mailing list