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 
289  return height(lat, lon);
290  }
291 
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
name
Annotation for function names.
Definition: attr.h:51
GeographicLib::Geoid::Interpolation
const std::string Interpolation() const
Definition: Geoid.hpp:348
GeographicLib::Geoid::_cubic
const bool _cubic
Definition: Geoid.hpp:104
GeographicLib::Geoid::CacheNorth
Math::real CacheNorth() const
Definition: Geoid.hpp:417
GeographicLib::Geoid::Scale
Math::real Scale() const
Definition: Geoid.hpp:383
GeographicLib::Geoid::c0_
static const int c0_
Definition: Geoid.hpp:96
GeographicLib::Geoid::filepos
void filepos(int ix, int iy) const
Definition: Geoid.hpp:122
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
d
static const double d[K][N]
Definition: igam.h:11
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
b
Scalar * b
Definition: benchVecAdd.cpp:17
real
float real
Definition: datatypes.h:10
GEOGRAPHICLIB_EXPORT
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
h
const double h
Definition: testSimpleHelicopter.cpp:19
GeographicLib::Geoid::Flattening
Math::real Flattening() const
Definition: Geoid.hpp:444
GeographicLib::Geoid::CacheWest
Math::real CacheWest() const
Definition: Geoid.hpp:398
GeographicLib::GeographicErr
Exception handling for GeographicLib.
Definition: Constants.hpp:389
GeographicLib::Geoid::operator()
Math::real operator()(real lat, real lon) const
Definition: Geoid.hpp:288
GeographicLib::Geoid::RMSError
Math::real RMSError() const
Definition: Geoid.hpp:367
GeographicLib::Geoid::c0n_
static const int c0n_
Definition: Geoid.hpp:97
GeographicLib::Math::real
double real
Definition: Math.hpp:129
GeographicLib::Geoid::convertflag
convertflag
Definition: Geoid.hpp:182
GeographicLib::Geoid::_scale
real _scale
Definition: Geoid.hpp:109
GeographicLib::Geoid::_eps
const real _eps
Definition: Geoid.hpp:105
GeographicLib::Geoid::rawval
real rawval(int ix, int iy) const
Definition: Geoid.hpp:131
GeographicLib::Geoid::GeoidName
const std::string & GeoidName() const
Definition: Geoid.hpp:338
GeographicLib::Geoid::GeoidDirectory
const std::string & GeoidDirectory() const
Definition: Geoid.hpp:343
GeographicLib::Geoid::Description
const std::string & Description() const
Definition: Geoid.hpp:322
GeographicLib::Geoid::MajorRadius
Math::real MajorRadius() const
Definition: Geoid.hpp:435
GeographicLib::Geoid::c0s_
static const int c0s_
Definition: Geoid.hpp:98
GeographicLib::Geoid::_rlonres
real _rlonres
Definition: Geoid.hpp:107
GeographicLib::Geoid::DateTime
const std::string & DateTime() const
Definition: Geoid.hpp:327
GeographicLib::Geoid::GeoidFile
const std::string & GeoidFile() const
Definition: Geoid.hpp:332
GeographicLib::Geoid::MaxError
Math::real MaxError() const
Definition: Geoid.hpp:358
GeographicLib::Geoid
Looking up the height of the geoid above the ellipsoid.
Definition: Geoid.hpp:82
GeographicLib::Geoid::Offset
Math::real Offset() const
Definition: Geoid.hpp:375
Constants.hpp
Header for GeographicLib::Constants class.
GeographicLib::Geoid::_iy
int _iy
Definition: Geoid.hpp:119
GeographicLib::Geoid::_data
std::vector< std::vector< pixel_t > > _data
Definition: Geoid.hpp:114
matlab_wrap.path
path
Definition: matlab_wrap.py:66
GeographicLib::Geoid::_threadsafe
bool _threadsafe
Definition: Geoid.hpp:112
GeographicLib::Geoid::real
Math::real real
Definition: Geoid.hpp:84
GeographicLib::Geoid::_swidth
unsigned long long _swidth
Definition: Geoid.hpp:111
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
GeographicLib::Geoid::Cache
bool Cache() const
Definition: Geoid.hpp:393
GeographicLib::Geoid::pixel_t
unsigned short pixel_t
Definition: Geoid.hpp:86
GeographicLib::Constants::WGS84_a
static T WGS84_a()
Definition: Constants.hpp:159
GeographicLib::Geoid::_v11
real _v11
Definition: Geoid.hpp:120
GeographicLib::Geoid::_ysize
int _ysize
Definition: Geoid.hpp:117
GeographicLib::Constants::WGS84_f
static T WGS84_f()
Definition: Constants.hpp:169
GeographicLib::Geoid::_name
std::string _name
Definition: Geoid.hpp:103
GeographicLib::Geoid::CacheEast
Math::real CacheEast() const
Definition: Geoid.hpp:407
lon
static const double lon
Definition: testGeographicLib.cpp:34
GeographicLib::Geoid::_cache
bool _cache
Definition: Geoid.hpp:115
GeographicLib::Geoid::CacheAll
void CacheAll() const
Definition: Geoid.hpp:262
GeographicLib::Geoid::ConvertHeight
Math::real ConvertHeight(real lat, real lon, real h, convertflag d) const
Definition: Geoid.hpp:308
GeographicLib::Geoid::CacheSouth
Math::real CacheSouth() const
Definition: Geoid.hpp:425
GeographicLib::Geoid::_width
int _width
Definition: Geoid.hpp:110
real
Definition: main.h:100
GeographicLib::Geoid::_description
std::string _description
Definition: Geoid.hpp:108
GeographicLib::Geoid::_file
std::ifstream _file
Definition: Geoid.hpp:106
GeographicLib::Geoid::ThreadSafe
bool ThreadSafe() const
Definition: Geoid.hpp:388
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:22