1 #ifndef __SG_DEM_TILE_HXX__
2 #define __SG_DEM_TILE_HXX__
3 
4 #include <gdal.h>
5 #include <gdal_priv.h>
6 
7 #include <map>
8 
9 #include <simgear/structure/SGSharedPtr.hxx>
10 #include <simgear/math/SGGeod.hxx>
11 
12 class SGDemSession;
13 
14 class SGDemTile : public SGReferenced
15 {
16 public:
17     // TODO - simple constructor, so writing a tile to disk not done in constructor.
18     // then - reading / writing done with tile API, not constructor.
19     //SGDemTile( const SGPath& path, int lon, int lat, int w, int h, int x, int y, int overlap );
20 
21     // constructor for reading a tile
22     SGDemTile( const SGPath& path, unsigned wo, unsigned so, int w, int h, int x, int y, int overlap, bool cache );
23     // constructor for writing a tile
24     SGDemTile( const SGPath& path, unsigned wo, unsigned so, int w, int h, int x, int y, int overlap, const SGDemSession& s, bool& bWritten );
25 
26     ~SGDemTile();
27 
28     // read / write tile from / to disk
29     //int read( bool cache );
30     //int write( const SGDemSession& s );
31 
getPath(void) const32     SGPath getPath( void ) const { return path; }
33     unsigned short getAlt(const SGGeod& loc) const;
34     void getGeods(unsigned wo, unsigned so, unsigned eo, unsigned no, int grid_width, int grid_height, unsigned subx, unsigned suby, int incw, int inch, ::std::vector<SGGeod>& geods, bool Debug1, bool Debug2);
35 
36 private:
37     std::string     getTileName( int lon, int lat );
38     void            dbgDumpDataset( GDALDataset* poDataset ) const;
39     void            dbgDumpBand( GDALRasterBand* poBand ) const;
40 
41     unsigned short* cacheTile( const SGPath& path );
42 
43     GDALDatasetH    createTile( char **papszSrcFiles,
44                         const char *pszFilename,
45                         int nForceLines, int nForcePixels,
46                         double dfMinX, double dfMinY,
47                         double dfMaxX, double dfMaxY,
48                         char **papszTO );
49 
50     void            doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char **papszTO, char** papszWarpOptions );
51 
52     SGPath          path;
53     unsigned short* raster;
54 
55     int             ref_lon, ref_lat;
56     int             width, height;
57     int             resx, resy;
58     int             overlap;
59     double          pixResX, pixResY;
60 };
61 
62 typedef SGSharedPtr<SGDemTile> SGDemTileRef;
63 typedef std::map<unsigned long, SGDemTileRef> SGDemCache;
64 
65 #endif /* #define __SG_DEM_TILE_HXX__ */
66