[vtkusers] How to change colour mapping of a vtkImageData? (used as a plane's texture)

Sara Broughton - CSCI/P2002 s3brough at scs.ryerson.ca
Mon Jun 27 18:13:25 EDT 2005


Hi Sean,

You could try using vtkImageMapToColors.  I used the following method a few weeks ago.  
(It produces a black and white image.)


vtkVolume16Reader *v16 = vtkVolume16Reader::New();
... // this should work for vtkImageReslice too.

// Create a black/white lookup table.
vtkLookupTable *bwLut = vtkLookupTable::New();
    bwLut->SetTableRange (0, 2000);
    bwLut->SetSaturationRange (0, 0);
    bwLut->SetHueRange (0, 0);
    bwLut->SetValueRange (0, 1);

vtkImageMapToColors *bwColors = vtkImageMapToColors::New();
    bwColors->SetInput(v16->GetOutput());
    bwColors->SetLookupTable(bwLut);

vtkTexture* planeYTexture = vtkTexture::New();
        planeYTexture->SetInput(bwColors->GetOutput());

planeYSource = vtkPlaneSource::New();
...

vtkPolyDataMapper *planeYMapper = vtkPolyDataMapper::New();
...

vtkActor *planeYActor = vtkActor::New();
        planeYActor->SetMapper(planeYMapper);
        planeYActor->SetTexture(planeYTexture);


The above is based on my pseudo-code--I don't have the actual source code 
with me at the moment... 


On Mon, 27 Jun 2005, Sean McBride wrote:

> Hi all,
> 
> I have a vtkImageData which I use as a texture on a plane.  It works
> great, but displays with what I am assuming is some kind of default
> colour table (it is full spectrum, like a rainbow).  I am trying to make
> it display in greyscale instead, but I don't know how.  I've found
> vtkMapper::SetLookupTable() but using it seems to have no effect (even
> if I pass NULL!).  Is it the wrong approach?
> 
> My pseudo-code snippit is:
> 
> vtkImageReslice* resliceY = vtkImageReslice::New();
>  ...
> planeYSource = vtkPlaneSource::New();
> 	planeYSource->SetOrigin (...);
> 	planeYSource->SetPoint1 (...);
> 	planeYSource->SetPoint2 (...);
> vtkColorTransferFunction*	colourTransfer = vtkColorTransferFunction::New();
> 	colourTransfer->AddRGBPoint (0, 0, 0, 0);
> 	colourTransfer->AddRGBPoint (255, 1, 1, 1);
> vtkPolyDataMapper*	planeYMapper = vtkPolyDataMapper::New();
> 	planeYMapper->SetInput(planeYSource->GetOutput());
> 	planeYMapper->SetLookupTable(colourTransfer); // ******
> vtkTexture*	planeYTexture = vtkTexture::New();
> 	planeYTexture->SetInput(resliceY->GetOutput());
> vtkActor*	planeYActor = vtkActor::New();
> 	planeYActor->SetMapper(planeYMapper);
> 	planeYActor->SetTexture(planeYTexture);
> myRenderer->AddActor(planeYActor);
> 
> Thanks!
> 
> 
> 

-- 
Sara Broughton
Research Assistant
Department of Computer Science
Ryerson University, Toronto





More information about the vtkusers mailing list