VTK  9.7.1
vtkNetCDFCFReader.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-LANL-California-USGov
4 
18 #ifndef vtkNetCDFCFReader_h
19 #define vtkNetCDFCFReader_h
20 
21 #include "vtkIONetCDFModule.h" // For export macro
22 #include "vtkNetCDFReader.h"
23 
24 #include "vtkStdString.h" // Used for ivars.
25 
26 VTK_ABI_NAMESPACE_BEGIN
27 class vtkImageData;
28 class vtkPoints;
29 class vtkRectilinearGrid;
30 class vtkStructuredGrid;
32 
33 class VTKIONETCDF_EXPORT vtkNetCDFCFReader : public vtkNetCDFReader
34 {
35 public:
37  static vtkNetCDFCFReader* New();
38  void PrintSelf(ostream& os, vtkIndent indent) override;
39 
41 
46  vtkGetMacro(SphericalCoordinates, vtkTypeBool);
47  vtkSetMacro(SphericalCoordinates, vtkTypeBool);
48  vtkBooleanMacro(SphericalCoordinates, vtkTypeBool);
50 
52 
63  vtkGetMacro(VerticalScale, double);
64  vtkSetMacro(VerticalScale, double);
65  vtkGetMacro(VerticalBias, double);
66  vtkSetMacro(VerticalBias, double);
68 
70 
77  vtkGetMacro(OutputType, int);
78  virtual void SetOutputType(int type);
79  void SetOutputTypeToAutomatic() { this->SetOutputType(-1); }
80  void SetOutputTypeToImage() { this->SetOutputType(VTK_IMAGE_DATA); }
81  void SetOutputTypeToRectilinear() { this->SetOutputType(VTK_RECTILINEAR_GRID); }
82  void SetOutputTypeToStructured() { this->SetOutputType(VTK_STRUCTURED_GRID); }
83  void SetOutputTypeToUnstructured() { this->SetOutputType(VTK_UNSTRUCTURED_GRID); }
85 
89  static int CanReadFile(VTK_FILEPATH const char* filename);
90 
92 
96  void SetTimeDimensionName(const char* name);
97  void SetLatitudeDimensionName(const char* name);
98  void SetLongitudeDimensionName(const char* name);
99  void SetVerticalDimensionName(const char* name);
101 
103 
107  const char* GetTimeDimensionName();
108  const char* GetLatitudeDimensionName();
109  const char* GetLongitudeDimensionName();
110  const char* GetVerticalDimensionName();
112 
113 protected:
115  ~vtkNetCDFCFReader() override;
116 
118 
120  double VerticalBias;
121 
123 
124  int RequestDataObject(vtkInformation* request, vtkInformationVector** inputVector,
125  vtkInformationVector* outputVector) override;
126 
127  int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
128  vtkInformationVector* outputVector) override;
129 
130  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
131  vtkInformationVector* outputVector) override;
132 
134 
137  int ReadMetaData(int ncFD) override;
138  int IsTimeDimension(int ncFD, int dimId) override;
139  vtkSmartPointer<vtkDoubleArray> GetTimeValues(int ncFD, int dimId) override;
141 
143  {
144  public:
145  vtkDimensionInfo() = default;
146  vtkDimensionInfo(vtkNetCDFAccessor* accessor, int ncFD, int id,
147  const std::vector<std::string>& dimensionNames);
148 
149  const char* GetName() const { return this->Name.c_str(); }
151  {
157  NUMBER_OF_UNITS
158  };
159  UnitsEnum GetUnits() const { return this->Units; }
160  vtkSmartPointer<vtkDoubleArray> GetCoordinates() { return this->Coordinates; }
161  vtkSmartPointer<vtkDoubleArray> GetBounds() { return this->Bounds; }
162  bool GetHasRegularSpacing() const { return this->HasRegularSpacing; }
163  double GetOrigin() const { return this->Origin; }
164  double GetSpacing() const { return this->Spacing; }
165  vtkSmartPointer<vtkStringArray> GetSpecialVariables() const { return this->SpecialVariables; }
166  void SetUnitsIfSpecialDimensionOverriden(UnitsEnum unit, const char* name);
167 
168  protected:
169  vtkNetCDFAccessor* Accessor = nullptr;
171  int DimId;
176  double Origin, Spacing;
178  std::vector<std::string> SpecialDimensionOverrideNames;
179  int LoadMetaData(int ncFD);
180  };
182  {
183  this->SpecialDimensionOverrideNames[dim] = name;
184  }
185  const char* GetSpecialDimensionName(vtkDimensionInfo::UnitsEnum dim);
186 
187  class vtkDimensionInfoVector;
188  friend class vtkDimensionInfoVector;
189  vtkDimensionInfoVector* DimensionInfo;
190  vtkDimensionInfo* GetDimensionInfo(int dimension);
191 
193  {
194  public:
196  : Accessor(accessor)
197  , Valid(false)
198  {
199  }
201  vtkNetCDFAccessor* accessor, int ncFD, int varId, vtkNetCDFCFReader* parent);
202  bool GetValid() const { return this->Valid; }
203  bool GetHasBounds() const { return this->HasBounds; }
204  bool GetCellsUnstructured() const { return this->CellsUnstructured; }
205  vtkSmartPointer<vtkIntArray> GetGridDimensions() const { return this->GridDimensions; }
207  {
208  return this->LongitudeCoordinates;
209  }
211  {
212  return this->LatitudeCoordinates;
213  }
214  vtkSmartPointer<vtkStringArray> GetSpecialVariables() const { return this->SpecialVariables; }
215 
216  protected:
218  bool Valid;
219  bool HasBounds;
225  int LoadMetaData(int ncFD, int varId, vtkNetCDFCFReader* parent);
226  int LoadCoordinateVariable(int ncFD, int varId, vtkDoubleArray* coords);
227  int LoadBoundsVariable(int ncFD, int varId, vtkDoubleArray* coords);
228  int LoadUnstructuredBoundsVariable(int ncFD, int varId, vtkDoubleArray* coords);
229  };
231  class vtkDependentDimensionInfoVector;
232  friend class vtkDependentDimensionInfoVector;
233  vtkDependentDimensionInfoVector* DependentDimensionInfo;
234 
235  // Finds the dependent dimension information for the given set of dimensions.
236  // Returns nullptr if no information has been recorded.
237  vtkDependentDimensionInfo* FindDependentDimensionInfo(vtkIntArray* dims);
238 
244  virtual void IdentifySphericalCoordinates(
245  vtkIntArray* dimensions, int& longitudeDim, int& latitudeDim, int& verticalDim);
246 
248  {
257  COORDS_SPHERICAL_PSIDED_CELLS
258  };
259 
265  CoordinateTypesEnum CoordinateType(vtkIntArray* dimensions);
266 
270  bool DimensionsAreForPointData(vtkIntArray* dimensions) override;
271 
277  void ExtentForDimensionsAndPiece(
278  int pieceNumber, int numberOfPieces, int ghostLevels, int extent[6]);
279 
283  void GetUpdateExtentForOutput(vtkDataSet* output, int extent[6]) override;
284 
286 
289  void AddRectilinearCoordinates(vtkImageData* imageOutput);
290  void AddRectilinearCoordinates(vtkRectilinearGrid* rectilinearOutput);
291  void FakeRectilinearCoordinates(vtkRectilinearGrid* rectilinearOutput);
292  void Add1DRectilinearCoordinates(vtkPoints* points, const int extent[6]);
293  void Add2DRectilinearCoordinates(vtkPoints* points, const int extent[6]);
294  void Add1DRectilinearCoordinates(vtkStructuredGrid* structuredOutput);
295  void Add2DRectilinearCoordinates(vtkStructuredGrid* structuredOutput);
296  void FakeStructuredCoordinates(vtkStructuredGrid* structuredOutput);
297  void Add1DRectilinearCoordinates(vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
298  void Add2DRectilinearCoordinates(vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
300 
302 
305  void Add1DSphericalCoordinates(vtkPoints* points, const int extent[6]);
306  void Add2DSphericalCoordinates(vtkPoints* points, const int extent[6]);
307  void Add1DSphericalCoordinates(vtkStructuredGrid* structuredOutput);
308  void Add2DSphericalCoordinates(vtkStructuredGrid* structuredOutput);
309  void Add1DSphericalCoordinates(vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
310  void Add2DSphericalCoordinates(vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
312 
316  void AddStructuredCells(vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
317 
319 
322  void AddUnstructuredRectilinearCoordinates(
323  vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
324  void AddUnstructuredSphericalCoordinates(
325  vtkUnstructuredGrid* unstructuredOutput, const int extent[6]);
327 
328  std::vector<std::string> SpecialDimensionOverrideNames;
329 
330 private:
331  vtkNetCDFCFReader(const vtkNetCDFCFReader&) = delete;
332  void operator=(const vtkNetCDFCFReader&) = delete;
333 };
334 
335 VTK_ABI_NAMESPACE_END
336 #endif // vtkNetCDFCFReader_h
std::vector< std::string > SpecialDimensionOverrideNames
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
vtkSmartPointer< vtkDoubleArray > Coordinates
vtkSmartPointer< vtkDoubleArray > GetCoordinates()
a dataset that is topologically regular with variable spacing in the three coordinate directions ...
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
vtkSmartPointer< vtkDoubleArray > LatitudeCoordinates
void SetOutputTypeToStructured()
Set/get the data type of the output.
Store vtkAlgorithm input/output information.
Reads netCDF files that follow the CF convention.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
std::vector< std::string > SpecialDimensionOverrideNames
vtkDimensionInfoVector * DimensionInfo
vtkSmartPointer< vtkStringArray > SpecialVariables
void SetOutputTypeToUnstructured()
Set/get the data type of the output.
void SetOutputTypeToImage()
Set/get the data type of the output.
virtual int ReadMetaData(int ncFD)
Reads meta data and populates ivars.
A superclass for reading netCDF files.
dynamic, self-adjusting array of double
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int RequestDataObject(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
This is called by the superclass.
int vtkTypeBool
Definition: vtkABI.h:64
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:35
void SetOutputTypeToAutomatic()
Set/get the data type of the output.
static vtkNetCDFReader * New()
virtual void GetUpdateExtentForOutput(vtkDataSet *output, int extent[6])
Retrieves the update extent for the output object.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkSmartPointer< vtkDoubleArray > GetLatitudeCoordinates() const
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
dataset represents arbitrary combinations of all possible cell types
vtkSmartPointer< vtkStringArray > GetSpecialVariables() const
virtual int IsTimeDimension(int ncFD, int dimId)
Determines whether the given variable is a time dimension.
vtkSmartPointer< vtkStringArray > SpecialVariables
vtkTypeBool SphericalCoordinates
vtkSmartPointer< vtkDoubleArray > GetBounds()
virtual vtkSmartPointer< vtkDoubleArray > GetTimeValues(int ncFD, int dimId)
Given a dimension already determined to be a time dimension (via a call to IsTimeDimension) returns a...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkSmartPointer< vtkDoubleArray > LongitudeCoordinates
#define VTK_FILEPATH
vtkDependentDimensionInfo(vtkNetCDFAccessor *accessor)
vtkDependentDimensionInfoVector * DependentDimensionInfo
topologically regular array of data
void SetSpecialDimensionOverrideName(vtkDimensionInfo::UnitsEnum dim, const char *name)
void SetOutputTypeToRectilinear()
Set/get the data type of the output.
Store zero or more vtkInformation instances.
vtkSmartPointer< vtkDoubleArray > GetLongitudeCoordinates() const
Cell is in a good state.
vtkSmartPointer< vtkDoubleArray > Bounds
vtkSmartPointer< vtkIntArray > GridDimensions
represent and manipulate 3D points
Definition: vtkPoints.h:30
virtual bool DimensionsAreForPointData(vtkIntArray *dimensions)
Called internally to determine whether a variable with the given set of dimensions should be loaded a...
vtkSmartPointer< vtkStringArray > GetSpecialVariables() const
vtkSmartPointer< vtkIntArray > GetGridDimensions() const