GeographicLib: Geoid.hpp Source File (original) (raw)
83 private:
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;
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;
112 bool _threadsafe;
113
114 mutable std::vector< std::vector<pixel_t> > _data;
115 mutable bool _cache;
116
117 mutable int _xoffset, _yoffset, _xsize, _ysize;
118
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(std::streamoff
124 (_datastart +
125 pixel_size_ * (unsigned(iy)*_swidth + unsigned(ix))));
126 }
127 real rawval(int ix, int iy) const {
128 if (ix < 0)
129 ix += _width;
130 else if (ix >= _width)
131 ix -= _width;
132 if (_cache && iy >= _yoffset && iy < _yoffset + _ysize &&
133 ((ix >= _xoffset && ix < _xoffset + _xsize) ||
134 (ix + _width >= _xoffset && ix + _width < _xoffset + _xsize))) {
135 return real(_data[iy - _yoffset]
136 [ix >= _xoffset ? ix - _xoffset : ix + _width - _xoffset]);
137 } else {
138 if (iy < 0 || iy >= _height) {
139 iy = iy < 0 ? -iy : 2 * (_height - 1) - iy;
140 ix += (ix < _width/2 ? 1 : -1) * _width/2;
141 }
142 try {
143 filepos(ix, iy);
144
145 char a = 0, b = 0;
146 _file.get(a);
147 _file.get(b);
148 unsigned r = ((unsigned char)(a) << 8) | (unsigned char)(b);
149
150 if (pixel_size_ == 4) {
151 _file.get(a);
152 _file.get(b);
153 r = (r << 16) | ((unsigned char)(a) << 8) | (unsigned char)(b);
154 }
155 return real(r);
156 }
157 catch (const std::exception& e) {
158
159
160
161
162 std::string err("Error reading ");
163 err += _filename;
164 err += ": ";
165 err += e.what();
167 }
168 }
169 }
170 real height(real lat, real lon) const;
171 Geoid(const Geoid&) = delete;
172 Geoid& operator=(const Geoid&) = delete;
173 public:
174
175
176
177
178
180
181
182
183
184 ELLIPSOIDTOGEOID = -1,
185
186
187
188 NONE = 0,
189
190
191
192
193 GEOIDTOELLIPSOID = 1,
194 };
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 explicit Geoid(const std::string& name, const std::string& path = "",
221 bool cubic = true, bool threadsafe = false);
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244 void CacheArea(real south, real west, real north, real east) const;
245
246
247
248
249
250
251
252
253
254
255
256
257
258
261
262
263
264
265
266 void CacheClear() const;
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
286 return height(lat, lon);
287 }
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
307 return h + real(d) * height(lat, lon);
308 }
309
310
311
312
313
314
315
316
317
318
319 const std::string& Description() const { return _description; }
320
321
322
323
324 const std::string& DateTime() const { return _datetime; }
325
326
327
328
329 const std::string& GeoidFile() const { return _filename; }
330
331
332
333
334
335 const std::string& GeoidName() const { return _name; }
336
337
338
339
341
342
343
344
346 { return std::string(_cubic ? "cubic" : "bilinear"); }
347
348
349
350
351
352
353
354
356
357
358
359
360
361
362
363
365
366
367
368
369
370
371
373
374
375
376
377
378
379
381
382
383
384
386
387
388
389
390 bool Cache() const { return _cache; }
391
392
393
394
396 return _cache ? ((_xoffset + (_xsize == _width ? 0 : _cubic)
397 + _width/2) % _width - _width/2) / _rlonres :
398 0;
399 }
400
401
402
403
405 return _cache ?
406 CacheWest() +
407 (_xsize - (_xsize == _width ? 0 : 1 + 2 * _cubic)) / _rlonres :
408 0;
409 }
410
411
412
413
415 return _cache ? real(Math::qd) - (_yoffset + _cubic) / _rlatres : 0;
416 }
417
418
419
420
421
423 return _cache ?
424 real(Math::qd) - ( _yoffset + _ysize - 1 - _cubic) / _rlatres :
425 0;
426 }
427
428
429
430
431
432
433
435 { return Constants::WGS84_a(); }
436
437
438
439
440
441
442
444
445
446
447
448
449
450
451
452
453
454
455 static std::string DefaultGeoidPath();
456
457
458
459
460
461
462
463
464
465 static std::string DefaultGeoidName();
466
467 };