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 #ifndef OSGEARTH_TERRAIN_LAYER_H 00021 #define OSGEARTH_TERRAIN_LAYER_H 1 00022 00023 #include <osgEarth/Common> 00024 #include <osgEarth/Layer> 00025 #include <osgEarth/Config> 00026 #include <osgEarth/TileSource> 00027 #include <osgEarth/Profile> 00028 #include <osgEarth/Caching> 00029 #include <osgEarth/ThreadingUtils> 00030 00031 namespace osgEarth 00032 { 00036 class OSGEARTH_EXPORT TerrainLayerOptions : public ConfigOptions 00037 { 00038 public: 00039 TerrainLayerOptions( const ConfigOptions& options =ConfigOptions() ); 00040 TerrainLayerOptions( const std::string& name, const TileSourceOptions& driverOptions ); 00041 00045 std::string& name() { return _name; } 00046 const std::string& name() const { return _name; } 00047 00053 optional<ProfileOptions>& profile() { return _profile; } 00054 const optional<ProfileOptions>& profile() const { return _profile; } 00055 00059 optional<TileSourceOptions>& driver() { return _driver; } 00060 const optional<TileSourceOptions>& driver() const { return _driver; } 00061 00065 optional<int>& minLevel() { return _minLevel; } 00066 const optional<int>& minLevel() const { return _minLevel; } 00067 00071 optional<double>& minLevelResolution() { return _minLevelResolution;} 00072 const optional<double>& minLevelResolution() const { return _minLevelResolution; } 00073 00074 00078 optional<int>& maxLevel() { return _maxLevel; } 00079 const optional<int>& maxLevel() const { return _maxLevel; } 00080 00084 optional<double>& maxLevelResolution() { return _maxLevelResolution; } 00085 const optional<double>& maxLevelResolution() const { return _maxLevelResolution; } 00086 00090 optional<unsigned int>& maxDataLevel() { return _maxDataLevel; } 00091 const optional<unsigned int>& maxDataLevel() const { return _maxDataLevel; } 00092 00093 00094 00098 optional<bool>& enabled() { return _enabled; } 00099 const optional<bool>& enabled() const { return _enabled; } 00100 00104 optional<bool>& exactCropping() { return _exactCropping; } 00105 const optional<bool>& exactCropping() const { return _exactCropping; } 00106 00110 optional<unsigned int> reprojectedTileSize() { return _reprojectedTileSize; } 00111 const optional<unsigned int> reprojectedTileSize() const { return _reprojectedTileSize; } 00112 00116 optional<std::string>& cacheFormat() { return _cacheFormat; } 00117 const optional<std::string>& cacheFormat() const { return _cacheFormat; } 00118 00122 optional<bool>& cacheEnabled() { return _cacheEnabled; } 00123 const optional<bool>& cacheEnabled() const { return _cacheEnabled; } 00124 00128 optional<bool>& cacheOnly() { return _cacheOnly; } 00129 const optional<bool>& cacheOnly() const { return _cacheOnly; } 00130 00136 optional<std::string>& cacheId() { return _cacheId; } 00137 const optional<std::string>& cacheId() const { return _cacheId; } 00138 00142 optional<float>& loadingWeight() { return _loadingWeight; } 00143 const optional<float>& loadingWeight() const { return _loadingWeight; } 00144 00151 optional<double>& edgeBufferRatio() { return _edgeBufferRatio;} 00152 const optional<double>& edgeBufferRatio() const { return _edgeBufferRatio; } 00153 00154 public: 00155 virtual Config getConfig() const; 00156 virtual void mergeConfig( const Config& conf ); 00157 00158 private: 00159 void fromConfig( const Config& conf ); 00160 void setDefaults(); 00161 00162 std::string _name; 00163 optional<ProfileOptions> _profile; 00164 optional<TileSourceOptions> _driver; 00165 optional<int> _minLevel; 00166 optional<int> _maxLevel; 00167 optional<double> _minLevelResolution; 00168 optional<double> _maxLevelResolution; 00169 optional<std::string> _cacheFormat; 00170 optional<bool> _cacheEnabled; 00171 optional<bool> _cacheOnly; 00172 optional<float> _loadingWeight; 00173 optional<bool> _exactCropping; 00174 optional<bool> _enabled; 00175 optional<unsigned int> _reprojectedTileSize; 00176 optional<double> _edgeBufferRatio; 00177 optional<std::string> _cacheId; 00178 optional<unsigned int> _maxDataLevel; 00179 }; 00180 00184 struct TerrainLayerCallback : public osg::Referenced 00185 { 00186 virtual void onEnabledChanged( class TerrainLayer* layer ) { } 00187 }; 00188 00189 typedef void (TerrainLayerCallback::*TerrainLayerCallbackMethodPtr)(TerrainLayer* layer); 00190 00191 00195 class OSGEARTH_EXPORT TerrainLayer : public Layer 00196 { 00197 protected: 00198 TerrainLayer( TerrainLayerOptions* options ); 00199 00200 TerrainLayer( TerrainLayerOptions* options, TileSource* tileSource ); 00201 00202 public: 00203 00207 const TerrainLayerOptions& getTerrainLayerOptions() const { 00208 return *_runtimeOptions; } 00209 00213 void setEnabled( bool value ); 00214 bool getEnabled() const { return *_runtimeOptions->enabled(); } 00215 00219 const std::string& getName() const { 00220 return getTerrainLayerOptions().name(); } 00221 00225 const Profile* getProfile() const; 00226 00230 TileSource* getTileSource() const; 00231 00235 unsigned int getTileSize() const; 00236 00240 unsigned int getMaxDataLevel() const; 00241 00245 bool isDynamic() const; 00246 00247 const std::string& getCacheFormat() const { return *_runtimeOptions->cacheFormat(); } 00248 00249 public: // methods 00250 00254 bool isKeyValid(const TileKey& key) const; 00255 00259 Cache* getCache() const { return _cache.get(); } 00260 00265 void setCache( Cache* cache ); 00266 00270 const CacheSpec& getCacheSpec() const { return _cacheSpec; } 00271 00278 virtual void setTargetProfileHint( const Profile* profile ); 00279 00284 bool isCacheOnly() const { return *_runtimeOptions->cacheOnly(); } 00285 00286 protected: 00287 00288 virtual void initTileSource(); 00289 00290 virtual std::string suggestCacheFormat() const; 00291 00292 protected: 00293 00294 osg::ref_ptr<TileSource> _tileSource; 00295 osg::ref_ptr<Cache> _cache; 00296 CacheSpec _cacheSpec; 00297 00298 osg::ref_ptr<const Profile> _profile; 00299 osg::ref_ptr<const Profile> _cacheProfile; 00300 osg::ref_ptr<const Profile> _targetProfileHint; 00301 00302 bool _tileSourceInitialized; 00303 unsigned _tileSize; 00304 00305 private: 00306 std::string _name; 00307 std::string _referenceURI; 00308 OpenThreads::Mutex _initTileSourceMutex; 00309 TerrainLayerOptions* _runtimeOptions; 00310 00311 void init(); 00312 virtual void fireCallback( TerrainLayerCallbackMethodPtr method ) =0; 00313 00314 // methods accesible by Map: 00315 friend class Map; 00316 void setReferenceURI( const std::string& uri ); 00317 void setCacheOnly( bool value ); 00318 }; 00319 00320 typedef std::vector<osg::ref_ptr<TerrainLayer> > TerrainLayerVector; 00321 00322 } // namespace TerrainLayer 00323 00324 #endif // OSGEARTH_TERRAIN_LAYER_H