/usr/include/osgEarth/TerrainLayer is in libosgearth-dev 2.5.0+dfsg-2+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | /* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2013 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_TERRAIN_LAYER_H
#define OSGEARTH_TERRAIN_LAYER_H 1
#include <osgEarth/Common>
#include <osgEarth/Cache>
#include <osgEarth/CachePolicy>
#include <osgEarth/Config>
#include <osgEarth/Layer>
#include <osgEarth/TileSource>
#include <osgEarth/Profile>
#include <osgEarth/ThreadingUtils>
#include <osgEarth/HTTPClient>
namespace osgEarth
{
/**
* Initialization (and serializable) options for a terrain layer.
*/
class OSGEARTH_EXPORT TerrainLayerOptions : public ConfigOptions
{
public:
TerrainLayerOptions( const ConfigOptions& options =ConfigOptions() );
TerrainLayerOptions( const std::string& name, const TileSourceOptions& driverOptions );
/** dtor */
virtual ~TerrainLayerOptions() { }
/**
* The readable name of the layer.
*/
std::string& name() { return _name; }
const std::string& name() const { return _name; }
/**
* Gets the explicity vertical datum identifier that will override a vertical
* datum specified by the tile source.
*/
optional<std::string>& verticalDatum() { return _vertDatum; }
const optional<std::string>& verticalDatum() const { return _vertDatum; }
/**
* Options for the underlyint tile source driver.
*/
optional<TileSourceOptions>& driver() { return _driver; }
const optional<TileSourceOptions>& driver() const { return _driver; }
/**
* Gets or sets the minimum of detail for which this layer should generate data.
*/
optional<unsigned>& minLevel() { return _minLevel; }
const optional<unsigned>& minLevel() const { return _minLevel; }
/**
* Gets or sets the minimum resolution for which this layer should generate data.
* The value is in units per pixel, using the base units of the layer's source data.
*/
optional<double>& minResolution() { return _minResolution; }
const optional<double>& minResolution() const { return _minResolution; }
/**
* The maximum level of detail for which this layer should generate data.
* Data from this layer will not appear in map tiles above the maxLevel.
*/
optional<unsigned>& maxLevel() { return _maxLevel; }
const optional<unsigned>& maxLevel() const { return _maxLevel; }
/**
* The maximum level resolution for which this layer should generate data.
* The value is in units per pixel, using the base units of the layer's source data.
*/
optional<double>& maxResolution() { return _maxResolution; }
const optional<double>& maxResolution() const { return _maxResolution; }
/**
* Overrides the maximum available LOD of the underlying tile source. The layer
* will never ask the tile source (or the cache) for an LOD higher than this.
* Data from this layer may still appear in map tiles above the maxDataLevel,
* but it will be upsampled from the maxDataLevel.
*/
optional<unsigned>& maxDataLevel() { return _maxDataLevel; }
const optional<unsigned>& maxDataLevel() const { return _maxDataLevel; }
/**
* Whether to use this layer with the map. Setting this to false means that
* the layer will remain in its map model but will not be used by the
* terrain engine. You cannot change the "enabled" state at runtime.
*/
optional<bool>& enabled() { return _enabled; }
const optional<bool>& enabled() const { return _enabled; }
/**
* Whether to render (or otherwise use) the layer.
*/
optional<bool>& visible() { return _visible; }
const optional<bool>& visible() const { return _visible; }
/**
* Whether to use exact cropping if image cropping is necessary
*/
optional<bool>& exactCropping() { return _exactCropping; }
const optional<bool>& exactCropping() const { return _exactCropping; }
/**
* The desired tile size to reproject imagery to if necessary.
*/
optional<unsigned int>& reprojectedTileSize() { return _reprojectedTileSize; }
const optional<unsigned int>& reprojectedTileSize() const { return _reprojectedTileSize; }
/**
* Explicit cache ID to uniquely identify the cache that matched this
* layer's tile source properties. This is usually automatically
* generated but you can override it here.
*/
optional<std::string>& cacheId() { return _cacheId; }
const optional<std::string>& cacheId() const { return _cacheId; }
/**
* The format that this MapLayer should use when caching. This can be a mime type
* or a file extension.
*/
optional<std::string>& cacheFormat() { return _cacheFormat; }
const optional<std::string>& cacheFormat() const { return _cacheFormat; }
/**
* Caching policy to use for this layer.
*/
optional<CachePolicy>& cachePolicy() { return _cachePolicy; }
const optional<CachePolicy>& cachePolicy() const { return _cachePolicy; }
/**
* The loading weight of this MapLayer (for threaded loading policies).
*/
optional<float>& loadingWeight() { return _loadingWeight; }
const optional<float>& loadingWeight() const { return _loadingWeight; }
/**
* The ratio used to expand the extent of a tile when the layer
* needs to be mosaiced to projected. This can be used to increase the
* number of tiles grabbed to ensure that enough data is grabbed to
* overlap the incoming tile.
*/
optional<double>& edgeBufferRatio() { return _edgeBufferRatio;}
const optional<double>& edgeBufferRatio() const { return _edgeBufferRatio; }
/**
* The hostname/port of a proxy server to use for HTTP communications on this layer
* Default = no proxy.
*/
optional<ProxySettings>& proxySettings() { return _proxySettings; }
const optional<ProxySettings>& proxySettings() const { return _proxySettings; }
public:
virtual Config getConfig() const { return getConfig(false); }
virtual Config getConfig( bool isolate ) const;
virtual void mergeConfig( const Config& conf );
private:
void fromConfig( const Config& conf );
void setDefaults();
std::string _name;
optional<std::string> _vertDatum;
optional<TileSourceOptions> _driver;
optional<unsigned> _minLevel;
optional<unsigned> _maxLevel;
optional<double> _minResolution;
optional<double> _maxResolution;
optional<float> _loadingWeight;
optional<bool> _exactCropping;
optional<bool> _enabled;
optional<bool> _visible;
optional<unsigned> _reprojectedTileSize;
optional<double> _edgeBufferRatio;
optional<unsigned> _maxDataLevel;
optional<std::string> _cacheId;
optional<std::string> _cacheFormat;
optional<CachePolicy> _cachePolicy;
optional<ProxySettings> _proxySettings;
};
/**
* Runtime property notification callback for TerrainLayers.
*/
struct TerrainLayerCallback : public osg::Referenced
{
virtual void onVisibleChanged( class TerrainLayer* layer ) { }
virtual ~TerrainLayerCallback() { }
};
typedef void (TerrainLayerCallback::*TerrainLayerCallbackMethodPtr)(class TerrainLayer* layer);
/**
* A layer that comprises the terrain skin (image or elevation layer)
*/
class OSGEARTH_EXPORT TerrainLayer : public Layer
{
protected:
TerrainLayer(
const TerrainLayerOptions& initOptions,
TerrainLayerOptions* runtimeOptions );
TerrainLayer(
const TerrainLayerOptions& initOptions,
TerrainLayerOptions* runtimeOptions,
TileSource* tileSource );
virtual ~TerrainLayer();
public:
/**
* The options data connected to this layer.
*/
const TerrainLayerOptions& getInitialOptions() const { return _initOptions; }
const TerrainLayerOptions& getTerrainLayerRuntimeOptions() const { return *_runtimeOptions; }
/**
* Whether to use this layer. Note, a layer is enabled/disabled once and its
* status cannot be changed.
*/
bool getEnabled() const { return *_runtimeOptions->enabled(); }
/**
* Whether to draw (or otherwise use) this layer.
*/
void setVisible( bool value );
bool getVisible() const { return getEnabled() && *_runtimeOptions->visible(); }
/**
* Gets the readable name of the map layer.
*/
const std::string& getName() const { return getTerrainLayerRuntimeOptions().name(); }
/**
* Sets the readable name of the map layer
*/
void setName( const std::string& name ) { _runtimeOptions->name() = name; }
/**
* Gets the profile of this MapLayer
*/
const Profile* getProfile() const;
/**
* Gets the underlying TileSource engine that serves this map layer. Use with caution.
*/
TileSource* getTileSource() const;
/**
* Gets the tile size of the this MapLayer
*/
unsigned int getTileSize() const;
/**
* Whether the layer represents dynamic data, i.e. tile data that can change.
*/
bool isDynamic() const;
/**
* Whether the given key is valid for this layer
*/
virtual bool isKeyValid(const TileKey& key) const;
/**
* Whether the data for the specified tile key is in the cache.
*/
virtual bool isCached(const TileKey& key) const;
/**
* Gives the terrain layer a hint as to what the target profile of
* images will be. This is optional, but it may allow the layer to enable
* certain optimizations since it has more information as to how the
* data will be used.
*/
virtual void setTargetProfileHint( const Profile* profile );
/**
* The cache bin for storing data generated by this layer
*/
virtual CacheBin* getCacheBin( const Profile* profile );
/**
* Gets the Cache to be used on this TerrainLayer.
*/
Cache* getCache() const { return _cache.get(); }
/**
* Convenience function to check for cache_only mode
*/
bool isCacheOnly() const {
return
_runtimeOptions->cachePolicy().isSet() &&
_runtimeOptions->cachePolicy()->usage() == CachePolicy::USAGE_CACHE_ONLY;
}
public: // Layer interface
virtual SequenceControl* getSequenceControl();
public:
/**
* Metadata about the terrain layer that is stored in the cache, and read
* when the cache is opened.
*/
struct CacheBinMetadata
{
CacheBinMetadata() { }
CacheBinMetadata( const CacheBinMetadata& rhs ) :
_empty ( rhs._empty ),
_cacheBinId ( rhs._cacheBinId ),
_sourceName ( rhs._sourceName ),
_sourceDriver ( rhs._sourceDriver ),
_sourceProfile( rhs._sourceProfile ),
_cacheProfile ( rhs._cacheProfile ) { }
CacheBinMetadata( const Config& conf )
{
_empty = conf.empty();
conf.getIfSet ( "cachebin_id", _cacheBinId );
conf.getIfSet ( "source_name", _sourceName );
conf.getIfSet ( "source_driver", _sourceDriver );
conf.getObjIfSet( "source_profile", _sourceProfile );
conf.getObjIfSet( "cache_profile", _cacheProfile );
}
Config getConfig() const
{
Config conf( "osgearth_terrainlayer_cachebin" );
conf.addIfSet ( "cachebin_id", _cacheBinId );
conf.addIfSet ( "source_name", _sourceName );
conf.addIfSet ( "source_driver", _sourceDriver );
conf.addObjIfSet( "source_profile", _sourceProfile );
conf.addObjIfSet( "cache_profile", _cacheProfile );
return conf;
}
bool _empty;
optional<std::string> _cacheBinId;
optional<std::string> _sourceName;
optional<std::string> _sourceDriver;
optional<ProfileOptions> _sourceProfile;
optional<ProfileOptions> _cacheProfile;
};
/**
* Access to information about the cache
*/
bool getCacheBinMetadata( const Profile* profile, CacheBinMetadata& output );
protected:
virtual void initTileSource();
CacheBin* getCacheBin( const Profile* profile, const std::string& binId );
protected:
osg::ref_ptr<TileSource> _tileSource;
osg::ref_ptr<const Profile> _profile;
osg::ref_ptr<const Profile> _targetProfileHint;
bool _tileSourceInitAttempted;
bool _tileSourceInitFailed;
unsigned _tileSize;
osg::ref_ptr<osgDB::Options> _dbOptions;
void setCachePolicy( const CachePolicy& cp );
const CachePolicy& getCachePolicy() const;
private:
std::string _name;
std::string _referenceURI;
OpenThreads::Mutex _initTileSourceMutex;
TerrainLayerOptions _initOptions;
TerrainLayerOptions* _runtimeOptions;
osg::ref_ptr<Cache> _cache;
// maps profile signature to cache bin pointer.
struct CacheBinInfo
{
osg::ref_ptr<CacheBin> _bin;
optional<CacheBinMetadata> _metadata;
};
typedef std::map< std::string, CacheBinInfo > CacheBinInfoMap; // indexed by profile signature
CacheBinInfoMap _cacheBins;
Threading::ReadWriteMutex _cacheBinsMutex;
void init();
//void applyCacheFormat( CacheBin* bin, const std::string& format );
virtual void fireCallback( TerrainLayerCallbackMethodPtr method ) =0;
// methods accesible by Map:
friend class Map;
void setDBOptions( const osgDB::Options* dbOptions );
void initializeCachePolicy( const osgDB::Options* );
void storeProxySettings( osgDB::Options* );
/**
* Sets the cache to be used on this MapLayer
* TODO: is it legal to set this at any time?
*/
void setCache( Cache* cache );
};
typedef std::vector<osg::ref_ptr<TerrainLayer> > TerrainLayerVector;
} // namespace TerrainLayer
#endif // OSGEARTH_TERRAIN_LAYER_H
|