Geoid.hpp
Go to the documentation of this file.
1 
10 #if !defined(GEOGRAPHICLIB_GEOID_HPP)
11 #define GEOGRAPHICLIB_GEOID_HPP 1
12 
13 #include <vector>
14 #include <fstream>
16 
17 #if defined(_MSC_VER)
18 // Squelch warnings about dll vs vector and constant conditional expressions
19 # pragma warning (push)
20 # pragma warning (disable: 4251 4127)
21 #endif
22 
23 #if !defined(GEOGRAPHICLIB_GEOID_PGM_PIXEL_WIDTH)
24 
31 # define GEOGRAPHICLIB_GEOID_PGM_PIXEL_WIDTH 2
32 #endif
33 
34 namespace GeographicLib {
35 
83  private:
84  typedef Math::real real;
85 #if GEOGRAPHICLIB_GEOID_PGM_PIXEL_WIDTH != 4
86  typedef unsigned short pixel_t;
87  static const unsigned pixel_size_ = 2;
88  static const unsigned pixel_max_ = 0xffffu;
89 #else
90  typedef unsigned pixel_t;
91  static const unsigned pixel_size_ = 4;
92  static const unsigned pixel_max_ = 0xffffffffu;
93 #endif
94  static const unsigned stencilsize_ = 12;
95  static const unsigned nterms_ = ((3 + 1) * (3 + 2))/2; // for a cubic fit
96  static const int c0_;
97  static const int c0n_;
98  static const int c0s_;
99  static const int c3_[stencilsize_ * nterms_];
100  static const int c3n_[stencilsize_ * nterms_];
101  static const int c3s_[stencilsize_ * nterms_];
102 
103  std::string _name, _dir, _filename;
104  const bool _cubic;
105  const real _a, _e2, _degree, _eps;
106  mutable std::ifstream _file;
107  real _rlonres, _rlatres;
108  std::string _description, _datetime;
109  real _offset, _scale, _maxerror, _rmserror;
110  int _width, _height;
111  unsigned long long _datastart, _swidth;
113  // Area cache
114  mutable std::vector< std::vector<pixel_t> > _data;
115  mutable bool _cache;
116  // NE corner and extent of cache
117  mutable int _xoffset, _yoffset, _xsize, _ysize;
118  // Cell cache
119  mutable int _ix, _iy;
120  mutable real _v00, _v01, _v10, _v11;
121  mutable real _t[nterms_];
122  void filepos(int ix, int iy) const {
123  _file.seekg(
124 #if !(defined(__GNUC__) && __GNUC__ < 4)
125  // g++ 3.x doesn't know about the cast to streamoff.
126  std::ios::streamoff
127 #endif
128  (_datastart +
129  pixel_size_ * (unsigned(iy)*_swidth + unsigned(ix))));
130  }
131  real rawval(int ix, int iy) const {
132  if (ix < 0)
133  ix += _width;
134  else if (ix >= _width)
135  ix -= _width;
136  if (_cache && iy >= _yoffset && iy < _yoffset + _ysize &&
137  ((ix >= _xoffset && ix < _xoffset + _xsize) ||
138  (ix + _width >= _xoffset && ix + _width < _xoffset + _xsize))) {
139  return real(_data[iy - _yoffset]
140  [ix >= _xoffset ? ix - _xoffset : ix + _width - _xoffset]);
141  } else {
142  if (iy < 0 || iy >= _height) {
143  iy = iy < 0 ? -iy : 2 * (_height - 1) - iy;
144  ix += (ix < _width/2 ? 1 : -1) * _width/2;
145  }
146  try {
147  filepos(ix, iy);
148  // initial values to suppress warnings in case get fails
149  char a = 0, b = 0;
150  _file.get(a);
151  _file.get(b);
152  unsigned r = ((unsigned char)(a) << 8) | (unsigned char)(b);
153  if (pixel_size_ == 4) {
154  _file.get(a);
155  _file.get(b);
156  r = (r << 16) | ((unsigned char)(a) << 8) | (unsigned char)(b);
157  }
158  return real(r);
159  }
160  catch (const std::exception& e) {
161  // throw GeographicErr("Error reading " + _filename + ": "
162  // + e.what());
163  // triggers complaints about the "binary '+'" under Visual Studio.
164  // So use '+=' instead.
165  std::string err("Error reading ");
166  err += _filename;
167  err += ": ";
168  err += e.what();
169  throw GeographicErr(err);
170  }
171  }
172  }
173  real height(real lat, real lon) const;
174  Geoid(const Geoid&); // copy constructor not allowed
175  Geoid& operator=(const Geoid&); // copy assignment not allowed
176  public:
177 
182  enum convertflag {
187  ELLIPSOIDTOGEOID = -1,
191  NONE = 0,
196  GEOIDTOELLIPSOID = 1,
197  };
198 
201 
223  explicit Geoid(const std::string& name, const std::string& path = "",
224  bool cubic = true, bool threadsafe = false);
225 
247  void CacheArea(real south, real west, real north, real east) const;
248 
262  void CacheAll() const { CacheArea(real(-90), real(0),
263  real(90), real(360)); }
264 
269  void CacheClear() const;
270 
272 
275 
288  Math::real operator()(real lat, real lon) const {
289  return height(lat, lon);
290  }
291 
308  Math::real ConvertHeight(real lat, real lon, real h,
309  convertflag d) const {
310  return h + real(d) * height(lat, lon);
311  }
312 
314 
317 
322  const std::string& Description() const { return _description; }
323 
327  const std::string& DateTime() const { return _datetime; }
328 
332  const std::string& GeoidFile() const { return _filename; }
333 
338  const std::string& GeoidName() const { return _name; }
339 
343  const std::string& GeoidDirectory() const { return _dir; }
344 
348  const std::string Interpolation() const
349  { return std::string(_cubic ? "cubic" : "bilinear"); }
350 
358  Math::real MaxError() const { return _maxerror; }
359 
367  Math::real RMSError() const { return _rmserror; }
368 
375  Math::real Offset() const { return _offset; }
376 
383  Math::real Scale() const { return _scale; }
384 
388  bool ThreadSafe() const { return _threadsafe; }
389 
393  bool Cache() const { return _cache; }
394 
399  return _cache ? ((_xoffset + (_xsize == _width ? 0 : _cubic)
400  + _width/2) % _width - _width/2) / _rlonres :
401  0;
402  }
403 
408  return _cache ?
409  CacheWest() +
410  (_xsize - (_xsize == _width ? 0 : 1 + 2 * _cubic)) / _rlonres :
411  0;
412  }
413 
418  return _cache ? 90 - (_yoffset + _cubic) / _rlatres : 0;
419  }
420 
426  return _cache ? 90 - ( _yoffset + _ysize - 1 - _cubic) / _rlatres : 0;
427  }
428 
436  { return Constants::WGS84_a(); }
437 
446 
456  static std::string DefaultGeoidPath();
457 
466  static std::string DefaultGeoidName();
467 
468  };
469 
470 } // namespace GeographicLib
471 
472 #if defined(_MSC_VER)
473 # pragma warning (pop)
474 #endif
475 
476 #endif // GEOGRAPHICLIB_GEOID_HPP
const std::string & GeoidFile() const
Definition: Geoid.hpp:332
const bool _cubic
Definition: Geoid.hpp:104
Math::real Scale() const
Definition: Geoid.hpp:383
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
std::string _description
Definition: Geoid.hpp:108
float real
Definition: datatypes.h:10
Math::real RMSError() const
Definition: Geoid.hpp:367
Scalar * b
Definition: benchVecAdd.cpp:17
bool ThreadSafe() const
Definition: Geoid.hpp:388
static const double lat
const std::string Interpolation() const
Definition: Geoid.hpp:348
Math::real Offset() const
Definition: Geoid.hpp:375
static const int c0s_
Definition: Geoid.hpp:98
const std::string & GeoidName() const
Definition: Geoid.hpp:338
Math::real ConvertHeight(real lat, real lon, real h, convertflag d) const
Definition: Geoid.hpp:308
bool Cache() const
Definition: Geoid.hpp:393
Math::real CacheNorth() const
Definition: Geoid.hpp:417
Math::real MaxError() const
Definition: Geoid.hpp:358
void filepos(int ix, int iy) const
Definition: Geoid.hpp:122
unsigned short pixel_t
Definition: Geoid.hpp:86
const real _eps
Definition: Geoid.hpp:105
real rawval(int ix, int iy) const
Definition: Geoid.hpp:131
static const int c0n_
Definition: Geoid.hpp:97
static const int c0_
Definition: Geoid.hpp:96
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const std::string & Description() const
Definition: Geoid.hpp:322
std::vector< std::vector< pixel_t > > _data
Definition: Geoid.hpp:114
const double h
unsigned long long _swidth
Definition: Geoid.hpp:111
Exception handling for GeographicLib.
Definition: Constants.hpp:389
Math::real CacheSouth() const
Definition: Geoid.hpp:425
Math::real real
Definition: Geoid.hpp:84
Header for GeographicLib::Constants class.
Math::real CacheWest() const
Definition: Geoid.hpp:398
std::ifstream _file
Definition: Geoid.hpp:106
static const double lon
Math::real Flattening() const
Definition: Geoid.hpp:444
Annotation for function names.
Definition: attr.h:48
std::string _name
Definition: Geoid.hpp:103
const std::string & DateTime() const
Definition: Geoid.hpp:327
const std::string & GeoidDirectory() const
Definition: Geoid.hpp:343
void CacheAll() const
Definition: Geoid.hpp:262
Math::real MajorRadius() const
Definition: Geoid.hpp:435
Math::real CacheEast() const
Definition: Geoid.hpp:407
Math::real operator()(real lat, real lon) const
Definition: Geoid.hpp:288
Looking up the height of the geoid above the ellipsoid.
Definition: Geoid.hpp:82


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:18