forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkNetCDFCFReader.h
241 lines (207 loc) · 8.75 KB
/
vtkNetCDFCFReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// -*- c++ -*-
/*=========================================================================
Program: Visualization Toolkit
Module: vtkNetCDFCFReader.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
// .NAME vtkNetCDFCFReader
//
// .SECTION Description
//
// Reads netCDF files that follow the CF convention. Details on this convention
// can be found at <http://cf-pcmdi.llnl.gov/>.
//
#ifndef __vtkNetCDFCFReader_h
#define __vtkNetCDFCFReader_h
#include "vtkNetCDFReader.h"
#include <vtkStdString.h> // Used for ivars.
class vtkStructuredGrid;
class VTK_IO_EXPORT vtkNetCDFCFReader : public vtkNetCDFReader
{
public:
vtkTypeMacro(vtkNetCDFCFReader, vtkNetCDFReader);
static vtkNetCDFCFReader *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// If on (the default), then 3D data with latitude/longitude dimensions
// will be read in as curvilinear data shaped like spherical coordinates.
// If false, then the data will always be read in Cartesian coordinates.
vtkGetMacro(SphericalCoordinates, int);
vtkSetMacro(SphericalCoordinates, int);
vtkBooleanMacro(SphericalCoordinates, int);
// Description:
// The scale and bias of the vertical component of spherical coordinates. It
// is common to write the vertical component with respect to something other
// than the center of the sphere (for example, the surface). In this case, it
// might be necessary to scale and/or bias the vertical height. The height
// will become height*scale + bias. Keep in mind that if the positive
// attribute of the vertical dimension is down, then the height is negated.
// By default the scale is 1 and the bias is 0 (that is, no change). The
// scaling will be adjusted if it results in invalid (negative) vertical
// values.
vtkGetMacro(VerticalScale, double);
vtkSetMacro(VerticalScale, double);
vtkGetMacro(VerticalBias, double);
vtkSetMacro(VerticalBias, double);
// Description:
// Returns true if the given file can be read.
static int CanReadFile(const char *filename);
protected:
vtkNetCDFCFReader();
~vtkNetCDFCFReader();
int SphericalCoordinates;
double VerticalScale;
double VerticalBias;
virtual int RequestDataObject(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
virtual int RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
//BTX
// Description:
// Interprets the special conventions of COARDS.
virtual int ReadMetaData(int ncFD);
virtual int IsTimeDimension(int ncFD, int dimId);
virtual vtkSmartPointer<vtkDoubleArray> GetTimeValues(int ncFD, int dimId);
//ETX
//BTX
class vtkDimensionInfo {
public:
vtkDimensionInfo() { };
vtkDimensionInfo(int ncFD, int id);
const char *GetName() const { return this->Name.c_str(); }
enum UnitsEnum {
UNDEFINED_UNITS,
TIME_UNITS,
LATITUDE_UNITS,
LONGITUDE_UNITS,
VERTICAL_UNITS
};
UnitsEnum GetUnits() const { return this->Units; }
vtkSmartPointer<vtkDoubleArray> GetCoordinates() {return this->Coordinates;}
vtkSmartPointer<vtkDoubleArray> GetBounds() { return this->Bounds; }
bool GetHasRegularSpacing() const { return this->HasRegularSpacing; }
double GetOrigin() const { return this->Origin; }
double GetSpacing() const { return this->Spacing; }
vtkSmartPointer<vtkStringArray> GetSpecialVariables() const {
return this->SpecialVariables;
}
protected:
vtkStdString Name;
int DimId;
vtkSmartPointer<vtkDoubleArray> Coordinates;
vtkSmartPointer<vtkDoubleArray> Bounds;
UnitsEnum Units;
bool HasRegularSpacing;
double Origin, Spacing;
vtkSmartPointer<vtkStringArray> SpecialVariables;
int LoadMetaData(int ncFD);
};
class vtkDimensionInfoVector;
friend class vtkDimensionInfoVector;
vtkDimensionInfoVector *DimensionInfo;
vtkDimensionInfo *GetDimensionInfo(int dimension);
class vtkDependentDimensionInfo {
public:
vtkDependentDimensionInfo() : Valid(false) { };
vtkDependentDimensionInfo(int ncFD, int varId, vtkNetCDFCFReader *parent);
bool GetValid() const { return this->Valid; }
bool GetHasBounds() const { return this->HasBounds; }
vtkSmartPointer<vtkIntArray> GetGridDimensions() const {
return this->GridDimensions;
}
vtkSmartPointer<vtkDoubleArray> GetLongitudeCoordinates() const {
return this->LongitudeCoordinates;
}
vtkSmartPointer<vtkDoubleArray> GetLatitudeCoordinates() const {
return this->LatitudeCoordinates;
}
vtkSmartPointer<vtkStringArray> GetSpecialVariables() const {
return this->SpecialVariables;
}
protected:
bool Valid;
bool HasBounds;
vtkSmartPointer<vtkIntArray> GridDimensions;
vtkSmartPointer<vtkDoubleArray> LongitudeCoordinates;
vtkSmartPointer<vtkDoubleArray> LatitudeCoordinates;
vtkSmartPointer<vtkStringArray> SpecialVariables;
int LoadMetaData(int ncFD, int varId, vtkNetCDFCFReader *parent);
int LoadCoordinateVariable(int ncFD, int varId, vtkDoubleArray *coords);
int LoadBoundsVariable(int ncFD, int varId, vtkDoubleArray *coords);
};
friend class vtkDependentDimensionInfo;
class vtkDependentDimensionInfoVector;
friend class vtkDependentDimensionInfoVector;
vtkDependentDimensionInfoVector *DependentDimensionInfo;
// Finds the dependent dimension information for the given set of dimensions.
// Returns NULL if no information has been recorded.
vtkDependentDimensionInfo *FindDependentDimensionInfo(vtkIntArray *dims);
vtkDependentDimensionInfo *FindDependentDimensionInfo(const int *dims,
int numDims);
//ETX
// Description:
// Given the list of dimensions, identify the longitude, latitude, and
// vertical dimensions. -1 is returned for any not found. The results depend
// on the values in this->DimensionInfo.
virtual void IdentifySphericalCoordinates(const int *dimensions,
int numDimensions,
int &longitudeDim,
int &latitudeDim,
int &verticalDim);
// Description:
// Convienience function that returns true if the given dimensions can be
// used as spherical coordinates, false otherwise.
bool CoordinatesAreSpherical(const int *dimensions, int numDimensions)
{
if (this->FindDependentDimensionInfo(dimensions, numDimensions) != NULL)
{
return true;
}
int longitudeDim, latitudeDim, verticalDim;
this->IdentifySphericalCoordinates(dimensions, numDimensions,
longitudeDim, latitudeDim, verticalDim);
if ( (longitudeDim != -1) && (latitudeDim != -1)
&& ((numDimensions == 2) || (verticalDim != -1)) )
{
return true;
}
else
{
return false;
}
}
// Description:
// Returns false for spherical dimensions, which should use cell data.
virtual bool DimensionsAreForPointData(const int *dimensions,
int numDimensions)
{
if (!this->SphericalCoordinates) return true;
if (!this->CoordinatesAreSpherical(dimensions, numDimensions)) return true;
// If the coordiantes are spherical, then the variable is cell data UNLESS
// the coordinates are given as 2D depenent coordinates without bounds.
vtkDependentDimensionInfo *info
= this->FindDependentDimensionInfo(dimensions, numDimensions);
if (info && !info->GetHasBounds()) return true;
return false;
}
// Description:
// Internal methods for setting spherical coordiantes.
void Add1DSphericalCoordinates(vtkStructuredGrid *structOutput);
void Add2DSphericalCoordinates(vtkStructuredGrid *structOutput);
private:
vtkNetCDFCFReader(const vtkNetCDFCFReader &); // Not implemented
void operator=(const vtkNetCDFCFReader &); // Not implemented
};
#endif //__vtkNetCDFCFReader_h