<div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div><div><div><div>Hi,<br></div><div><br></div>I am working on ocean data visualization. I have data in netCdf format.<br></div></div></div>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. <br><br>I have created lookup table for color mapping, but it is not working.. Please help me.<br></div><div>Following is my code...<br></div><div dir="ltr"><div>========================================================<br>from vtk import *<br><br>reader = vtkNetCDFCFReader()<br>reader.SetFileName("<a href="http://3d.nc" target="_blank">3d.nc</a>")<br>reader.SphericalCoordinatesOff()<br>#reader.SetOutputTypeToRectilinear()<br>reader.SetOutputType(6)#SetOutputTypeToRectilinear()<br>reader.SetReplaceFillValueWithNan(1)<br>reader.UpdateMetaData()<br>reader.Update()<br>reader.GetOutput().UpdateInformation()<br>output = reader.GetOutput()<br><br># find the range of the point scalars<br>a,b = reader.GetOutput().GetPointData().GetArray("SAL").GetRange()<br>nm = reader.GetOutput().GetPointData().GetArray("SAL").GetName()<br><br># show how to print a string in python, it is similar to C-style sprintf<br>print "Range of %s: %4.2f-%4.2f" %(nm,a,b)<br><br># transfer function (lookup table) for mapping point scalar data<br># to colors (parent class is vtkScalarsToColors)<br>lut = vtk.vtkColorTransferFunction()<br>lut.AddRGBPoint(a, 0.0, 0.0, 1.0)<br>lut.AddRGBPoint(a+(b-a)/4, 0.0, 0.5, 0.5)<br>lut.AddRGBPoint(a+(b-a)/2, 0.0, 1.0, 0.0)<br>lut.AddRGBPoint(b-(b-a)/4, 0.5, 0.5, 0.0)<br>lut.AddRGBPoint(b, 1.0, 0.0, 0.0)<br>lut.SetAlpha(0.5)<br><br>mapper = vtkDataSetMapper()<br>mapper.SetInputConnection(reader.GetOutputPort())<br>mapper.SetScalarModeToUsePointData()<br>mapper.SetLookupTable(lut)<br>mapper.SetScalarRange(a,b)<br>mapper.SelectColorArray("SAL");<br><br># the actor<br>myActor = vtkActor()<br>myActor.SetMapper( mapper )<br><br># renderer and render window <br>ren = vtkRenderer()<br>ren.SetBackground(1, 1, 1)<br>renWin = vtk.vtkRenderWindow()<br>renWin.SetSize(512, 512)<br>renWin.AddRenderer( ren )<br><br># render window interactor<br>iren = vtkRenderWindowInteractor()<br>iren.SetRenderWindow( renWin )<br><br># add the actors to the renderer<br>ren.AddActor( myActor )<br><br><br># render<br>renWin.Render()<br><br># initialize and start the interactor<br>iren.Initialize()<br>iren.Start()<br><br>======================================================<br><br><br clear="all"><div><div><div><div><div><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><font color="#ff0000"> </font><font color="#ff6600">Thanks and Regards,</font></div><font color="#3366ff">Manjunath</font><br></div><div dir="ltr"><div><font color="#3366ff"> </font></div></div></div></div></div></div></div></div></div></div>
</div></div></div></div></div></div>
</div><br></div>
</div><br></div>