osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 00026 #ifndef OSGEARTH_TMS_H 00027 #define OSGEARTH_TMS_H 1 00028 00029 #include <vector> 00030 #include <iostream> 00031 #include <osgEarth/Profile> 00032 #include <osgEarth/Common> 00033 00034 #include <osg/Referenced> 00035 #include <osgDB/ReaderWriter> 00036 00037 #include <osg/Version> 00038 #if OSG_MIN_VERSION_REQUIRED(2,9,5) 00039 #include <osgDB/Options> 00040 #endif 00041 00042 namespace osgEarth 00043 { 00044 class TileSource; 00045 00049 class OSGEARTH_EXPORT TileFormat 00050 { 00051 public: 00052 TileFormat(); 00053 00057 unsigned int getWidth() const {return _width;} 00058 00062 void setWidth(unsigned int width) {_width = width;} 00063 00067 unsigned int getHeight() const {return _height;} 00068 00072 void setHeight(unsigned int height) {_height = height;} 00073 00077 const std::string& getMimeType() const {return _mimeType;} 00078 00082 void setMimeType(const std::string& mimeType) {_mimeType = mimeType;} 00083 00087 const std::string& getExtension() const {return _extension;} 00088 00092 void setExtension(const std::string& extension) {_extension = extension;} 00093 00094 protected: 00095 unsigned int _width; 00096 unsigned int _height; 00097 std::string _mimeType; 00098 std::string _extension; 00099 }; 00100 00104 class OSGEARTH_EXPORT TileSet 00105 { 00106 public: 00107 TileSet(); 00108 00112 const std::string& getHref() const {return _href;} 00113 00117 void setHref( const std::string &href) {_href = href;} 00118 00122 double getUnitsPerPixel() const {return _unitsPerPixel;} 00123 00127 void setUnitsPerPixel(double unitsPerPixel) {_unitsPerPixel = unitsPerPixel;} 00128 00132 unsigned int getOrder() const {return _order;} 00133 00137 void setOrder( int order ) {_order = order;} 00138 00139 protected: 00140 std::string _href; 00141 double _unitsPerPixel; 00142 unsigned int _order; 00143 }; 00144 00148 class OSGEARTH_EXPORT TileMap : public osg::Referenced 00149 { 00150 public: 00151 TileMap(); 00152 00156 const std::string& getTileMapService() const {return _tileMapService;} 00157 00161 void setTileMapService(const std::string& tileMapService) {_tileMapService = tileMapService;} 00162 00166 const std::string& getVersion() const {return _version;} 00167 00171 void setVersion(const std::string& version) {_version = version;} 00172 00176 const std::string& getTitle() const {return _title;} 00177 00181 void setTitle(const std::string& title) {_title = title;} 00182 00186 const std::string& getAbstract() const {return _abstract;} 00187 00191 void setAbstract(const std::string& value) {_abstract = value;} 00192 00196 const std::string& getSRS() const {return _srs;} 00197 00201 void setSRS(const std::string& srs) {_srs = srs;} 00202 00206 const std::string& getVerticalSRS() const { return _vsrs; } 00207 00211 void setVerticalSRS(const std::string& vsrs) { _vsrs = vsrs; } 00212 00216 const std::string& getFilename() const {return _filename;} 00217 00221 void setFilename(const std::string& filename) {_filename = filename;} 00222 00226 unsigned int getMinLevel() const {return _minLevel;} 00227 00231 unsigned int getMaxLevel() const {return _maxLevel;} 00232 00236 void computeMinMaxLevel(); 00237 00241 void computeNumTiles(); 00242 00246 double getOriginX() const {return _originX;} 00247 00251 void setOriginX(double x) {_originX = x;} 00252 00256 double getOriginY() const {return _originY;} 00257 00261 void setOriginY(double y) {_originY = y;} 00262 00271 void setOrigin(double x, double y); 00272 00284 void getExtents( double &minX, double &minY, double &maxX, double &maxY) const; 00285 00297 void setExtents( double minX, double minY, double maxX, double maxY); 00298 00302 unsigned int getNumTilesWide() const { return _numTilesWide; } 00303 00307 void setNumTilesWide(unsigned int w) { _numTilesWide = w; } 00308 00312 unsigned int getNumTilesHigh() const { return _numTilesHigh; } 00313 00317 void setNumTilesHigh(unsigned int h) {_numTilesHigh = h;} 00318 00319 osgEarth::Profile::ProfileType getProfileType() const {return _profile_type;} 00320 void setProfileType( osgEarth::Profile::ProfileType type ) {_profile_type = type;} 00321 00322 const Profile* createProfile() const; 00323 00325 TileFormat& getFormat() {return _format;} 00326 00328 const TileFormat& getFormat() const {return _format;} 00329 00330 00332 typedef std::vector<TileSet> TileSetList; 00333 00335 TileSetList& getTileSets() {return _tileSets;} 00336 00338 const TileSetList& getTileSets() const {return _tileSets;} 00339 00340 DataExtentList& getDataExtents() { return _dataExtents;} 00341 const DataExtentList& getDataExtents() const { return _dataExtents;} 00342 00343 00353 std::string getURL(const osgEarth::TileKey& tileKey, bool invertY); 00354 00358 bool intersectsKey(const osgEarth::TileKey& tileKey); 00359 00363 void generateTileSets(unsigned int numLevels = 20); 00364 00368 static TileMap* create( 00369 const std::string& url, 00370 const Profile* profile, 00371 //osgEarth::Profile::ProfileType type, 00372 const std::string& format, 00373 int tile_width, 00374 int tile_height ); 00375 00379 static TileMap* create( 00380 const TileSource* tileSource, 00381 const Profile* profile ); 00382 00383 protected: 00384 std::string _tileMapService; 00385 std::string _version; 00386 std::string _title; 00387 std::string _abstract; 00388 std::string _srs; 00389 std::string _vsrs; 00390 00391 00392 double _originX, _originY; 00393 00394 double _minX, _minY, _maxX, _maxY; 00395 00396 TileSetList _tileSets; 00397 00398 TileFormat _format; 00399 00400 std::string _filename; 00401 00402 unsigned int _minLevel; 00403 unsigned int _maxLevel; 00404 00405 unsigned int _numTilesWide; 00406 unsigned int _numTilesHigh; 00407 00408 osgEarth::Profile::ProfileType _profile_type; 00409 00410 DataExtentList _dataExtents; 00411 }; 00412 00413 class OSGEARTH_EXPORT TileMapReaderWriter 00414 { 00415 public: 00416 static TileMap* read( const std::string &location, const osgDB::ReaderWriter::Options* options ); 00417 static TileMap* read( std::istream &in ); 00418 00419 static void write(const TileMap* tileMap, const std::string& location); 00420 static void write(const TileMap* tileMap, std::ostream& output); 00421 00422 private: 00423 TileMapReaderWriter(); 00424 TileMapReaderWriter(const TileMapReaderWriter &tmr); 00425 }; 00426 } 00427 00428 #endif //OSGEARTH_TMS_H