[vtkusers] Problem mapping scalars to colors using a vtkLooku pTable

Nithiananthan, Sajendra Sajendra.Nithiananthan at rmp.uhn.on.ca
Tue Jul 3 10:16:23 EDT 2007


> Hello Geofram and others,

>Now, if only a vtkColorTransferFunction would allow you to specify an
opacity for each scalar... Are there any 
>classes that do such things?


Peter,

I don't think there's a class that does it directly, but you can define a
transfer function for colour, and one for opacity, then use that to
construct the lookup table.  eg:

  vtkColorTransferFunction *colourTF = vtkColorTransferFunction::New();
  colourTF->AddRGBPoint(0, r0, g0, b0);
	...
  colourTF->AddRGBPoint(255, r255, g255, b255);
  colourTF->Build();
	
  vtkPiecewiseFunction *opacityTF = vtkPiecewiseFunction::New();
  opacityTF->AddPoint(1, 0);
  opacityTF->AddPoint(255, 1); 

  vtkLookupTable *tbl = vtkLookupTable::New();
  tbl->SetRange(somemin , somemax); 
  tbl->SetNumberOfTableValues(256);
  for(int i=0; i < 256; i++) {
    double rgba[4];
    rgba[0] = colourTF->GetRedValue(i);
    rgba[1] = colourTF->GetGreenValue(i);
    rgba[2] = colourTF->GetBlueValue(i);
    rgba[3] = opacityTF->GetValue(i);
    tbl->SetTableValue(i,rgba);
  }

  something->SetLookupTable(tbl);



Hope that helps,
SN

This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient. Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited. If you have received this e-mail in error, please contact the sender and delete all copies. Opinions, conclusions or other information contained in this e-mail may not be that of the organization.



More information about the vtkusers mailing list