[vtkusers] Problem mapping scalars to colors using a vtkLookupTable

Geoframer geoframer at gmail.com
Tue Jun 5 19:55:16 EDT 2007


Hey Peter,

Is it the creation of the lookuptable that's causing you problems or
something else? I've been experimenting a bit with lookuptables and can
create a lookuptable as you described (see scrap of python-code below), does
this help?

Regards - Geofram


import vtk

#create the lookuptable for colors
lookupTable = vtk.vtkLookupTable()
lookupTable.SetNumberOfTableValues(100)
lookupTable.SetTableRange(0, 100)
lookupTable.Build()

for i in range(100):
    lookupTable.SetTableValue(i, 0.0, 0.0, 0.0, 1.0)
lookupTable.SetTableValue(5, 1.0, 0.0, 0.0, 1.0)
lookupTable.SetTableValue(10, 0.0, 1.0, 0.0, 1.0)
lookupTable.SetTableValue(50, 0.0, 0.0, 1.0, 1.0)

#create a colorbar using the lookuptable to see if it's correct
colorbar = vtk.vtkScalarBarActor()
colorbar.SetMaximumNumberOfColors(400)
colorbar.SetLookupTable(lookupTable)
colorbar.SetWidth(0.05)
colorbar.SetPosition(0.95, 0.1)
colorbar.SetLabelFormat("%.3g")
colorbar.VisibilityOn()

#create the stuff to visualise
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(750,750)
interact = vtk.vtkRenderWindowInteractor()
interact.SetRenderWindow(renWin)
ren.AddActor(colorbar)
ren.SetBackground(0.5,0.6,0.7)
renWin.GetInteractor().Initialize()
renWin.Render()
renWin.GetInteractor().Start()



On 5/21/07, Peter Kok <peter.kok at gmail.com> wrote:
>
> Hi there,
>
> I am trying to map certain specific scalars to colors using a
> vtkLookupTable. Let's say I want to map the scalar 5 to red, 10 to green,
> 100 to blue and the rest to black. So what I need to do is similar to a
> vtkColorTransferFunction, which I cannot use, because I want to use it for a
> vtkImagePlaneWidget, which only accepts vtkLookupTables.
>
> One option seemed to be to extend vtkLookupTable and reimplement
> GetIndex(float) -> int, which I expected to map the scalar to an index in
> the table values. This didn't work, but I am not sure if it is supposed to
> work.
>
> What are my options?
>
> Regards,
> Peter
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070606/5831b9d2/attachment.htm>


More information about the vtkusers mailing list