[vtkusers] Color Look up table not working for vtkDataSetMapper using vtkNetCDFCFReader

Manjunath K E ke.manjunath at gmail.com
Thu Jul 2 08:25:07 EDT 2015


Hi,

I am working on ocean data visualization. I have data in netCdf format.
I have written a code to read netcdf file and assign color for the input.
Although, I am able to get grid display, but I am unable to get the
coloring on it.

I have created lookup table for color mapping, but it is not working..
Please  help me.
Following is my code...
========================================================
from vtk import *

reader = vtkNetCDFCFReader()
reader.SetFileName("3d.nc")
reader.SphericalCoordinatesOff()
#reader.SetOutputTypeToRectilinear()
reader.SetOutputType(6)#SetOutputTypeToRectilinear()
reader.SetReplaceFillValueWithNan(1)
reader.UpdateMetaData()
reader.Update()
reader.GetOutput().UpdateInformation()
output = reader.GetOutput()

# find the range of the point scalars
a,b = reader.GetOutput().GetPointData().GetArray("SAL").GetRange()
nm = reader.GetOutput().GetPointData().GetArray("SAL").GetName()

# show how to print a string in python, it is similar to C-style sprintf
print "Range of %s: %4.2f-%4.2f" %(nm,a,b)

# transfer function (lookup table) for mapping point scalar data
# to colors (parent class is vtkScalarsToColors)
lut = vtk.vtkColorTransferFunction()
lut.AddRGBPoint(a,         0.0, 0.0, 1.0)
lut.AddRGBPoint(a+(b-a)/4, 0.0, 0.5, 0.5)
lut.AddRGBPoint(a+(b-a)/2, 0.0, 1.0, 0.0)
lut.AddRGBPoint(b-(b-a)/4, 0.5, 0.5, 0.0)
lut.AddRGBPoint(b,         1.0, 0.0, 0.0)
lut.SetAlpha(0.5)

mapper = vtkDataSetMapper()
mapper.SetInputConnection(reader.GetOutputPort())
mapper.SetScalarModeToUsePointData()
mapper.SetLookupTable(lut)
mapper.SetScalarRange(a,b)
mapper.SelectColorArray("SAL");

# the actor
myActor = vtkActor()
myActor.SetMapper( mapper )

# renderer and render window
ren = vtkRenderer()
ren.SetBackground(1, 1, 1)
renWin = vtk.vtkRenderWindow()
renWin.SetSize(512, 512)
renWin.AddRenderer( ren )

# render window interactor
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow( renWin )

# add the actors to the renderer
ren.AddActor( myActor )


# render
renWin.Render()

# initialize and start the interactor
iren.Initialize()
iren.Start()

======================================================


 Thanks and Regards,
Manjunath
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150702/ec91cd1c/attachment.html>


More information about the vtkusers mailing list