Main Page   Class Hierarchy   Compound List   File List   Compound Members  

ElevationGrid.h

00001 //
00002 // vtElevationGrid.h
00003 //
00004 // Copyright (c) 2001 Virtual Terrain Project.
00005 // Free for all uses, see license.txt for details.
00006 //
00007 
00008 #ifndef ELEVATIONGRIDH
00009 #define ELEVATIONGRIDH
00010 
00011 #include <stdio.h>
00012 #include <limits.h>         // for SHRT_MIN
00013 #include "MathTypes.h"
00014 #include "Projections.h"
00015 #include "vtDIB.h"
00016 
00017 #define INVALID_ELEVATION   SHRT_MIN
00018 
00029 class vtElevationGrid 
00030 {
00031 public:
00032     vtElevationGrid();
00033     vtElevationGrid(DRECT area, int iColumns, int iRows, bool bFloat, vtProjection proj);
00034     ~vtElevationGrid();
00035 
00036     bool ConvertProjection(vtElevationGrid *pOld, vtProjection &NewProj, void progress_callback(int) = NULL);
00037 
00038     // Load
00039     bool LoadFromDEM(const char *szFileName, void progress_callback(int) = NULL);
00040     bool LoadFromASC(const char *szFileName, void progress_callback(int) = NULL);
00041     bool LoadFromTerragen(const char *szFileName, void progress_callback(int) = NULL);
00042     bool LoadFromCDF(const char *szFileName, void progress_callback(int) = NULL);
00043     bool LoadFromDTED(const char *szFileName, void progress_callback(int) = NULL);
00044     bool LoadFromGTOPO30(const char *szFileName, void progress_callback(int) = NULL);
00045     bool LoadFromGRD(const char *szFileName, void progress_callback(int) = NULL);
00046     bool LoadFromPGM(const char *szFileName, void progress_callback(int) = NULL);
00047     bool LoadFromRAW(const char *szFileName, int width, int height,
00048         int bytes_per_element, float vertical_units);
00049     bool LoadFromBT(const char *szFileName, void progress_callback(int) = NULL);
00050     bool LoadBTHeader(FILE *fp);
00051 
00052     // Use GDAL to read a file
00053     bool LoadWithGDAL(const char *szFileName, void progress_callback(int));
00054 
00055     // Save
00056     void SaveToTerragen(FILE *fp);
00057     void SaveToBT(FILE *fp);
00058 
00059     void ComputeHeightExtents();
00060     void GetHeightExtents(float &fMinHeight, float &fMaxHeight);
00061     void GetDimensions(int &nColumns, int &nRows);
00062     DPoint2 GetSpacing();
00063 
00066     bool ContainsPoint(float x, float y)
00067     {
00068         return (m_area.left < x && x < m_area.right &&
00069                 m_area.bottom < y && y < m_area.top);
00070     }
00071 
00072     // Set/Get height values
00073     void  SetFValue(int i, int j, float value);
00074     void  SetValue(int i, int j, short value);
00075     int   GetValue(int i, int j);   // returns height value as a integer
00076     float GetFValue(int i, int j);  // returns height value as a float
00077 
00078     float GetClosestValue(double x, double y);
00079     float GetFilteredValue(double x, double y);
00080 
00081     // Accessors
00083     char *GetDEMName()  { return m_szOriginalDEMName; }
00084 
00086     DRECT &GetGridExtents() { return m_area; }
00087 
00089     DRECT GetAreaExtents();
00090 
00092     void SetGridExtents(DRECT &ext) { m_area = ext; }
00093 
00097     bool  IsFloatMode() { return m_bFloatMode; }
00098 
00099     void ColorDibFromElevation1(vtDIB *pDIB, RGBi color_ocean);
00100 
00101     vtProjection &GetProjection() { return m_proj; }
00102 
00103     void GetCorners(DLine2 &line, bool bGeo);
00104     void SetCorners(DLine2 &line);
00105 
00106 protected:
00107     DRECT   m_area;     // bounds in the original data space
00108     int     m_iColumns;
00109     int     m_iRows;
00110     bool    m_bFloatMode;
00111     short   *m_pData;
00112     float   *m_pFData;
00113 
00114     void ComputeExtentsFromCorners();
00115     void ComputeCornersFromExtents();
00116 
00117     DPoint2     m_Corners[4];       // data corners, in the projection of this terrain
00118 
00119     vtProjection    m_proj;
00120 
00121 private:
00122     // minimum and maximum height values for the whole grid
00123     float   m_fMinHeight, m_fMaxHeight;
00124     char    m_szOriginalDEMName[41];
00125 
00126     void    AllocateArray();
00127 
00128     // only used by DEM reader code
00129     double  m_fVMeters;
00130     double  m_fGRes;
00131     int     m_iDataSize;
00132 };
00133 
00135 
00136 //  Header structure for a GTOPO30 DEM header file
00137 typedef struct  
00138 {
00139     char            ByteOrder[30];      //  Byte order in which image pixel values are stored 
00140                                         //      M = Motorola byte order (MSB first)
00141     char            Layout[30];         //  Organization of the bands in the file
00142                                         //      BIL = Band interleaved by line (DEM = single band image)
00143     unsigned long   NumRows;            //  Number of rows in the image
00144     unsigned long   NumCols;            //  Number of columns in the image
00145     char            Bands[30];          //  Number of spectral bands in the image (1 for DEM)
00146     char            Bits[30];           //  Number of bits per pixel (16 for DEM)
00147     char            BandRowBytes[30];   //  Number of bytes per band per row 
00148                                         //      (twice the number of columns for 16 bit DEM)
00149     char            TotalRowBytes[30];  //  Total number of bytes of data per row
00150                                         //      (twice the number of columns for 16 bit DEM)
00151     char            BandGapBytes[30];   //  Number of bytes between bands in a BSQ format
00152                                         //      (0 for DEM)
00153     short           NoData;             //  Value used for no data or masking purposes
00154     double          ULXMap;             //  Longitude of the center of the upper left pixel in decimal degrees.     
00155     double          ULYMap;             //  Latitude of the center of the upper left pixel in decimal degrees.      
00156     double          XDim;               //  x dimension of a pixel in geographic units (decimal degrees).       
00157     double          YDim;               //  y dimension of a pixel in geographic units (decimal degrees).
00158 } GTOPOHeader;
00159 
00160 #ifndef max
00161 #define max(a,b)            (((a) > (b)) ? (a) : (b))
00162 #endif
00163 
00164 #ifndef min
00165 #define min(a,b)            (((a) < (b)) ? (a) : (b))
00166 #endif
00167 
00168 #endif  // ELEVATIONGRIDH
00169 

Generated at Fri Aug 17 14:40:42 2001 for vtdata library by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000