00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ELEVATIONGRIDH
00009 #define ELEVATIONGRIDH
00010
00011 #include <stdio.h>
00012 #include <limits.h>
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
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
00053 bool LoadWithGDAL(const char *szFileName, void progress_callback(int));
00054
00055
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
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);
00076 float GetFValue(int i, int j);
00077
00078 float GetClosestValue(double x, double y);
00079 float GetFilteredValue(double x, double y);
00080
00081
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;
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];
00118
00119 vtProjection m_proj;
00120
00121 private:
00122
00123 float m_fMinHeight, m_fMaxHeight;
00124 char m_szOriginalDEMName[41];
00125
00126 void AllocateArray();
00127
00128
00129 double m_fVMeters;
00130 double m_fGRes;
00131 int m_iDataSize;
00132 };
00133
00135
00136
00137 typedef struct
00138 {
00139 char ByteOrder[30];
00140
00141 char Layout[30];
00142
00143 unsigned long NumRows;
00144 unsigned long NumCols;
00145 char Bands[30];
00146 char Bits[30];
00147 char BandRowBytes[30];
00148
00149 char TotalRowBytes[30];
00150
00151 char BandGapBytes[30];
00152
00153 short NoData;
00154 double ULXMap;
00155 double ULYMap;
00156 double XDim;
00157 double YDim;
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