10 #if !defined(GEOGRAPHICLIB_GEOID_HPP)
11 #define GEOGRAPHICLIB_GEOID_HPP 1
19 # pragma warning (push)
20 # pragma warning (disable: 4251 4127)
23 #if !defined(GEOGRAPHICLIB_GEOID_PGM_PIXEL_WIDTH)
31 # define GEOGRAPHICLIB_GEOID_PGM_PIXEL_WIDTH 2
34 namespace GeographicLib {
86 #if GEOGRAPHICLIB_GEOID_PGM_PIXEL_WIDTH != 4
87 typedef unsigned short pixel_t;
88 static const unsigned pixel_size_ = 2;
89 static const unsigned pixel_max_ = 0xffffu;
91 typedef unsigned pixel_t;
92 static const unsigned pixel_size_ = 4;
93 static const unsigned pixel_max_ = 0xffffffffu;
95 static const unsigned stencilsize_ = 12;
96 static const unsigned nterms_ = ((3 + 1) * (3 + 2))/2;
98 static const int c0n_;
99 static const int c0s_;
100 static const int c3_[stencilsize_ * nterms_];
101 static const int c3n_[stencilsize_ * nterms_];
102 static const int c3s_[stencilsize_ * nterms_];
104 std::string _name, _dir, _filename;
106 const real _a, _e2, _degree, _eps;
107 mutable std::ifstream _file;
108 real _rlonres, _rlatres;
109 std::string _description, _datetime;
110 real _offset, _scale, _maxerror, _rmserror;
112 unsigned long long _datastart, _swidth;
115 mutable std::vector< std::vector<pixel_t> > _data;
118 mutable int _xoffset, _yoffset, _xsize, _ysize;
120 mutable int _ix, _iy;
121 mutable real _v00, _v01, _v10, _v11;
122 mutable real _t[nterms_];
123 void filepos(
int ix,
int iy)
const {
125 #
if !(defined(__GNUC__) && __GNUC__ < 4)
130 pixel_size_ * (
unsigned(iy)*_swidth +
unsigned(ix))));
132 real rawval(
int ix,
int iy)
const {
135 else if (ix >= _width)
137 if (_cache && iy >= _yoffset && iy < _yoffset + _ysize &&
138 ((ix >= _xoffset && ix < _xoffset + _xsize) ||
139 (ix + _width >= _xoffset && ix + _width < _xoffset + _xsize))) {
140 return real(_data[iy - _yoffset]
141 [ix >= _xoffset ? ix - _xoffset : ix + _width - _xoffset]);
143 if (iy < 0 || iy >= _height) {
144 iy = iy < 0 ? -iy : 2 * (_height - 1) - iy;
145 ix += (ix < _width/2 ? 1 : -1) * _width/2;
153 unsigned r = ((
unsigned char)(a) << 8) | (
unsigned char)(b);
154 if (pixel_size_ == 4) {
157 r = (r << 16) | ((
unsigned char)(a) << 8) | (
unsigned char)(b);
161 catch (
const std::exception& e) {
166 std::string err(
"Error reading ");
174 real height(real lat, real lon,
bool gradp,
175 real& grade, real& gradn)
const;
189 ELLIPSOIDTOGEOID = -1,
198 GEOIDTOELLIPSOID = 1,
225 explicit Geoid(
const std::string& name,
const std::string& path =
"",
226 bool cubic =
true,
bool threadsafe =
false);
270 void CacheClear()
const;
291 return height(lat, lon,
false, gradn, grade);
314 return height(lat, lon,
true, gradn, grade);
335 return h +
real(d) * height(lat, lon,
true, gradn, grade);
352 const std::string&
DateTime()
const {
return _datetime; }
357 const std::string&
GeoidFile()
const {
return _filename; }
373 const std::string Interpolation()
const
374 {
return std::string(_cubic ?
"cubic" :
"bilinear"); }
418 bool Cache()
const {
return _cache; }
424 return _cache ? ((_xoffset + (_xsize == _width ? 0 : _cubic)
425 + _width/2) % _width - _width/2) / _rlonres :
435 (_xsize - (_xsize == _width ? 0 : 1 + 2 * _cubic)) / _rlonres :
443 return _cache ? 90 - (_yoffset + _cubic) / _rlatres : 0;
451 return _cache ? 90 - ( _yoffset + _ysize - 1 - _cubic) / _rlatres : 0;
490 static std::string DefaultGeoidPath();
500 static std::string DefaultGeoidName();
506 #if defined(_MSC_VER)
507 # pragma warning (pop)
510 #endif // GEOGRAPHICLIB_GEOID_HPP