VTK
dox/IO/vtkNetCDFCFReader.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 /*=========================================================================
00003 
00004   Program:   Visualization Toolkit
00005   Module:    vtkNetCDFCFReader.h
00006 
00007   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00016 
00017 /*-------------------------------------------------------------------------
00018   Copyright 2008 Sandia Corporation.
00019   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00020   the U.S. Government retains certain rights in this software.
00021 -------------------------------------------------------------------------*/
00022 
00035 #ifndef __vtkNetCDFCFReader_h
00036 #define __vtkNetCDFCFReader_h
00037 
00038 #include "vtkNetCDFReader.h"
00039 
00040 #include <vtkStdString.h> // Used for ivars.
00041 
00042 class vtkStructuredGrid;
00043 
00044 class VTK_IO_EXPORT vtkNetCDFCFReader : public vtkNetCDFReader
00045 {
00046 public:
00047   vtkTypeMacro(vtkNetCDFCFReader, vtkNetCDFReader);
00048   static vtkNetCDFCFReader *New();
00049   virtual void PrintSelf(ostream &os, vtkIndent indent);
00050 
00052 
00056   vtkGetMacro(SphericalCoordinates, int);
00057   vtkSetMacro(SphericalCoordinates, int);
00058   vtkBooleanMacro(SphericalCoordinates, int);
00060 
00062 
00071   vtkGetMacro(VerticalScale, double);
00072   vtkSetMacro(VerticalScale, double);
00073   vtkGetMacro(VerticalBias, double);
00074   vtkSetMacro(VerticalBias, double);
00076 
00078   static int CanReadFile(const char *filename);
00079 
00080 protected:
00081   vtkNetCDFCFReader();
00082   ~vtkNetCDFCFReader();
00083 
00084   int SphericalCoordinates;
00085 
00086   double VerticalScale;
00087   double VerticalBias;
00088 
00089   virtual int RequestDataObject(vtkInformation *request,
00090                                 vtkInformationVector **inputVector,
00091                                 vtkInformationVector *outputVector);
00092 
00093   virtual int RequestData(vtkInformation *request,
00094                           vtkInformationVector **inputVector,
00095                           vtkInformationVector *outputVector);
00096 
00097 //BTX
00099 
00100   virtual int ReadMetaData(int ncFD);
00101   virtual int IsTimeDimension(int ncFD, int dimId);
00102   virtual vtkSmartPointer<vtkDoubleArray> GetTimeValues(int ncFD, int dimId);
00104 //ETX
00105 
00106 //BTX
00107   class vtkDimensionInfo {
00108   public:
00109     vtkDimensionInfo() { };
00110     vtkDimensionInfo(int ncFD, int id);
00111     const char *GetName() const { return this->Name.c_str(); }
00112     enum UnitsEnum {
00113       UNDEFINED_UNITS,
00114       TIME_UNITS,
00115       LATITUDE_UNITS,
00116       LONGITUDE_UNITS,
00117       VERTICAL_UNITS
00118     };
00119     UnitsEnum GetUnits() const { return this->Units; }
00120     vtkSmartPointer<vtkDoubleArray> GetCoordinates() {return this->Coordinates;}
00121     vtkSmartPointer<vtkDoubleArray> GetBounds() { return this->Bounds; }
00122     bool GetHasRegularSpacing() const { return this->HasRegularSpacing; }
00123     double GetOrigin() const { return this->Origin; }
00124     double GetSpacing() const { return this->Spacing; }
00125     vtkSmartPointer<vtkStringArray> GetSpecialVariables() const {
00126       return this->SpecialVariables;
00127     }
00128   protected:
00129     vtkStdString Name;
00130     int DimId;
00131     vtkSmartPointer<vtkDoubleArray> Coordinates;
00132     vtkSmartPointer<vtkDoubleArray> Bounds;
00133     UnitsEnum Units;
00134     bool HasRegularSpacing;
00135     double Origin, Spacing;
00136     vtkSmartPointer<vtkStringArray> SpecialVariables;
00137     int LoadMetaData(int ncFD);
00138   };
00139   class vtkDimensionInfoVector;
00140   friend class vtkDimensionInfoVector;
00141   vtkDimensionInfoVector *DimensionInfo;
00142   vtkDimensionInfo *GetDimensionInfo(int dimension);
00143 
00144   class vtkDependentDimensionInfo {
00145   public:
00146     vtkDependentDimensionInfo() : Valid(false) { };
00147     vtkDependentDimensionInfo(int ncFD, int varId, vtkNetCDFCFReader *parent);
00148     bool GetValid() const { return this->Valid; }
00149     bool GetHasBounds() const { return this->HasBounds; }
00150     vtkSmartPointer<vtkIntArray> GetGridDimensions() const {
00151       return this->GridDimensions;
00152     }
00153     vtkSmartPointer<vtkDoubleArray> GetLongitudeCoordinates() const {
00154       return this->LongitudeCoordinates;
00155     }
00156     vtkSmartPointer<vtkDoubleArray> GetLatitudeCoordinates() const {
00157       return this->LatitudeCoordinates;
00158     }
00159     vtkSmartPointer<vtkStringArray> GetSpecialVariables() const {
00160       return this->SpecialVariables;
00161     }
00162   protected:
00163     bool Valid;
00164     bool HasBounds;
00165     vtkSmartPointer<vtkIntArray> GridDimensions;
00166     vtkSmartPointer<vtkDoubleArray> LongitudeCoordinates;
00167     vtkSmartPointer<vtkDoubleArray> LatitudeCoordinates;
00168     vtkSmartPointer<vtkStringArray> SpecialVariables;
00169     int LoadMetaData(int ncFD, int varId, vtkNetCDFCFReader *parent);
00170     int LoadCoordinateVariable(int ncFD, int varId, vtkDoubleArray *coords);
00171     int LoadBoundsVariable(int ncFD, int varId, vtkDoubleArray *coords);
00172   };
00173   friend class vtkDependentDimensionInfo;
00174   class vtkDependentDimensionInfoVector;
00175   friend class vtkDependentDimensionInfoVector;
00176   vtkDependentDimensionInfoVector *DependentDimensionInfo;
00177 
00178   // Finds the dependent dimension information for the given set of dimensions.
00179   // Returns NULL if no information has been recorded.
00180   vtkDependentDimensionInfo *FindDependentDimensionInfo(vtkIntArray *dims);
00181   vtkDependentDimensionInfo *FindDependentDimensionInfo(const int *dims,
00182                                                         int numDims);
00183 //ETX
00184 
00186 
00189   virtual void IdentifySphericalCoordinates(const int *dimensions,
00190                                             int numDimensions,
00191                                             int &longitudeDim,
00192                                             int &latitudeDim,
00193                                             int &verticalDim);
00195 
00197 
00199   bool CoordinatesAreSpherical(const int *dimensions, int numDimensions)
00200   {
00201     if (this->FindDependentDimensionInfo(dimensions, numDimensions) != NULL)
00202       {
00203       return true;
00204       }
00206 
00207     int longitudeDim, latitudeDim, verticalDim;
00208     this->IdentifySphericalCoordinates(dimensions, numDimensions,
00209                                        longitudeDim, latitudeDim, verticalDim);
00210     if (   (longitudeDim != -1) && (latitudeDim != -1)
00211         && ((numDimensions == 2) || (verticalDim != -1)) )
00212       {
00213       return true;
00214       }
00215     else
00216       {
00217       return false;
00218       }
00219   }
00220 
00222 
00223   virtual bool DimensionsAreForPointData(const int *dimensions,
00224                                          int numDimensions)
00225   {
00226     if (!this->SphericalCoordinates) return true;
00227     if (!this->CoordinatesAreSpherical(dimensions, numDimensions)) return true;
00229 
00230     // If the coordiantes are spherical, then the variable is cell data UNLESS
00231     // the coordinates are given as 2D depenent coordinates without bounds.
00232     vtkDependentDimensionInfo *info
00233       = this->FindDependentDimensionInfo(dimensions, numDimensions);
00234     if (info && !info->GetHasBounds()) return true;
00235 
00236     return false;
00237   }
00238 
00240 
00241   void Add1DSphericalCoordinates(vtkStructuredGrid *structOutput);
00242   void Add2DSphericalCoordinates(vtkStructuredGrid *structOutput);
00244 
00245 
00246 private:
00247   vtkNetCDFCFReader(const vtkNetCDFCFReader &); // Not implemented
00248   void operator=(const vtkNetCDFCFReader &);        // Not implemented
00249 };
00250 
00251 #endif //__vtkNetCDFCFReader_h
00252