1 // SGDem.hxx -- read, write DEM heiarchy
2 //
3 // Written by Peter Sadrozinski, started August 2016.
4 //
5 // Copyright (C) 2001 - 2003  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22 
23 
24 #ifndef __SG_DEM_HXX__
25 #define __SG_DEM_HXX__
26 
27 #include <map>
28 
29 #include <simgear/compiler.h>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/scene/dem/SGDemRoot.hxx>
32 
33 class SGDem : public SGReferenced
34 {
35 public:
SGDem()36     SGDem() {};
~SGDem()37     ~SGDem() {};
38 
39     int addRoot( const SGPath& root );
40     int createRoot( const SGPath& root );
getRoot(unsigned int i)41     SGDemRoot* getRoot( unsigned int i ) {
42         if ( i < demRoots.size() ) {
43             return &demRoots[i];
44         } else {
45             return NULL;
46         }
47     }
48 
getNumRoots(void)49     unsigned int getNumRoots( void ) {
50         return demRoots.size();
51     }
52 
53     // todo : move to session
54     // unsigned short getAlt( const SGDemSession& s, const SGGeod& loc ) const;
55 
56     // find a Dem to satisfy a session - must have the level, and extents
57     SGDemRoot* findDem( unsigned wo, unsigned so, unsigned eo, unsigned no, int lvl );
58 
59     // open a session from a dem level - tiles will be read and reference counted until closed
60     //SGDemSession openSession( const SGGeod& min, const SGGeod& max, int level, bool cache );
61     SGDemSession openSession( unsigned wo, unsigned so, unsigned eo, unsigned no, int level, bool cache );
62 
63     // open a session from an bare directory
64     SGDemSession openSession( const SGGeod& min, const SGGeod& max, const SGPath& input );
65 
66     // static helpers
67     static int      floorWithEpsilon( double x );
68     static unsigned normalizeLongitude( unsigned offset );
69     static unsigned longitudeDegToOffset( double lon );
70     static double   offsetToLongitudeDeg( unsigned offset );
71     static unsigned latitudeDegToOffset( double lat );
72     static double   offsetToLatitudeDeg( unsigned offset );
73     static unsigned roundDown( unsigned offset, unsigned roundTo );
74     static unsigned roundUp( unsigned offset, unsigned roundTo );
75 
76 private:
77     std::vector<SGDemRoot>  demRoots;
78 };
79 
80 typedef SGSharedPtr<SGDem> SGDemPtr;
81 
82 #endif /* __SG_DEM_HXX__ */
83