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

Cory Quammen cory.quammen at kitware.com
Wed Jul 15 08:54:39 EDT 2015


Hi Manjunath,

Sorry to take so long to get back to you.

Change

mapper.SetScalarModeToUsePointData()

to

mapper.SetScalarModeToUsePointFieldData()

The difference is subtle. The first call says to use the currently "active"
scalar array. VTK has the concept of active attributes, which means that
you can set one array in the point data arrays to be the active scalars.
This concept is being used less and less, but it is still around, so it's
worth knowing about. The call you had says to color by this array, but
apparently there is no active array in the output of the NetCDF reader.

The call I am suggesting (and which I tested with a sample NetCDF file)
says to use the array named by mapper.SelectColorArray(varName) for
coloring.

HTH,
Cory

On Thu, Jul 2, 2015 at 8:25 AM, Manjunath K E <ke.manjunath at gmail.com>
wrote:

> 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
>
>
>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150715/0b4fbb6a/attachment.html>


More information about the vtkusers mailing list