KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nedgrid.h
Go to the documentation of this file.
1 
15 /*
16  * $Id: nedgrid.h 18278 2014-11-25 01:42:10Z ksimek $
17  */
18 
19 #ifndef NEDGRID_H_UOFARIZONA_VISION
20 #define NEDGRID_H_UOFARIZONA_VISION
21 
22 #include <l_cpp/l_exception.h>
23 #include <m_cpp/m_matrix.h>
24 #include <topo_cpp/layer.h>
25 #include <string>
26 #include <deque>
27 #include <vector>
28 #include <algorithm>
29 #include <utility>
30 
31 #include <boost/scoped_ptr.hpp>
32 
33 namespace kjb
34 {
35 
36 
37 extern const int NED_ELLIPSOID;
38 
39 
40 
67 {
68 public:
69  typedef std::vector<std::string> Path;
70 
71  struct IntegralLL;
72 
83  Ned13_one_degree_grid(const IntegralLL& ill, const Path& path);
84 
85  Ned13_one_degree_grid(int, int, const Path&);
86 
87 #if 0
88  void display(const std::string&, int) const;
89 #endif
90 
92  bool is_in_bounds(const IntegralLL&) const;
93 
94  float elevation_meters(const IntegralLL&) const;
95 
97  float maximum_elevation() const
98  {
99  return max_and_min_elevations().first;
100  }
101 
103  float minimum_elevation() const
104  {
105  return max_and_min_elevations().second;
106  }
107 
109  std::pair<float, float> max_and_min_elevations() const;
110 
112 
113  IntegralLL northwest_corner() const;
114 
116  IntegralLL southeast_corner() const;
117 
118 private:
121  boost::scoped_ptr< IntegralLL > nw_corner;
122 
124  std::deque< float > elevation;
125 
126  void grid_rc(const IntegralLL&, int*, int*) const;
127 
128  bool grid_inbounds(int, int) const;
129 
130  // teasers: this object is not copyable or assignable (swappable, though)
132  Ned13_one_degree_grid& operator=(const Ned13_one_degree_grid&);
133 };
134 
135 
136 
175 {
176  int ilat,
177  ilon;
178 
180  double dd_latitude() const;
181 
183  double dd_longitude() const;
184 
185  // named ctor constructs from float n latitude, e longitude degrees,
186  static IntegralLL from_lat_lon(double, double);
187 
188  // named ctor constructs from integer n latitude, e longitude degrees
189  static IntegralLL from_lat_lon(int, int);
190 
191 private:
192  IntegralLL(int, int);
193 };
194 
197 
200 
202 std::pair<double, double> delta_n_e_meters(
204 );
205 
208 
209 
211 
212 
214 inline bool operator==(
217 )
218 {
219  return p.ilat == q.ilat && p.ilon == q.ilon;
220 }
221 
222 
224 inline bool operator<(
227 )
228 {
229  return p.ilat == q.ilat ? p.ilon < q.ilon : p.ilat < q.ilat;
230 }
231 
232 
233 Ned13_one_degree_grid::IntegralLL round_nw_to_whole_degrees(
234  const Ned13_one_degree_grid::IntegralLL&
235 );
236 
237 
238 
241 {
242  std::vector< Ned13_one_degree_grid* > m_grids;
243  Ned13_one_degree_grid* most_recent;
244  const std::vector< std::string > m_path;
245 
247  void discard_cache();
248 
249  // teasers
250  Ned13_grid_cache(const Ned13_grid_cache&); // not copyable
251  Ned13_grid_cache& operator=(const Ned13_grid_cache&); // not assignable
252 
253 public:
255  const std::vector< std::string >& path = std::vector<std::string>()
256  )
257  : most_recent(00),
258  m_path(path.begin(), path.end())
259  {}
260 
263  {
264  discard_cache();
265  }
266 
270  );
271 
272  const Ned13_one_degree_grid& fetch(double, double);
273 
276  {
278  }
279 
287  size_t cache_size() const
288  {
289  return m_grids.size();
290  }
291 };
292 
293 
296 {
298  const std::vector< std::string >& path = std::vector<std::string>()
299  )
300  : cache(path)
301  {}
302 
303  virtual float elevation_meters(const TopoFusion::pt&) = 0;
304 
306 
308 };
309 
310 
321 : public Ned13_caching_reader
322 {
324  float elevation_meters(const TopoFusion::pt&);
325 
327  const std::vector< std::string >& path = std::vector<std::string>()
328  )
329  : Ned13_caching_reader(path)
330  {}
331 };
332 
333 
344 : public Ned13_caching_reader
345 {
347  float elevation_meters(const TopoFusion::pt&);
348 
350  const std::vector< std::string >& path = std::vector<std::string>()
351  )
352  : Ned13_caching_reader(path)
353  {}
354 };
355 
356 
358 : public Ned13_caching_reader
359 {
361  float elevation_meters(const TopoFusion::pt&);
362 
364  const std::vector< std::string >& path = std::vector<std::string>()
365  )
366  : Ned13_caching_reader(path)
367  {}
368 
394  static float characteristic_length_squared() { return 500; }
395 };
396 
397 
427 int ned13_grid(
428  const TopoFusion::pt& center,
429  Matrix *elev_o,
430  Matrix *elev_de_o,
431  Matrix *elev_dn_o,
432  int eastwest_size_meters = 2000,
433  int northsouth_size_meters = 2000,
434  int resolution_meters = 1,
435  Ned13_caching_reader *cache = 0,
436  const std::vector< std::string > &path = std::vector< std::string >()
437 );
438 
439 
440 
461 inline
463  const TopoFusion::pt& center,
464  int eastwest_size_meters = 2000,
465  int northsouth_size_meters = 2000,
466  int resolution_meters = 1,
467  Ned13_caching_reader *cache = 0,
468  const std::vector< std::string > &path = std::vector< std::string >()
469 )
470 {
471  Matrix e;
472  ETX(ned13_grid(center, &e, 0, 0, eastwest_size_meters,
473  northsouth_size_meters, resolution_meters, cache, path));
474  return e;
475 }
476 
477 
478 TopoFusion::pt dem_to_doq_displacement(const TopoFusion::pt&);
479 
480 
481 void set_spy_filename(const std::string&);
482 
483 TopoFusion::pt force_zone_to_this(const TopoFusion::pt&, char use_this_zone);
484 
485 }
486 
487 
488 namespace std
489 {
490 
491 //template<> // <-- overloading is preferred to template specialization in this context.
492 // (also, this doesn't compile in c++11)
494 {
495  p.swap(q);
496 }
497 
498 }
499 
500 #endif /* NEDGRID_H_UOFARIZONA_VISION */
bool is_in_bounds(const IntegralLL &) const
is the given location within this grid?
Definition: nedgrid.cpp:747
integer-valued, latitude-style and longitude-style coordinates
Definition: nedgrid.h:174
GILL round_nw_to_whole_degrees(const GILL &ill)
map an input location to the nearest location to northwest of whole degrees
Definition: nedgrid.cpp:1043
Definition: nedgrid.h:357
#define ETX(a)
Definition: l_exception.h:67
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
void set_spy_filename(const std::string &)
Contains definitions of basic TopoFusion data structures.
std::vector< std::string > Path
list of dirs to srch for tiles
Definition: nedgrid.h:69
float minimum_elevation() const
determine the minimum elevation, disregarding missing-data flag
Definition: nedgrid.h:103
interface to an elevation-info object that caches its NED13 grids
Definition: nedgrid.h:295
const int NED_ELLIPSOID
Definition: nedgrid.cpp:577
This caches a bunch (potentially) of one-degree grids for you.
Definition: nedgrid.h:240
Ned13_one_degree_grid(const IntegralLL &ill, const Path &path)
try to load a NED13 tile at a given geo location
Definition: nedgrid.cpp:756
Ned13_grid_cache cache
Definition: nedgrid.h:307
bool operator<(const Face_detection &f1, const Face_detection &f2)
Compares to boxes using middle of box. Needed because we have associated containers of these...
Definition: d_facecom.cpp:147
TopoFusion::pt ned13_ill_to_utm(const Ned13_one_degree_grid::IntegralLL &i)
convert to UTM coordinates (no elevation)
Definition: nedgrid.cpp:978
Ned13_grid_cache(const std::vector< std::string > &path=std::vector< std::string >())
Definition: nedgrid.h:254
virtual float elevation_meters(const TopoFusion::pt &)=0
virtual ~Ned13_caching_reader()
Definition: nedgrid.h:305
float elevation_meters(const TopoFusion::pt &)
basic query operation: estimate the elevation at a point
Definition: nedgrid.cpp:1166
std::pair< float, float > max_and_min_elevations() const
determine extremal elevations, disregarding missing-data flag
Definition: nedgrid.cpp:1007
double delta_e_meters(const Ned13_one_degree_grid::IntegralLL &ill)
distance, in meters, of the next grid point to the east
Definition: nedgrid.cpp:892
size_t cache_size() const
return the number of grids in the cache
Definition: nedgrid.h:287
int ilat
latitude, in one-third-arcsecond units (north=+)
Definition: nedgrid.h:176
void swap(Ned13_one_degree_grid &)
Definition: nedgrid.cpp:1029
double dd_latitude() const
latitude, in "decimal" degrees
Definition: nedgrid.cpp:961
GILL utm_to_se_ned13_ill(const TopoFusion::pt &p)
convert from UTM coord to grid location, truncating to the southeast
Definition: nedgrid.cpp:995
static IntegralLL from_lat_lon(double, double)
named-ctor builds fr. floating-point decimal degrees, rounding to southeast
Definition: nedgrid.cpp:715
TopoPt force_zone_to_this(const TopoPt &p, char use_this_zone)
Definition: nedgrid.cpp:581
Ned13_caching_reader(const std::vector< std::string > &path=std::vector< std::string >())
Definition: nedgrid.h:297
IntegralLL southeast_corner() const
get the whole-degree location of the southeast corner of grid
Definition: nedgrid.cpp:1070
static float characteristic_length_squared()
characteristic length of squared exponential kernel function
Definition: nedgrid.h:394
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
float maximum_elevation() const
determine the maximum elevation value in the grid
Definition: nedgrid.h:97
const Ned13_one_degree_grid & fetch(const Ned13_one_degree_grid::IntegralLL &)
return reference to grid with the given exact NW corner point
Definition: nedgrid.cpp:1110
bool operator==(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for exact equality between two matrices.
Definition: l_int_matrix.cpp:218
float elevation_meters(const TopoFusion::pt &)
basic query operation: estimate the elevation at a point
Definition: nedgrid.cpp:1175
double dd_longitude() const
longitude, in "decimal" degrees; negative values within the USA.
Definition: nedgrid.cpp:967
Ned13_bilinear_reader(const std::vector< std::string > &path=std::vector< std::string >())
Definition: nedgrid.h:349
float elevation_meters(const IntegralLL &) const
get the elevation, in meters, at the given point
Definition: nedgrid.cpp:883
virtual ~Ned13_grid_cache()
dtor cleans up (releases all grid objects in the cache)
Definition: nedgrid.h:262
Ned13_gp_reader(const std::vector< std::string > &path=std::vector< std::string >())
Definition: nedgrid.h:363
TopoFusion::pt dem_to_doq_displacement(const TopoFusion::pt &dem_p)
return correction factor between DEM and DOQ coordinate systems.
Definition: nedgrid.cpp:1283
int ned13_grid(const TopoFusion::pt &center, Matrix *elev_o, Matrix *elev_de_o, Matrix *elev_dn_o, int eastwest_size_meters, int northsouth_size_meters, int resolution_meters, Ned13_caching_reader *cache, const std::vector< std::string > &path)
generate a grid describing an elevation model near some location
Definition: nedgrid.cpp:600
std::pair< double, double > delta_n_e_meters(const Ned13_one_degree_grid::IntegralLL &ill)
distances, in meters, of next grid pt north (first), east (second)
Definition: nedgrid.cpp:934
support NED 13 elevation queries using bilinear interpolation
Definition: nedgrid.h:343
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Ned13_nearest_se_neighbor_reader(const std::vector< std::string > &path=std::vector< std::string >())
Definition: nedgrid.h:326
Support for error handling exception classes in libKJB.
double delta_n_meters(const Ned13_one_degree_grid::IntegralLL &ill)
distance, in meters, of the next grid point to the north
Definition: nedgrid.cpp:920
float elevation_meters(const TopoFusion::pt &)
basic query operation: estimate the elevation at a point
Definition: nedgrid.cpp:1253
const Ned13_one_degree_grid & fetch(const TopoFusion::pt &p)
return reference to grid, from cache or loading if necessary
Definition: nedgrid.h:275
int ilon
longitude, in 1/3rd-arcsecond units (west = neg)
Definition: nedgrid.h:176
IntegralLL northwest_corner() const
get the whole-degree location of the northwest corner of grid
Definition: nedgrid.cpp:675
support NED 13 elevation queries by using nearest southeast neighbor
Definition: nedgrid.h:320
definition for a TopoFusion pt
Definition: layer.h:34
storage for a single NED13 grid tile, plus convenient access.
Definition: nedgrid.h:66