[vtkusers] Re: NetCDF reader/writer for VTK

Patrick Brockmann Patrick.Brockmann at cea.fr
Wed Feb 4 05:15:35 EST 2004


Bernd Hentschel wrote:

>>Hi all,
>>
>>I'm currently working on a project involving CFD data (curvilinear
>>grids) given in NetCDF-format. Since (to my knowledge) vtk can not
>>directly access these data sets I will need custom
>>vtkDataReader/vtkDataWriter classes which convert the content of the
>>given data files to vtk-structures and v.v. My question is if there is
>>anybody here who has done this before or who knows of an implementation
>>of such a reader/writer.
>
Hi Bernd,

The python module CDMS can do this very well.
See the CDAT site at http://esg.llnl.gov/cdat/

The CDMS (Climate Data Management System) has been designed for
climate studies but this module has a lot of reading/writing capacities too.
Formats netCDF, HDF, GrADS/GRIB (GRIB with a GrADS control file), or
PCMDI DRS are readable.

After the reading, this is just a matter of building the rigth VTK 
structure.
Here is a piece a code to build a polydata from a curvilinear grid:

#--------------------------------------------
var, x,y,z are vectors read with CDMS with values, cartesian positions 
of vertex of each cell

#--------------------------------------------
polydata = vtkPolyData()
points = vtkPoints()
polys = vtkCellArray()
n_points=0
for i in range(Numeric.size(var)):
                polys.InsertNextCell(nvertex)
                for v in range(nvertex):
                        points.InsertPoint(n_points,x[i,v],y[i,v],z[i,v])
                        polys.InsertCellPoint(n_points)
                        n_points=n_points+1
polydata.SetPoints(points)
polydata.SetPolys(polys)
#--------------------------------------------
celldata = vtkFloatArray()
for i in range(Numeric.size(var)):
                celldata.InsertNextValue(var[i])
polydata.GetCellData().SetScalars(celldata)
#--------------------------------------------

You can have a look to example plots
using this CDMS and VTK strategy at:
http://dods.ipsl.jussieu.fr/brocksce/vtk_ex/

Hope that's help.
-- Patrick





More information about the vtkusers mailing list