[vtkusers] Color maps
Eric E. Monson
emonson at cs.duke.edu
Thu Mar 4 09:57:16 EST 2010
Hey Uliana,
Maybe someone else has a better method, but when I need more control over the creation of a lookup table, I use a vtkColorTransferFunction to build the color table that I want, and then copy the values into a vtkLookupTable. Here is an example of what I did recently to create a diverging blue to red color map (sorry it's in Python):
lut = vtk.vtkLookupTable()
lutNum = 256
lut.SetNumberOfTableValues(lutNum)
ctf = vtk.vtkColorTransferFunction()
ctf.SetColorSpaceToDiverging()
ctf.AddRGBPoint(0.0, 0, 0, 1.0)
ctf.AddRGBPoint(1.0, 1.0, 0, 0)
for ii,ss in enumerate([float(xx)/float(lutNum) for xx in range(lutNum)]):
cc = ctf.GetColor(ss)
lut.SetTableValue(ii,cc[0],cc[1],cc[2],1.0)
There are many options in vtkColorTransferFunction that I've never played with.
For opacity, if you're just creating your lookup table directly, there is a SetAlphaRange(). For more manual control, the last argument in SetTableValue() is the alpha value (where in the above example I have just used 1.0 to set it opaque).
I see that vtkDiscretizableColorTransferFunction is supposed to combine the functionality of vtkColorTransferFunction and vtkLookupTable, but the documentation is sparse, and I hadn't seen it until this morning.
Hope this helps get you started,
-Eric
------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group
On Mar 3, 2010, at 8:28 PM, Ula Popov wrote:
> Hi all,
>
> I have a couple of questions about color maps.
> I have a scalar date that's range is [0..1265]
> My code looks like this:
>
> vtkLookupTable *lut = vtkLookupTable::New();
> lut->SetNumberOfColors(256);
> lut->SetHueRange(0.0,1.0);
> lut->Build();
>
> vtkDataSetMapper *mapper = vtkDataSetMapper::New();
> mapper->SetInputConnection(T2_reader->GetOutputPort());
> mapper->SetLookupTable(lut);
> mapper->SetScalarRange(0.0, 1265.0);
>
> I have 2 problems:
> - 70% of the picture is red. How can I "shift" the color map? What should I do to see 70% white?
> - How can I change the opacity? If I want [0..300] be 0.3 opaque and [301..1265] 0.8 opaque?
>
>
> Thank you,
> Uliana
> _______________________________________________
> 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
More information about the vtkusers
mailing list