[vtkusers] NetCDF reader/writer for VTK
Chris Hood
Chris.Hood at noaa.gov
Wed Feb 11 18:47:13 EST 2004
Here's a simplified version of what I use in Java. It's reads the points
into a vtkPoints the puts it into a vtkStructuredGrid(sGrid). The data is
read into a vtkFloatArray, which is also put into the sGrid. The changes
for read multiple value per point into one array (such as a vector) are
given in the code.
//General Variable Declarations
vtkStructuredGrid sGrid = new vtkStructuredGrid();
Array ncArray1;
Index ncIndex1;
// Set the input file
NetcdfFile dataFile = new NetcdfFile(inputFile);
// Read the points (I left out two dimentions)
vtkPoints points = new vtkPoints();
ncArray1 = dataFile.findVariable("X").read().reduce();
ncIndex1 = ncArray1.getIndex();
int [] size = ncArray1.getShape();
rad = new float[(size[0]];
for(i=0; i<size[0]; i++) rad[i] = ncArray1.getFloat(ncIndex1.set(i));
// Put points into Strucuterd Grid
points.SetNumberOfPoints(noOfPoints[3]); // noOfPoint 0, 1 & 2
are the dimensions, 3 is the total # of points
sGrid.SetDimensions(noOfPoints[0], noOfPoints[1], noOfPoints[2]);
sGrid.SetPoints(points);
// Read the data
vtkFloatArray arrayDensity = new vtkFloatArray();
arrayDensity.SetNumberOfValues(noOfPoints[3]);
ncArray1 = dataFile.findVariable("D").read().reduce();
ncIndex1 = ncArray1.getIndex();
for (k=0; i<noOfPoints[2]; k++) {
for (j=0; i<noOfPoints[1]; j++) {
for (i=0; i<noOfPoints[0]; i++) {
arrayDensity.SetValue(i, ncArray1.getFloat(ncIndex1.set(i, j,
k))); //
// when reading a vector use:
// arrayDensity.SetTuple3(p, value1, value2, value3);
}
arrayDensity.SetName("Density");
sGrid.GetPointData().AddArray(arrayDensity);
At 10:28 AM 2/3/2004, you wrote:
>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.
____________________________________
Chris Hood
Graduate Student Research Assistant
University of Colorado, Boulder
Space Environment Center - NOAA
More information about the vtkusers
mailing list