osgEarth 2.1.1
|
Public Member Functions | |
const TerrainLayerOptions & | getTerrainLayerOptions () const |
void | setEnabled (bool value) |
bool | getEnabled () const |
const std::string & | getName () const |
const Profile * | getProfile () const |
TileSource * | getTileSource () const |
unsigned int | getTileSize () const |
unsigned int | getMaxDataLevel () const |
bool | isDynamic () const |
const std::string & | getCacheFormat () const |
bool | isKeyValid (const TileKey &key) const |
Cache * | getCache () const |
void | setCache (Cache *cache) |
const CacheSpec & | getCacheSpec () const |
virtual void | setTargetProfileHint (const Profile *profile) |
bool | isCacheOnly () const |
Protected Member Functions | |
TerrainLayer (TerrainLayerOptions *options) | |
TerrainLayer (TerrainLayerOptions *options, TileSource *tileSource) | |
virtual void | initTileSource () |
virtual std::string | suggestCacheFormat () const |
Protected Attributes | |
osg::ref_ptr< TileSource > | _tileSource |
osg::ref_ptr< Cache > | _cache |
CacheSpec | _cacheSpec |
osg::ref_ptr< const Profile > | _profile |
osg::ref_ptr< const Profile > | _cacheProfile |
osg::ref_ptr< const Profile > | _targetProfileHint |
bool | _tileSourceInitialized |
unsigned | _tileSize |
Private Member Functions | |
void | init () |
virtual void | fireCallback (TerrainLayerCallbackMethodPtr method)=0 |
void | setReferenceURI (const std::string &uri) |
void | setCacheOnly (bool value) |
Private Attributes | |
std::string | _name |
std::string | _referenceURI |
OpenThreads::Mutex | _initTileSourceMutex |
TerrainLayerOptions * | _runtimeOptions |
Friends | |
class | Map |
A layer that comprises the terrain skin (image or elevation layer)
Definition at line 195 of file TerrainLayer.
TerrainLayer::TerrainLayer | ( | TerrainLayerOptions * | options | ) | [protected] |
Definition at line 133 of file TerrainLayer.cpp.
: _runtimeOptions( options ) { init(); }
TerrainLayer::TerrainLayer | ( | TerrainLayerOptions * | options, |
TileSource * | tileSource | ||
) | [protected] |
Definition at line 139 of file TerrainLayer.cpp.
: _runtimeOptions( options ), _tileSource ( tileSource ) { init(); }
virtual void osgEarth::TerrainLayer::fireCallback | ( | TerrainLayerCallbackMethodPtr | method | ) | [private, pure virtual] |
Implemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.
Cache* osgEarth::TerrainLayer::getCache | ( | ) | const [inline] |
Gets the Cache to be used on this TerrainLayer.
Definition at line 259 of file TerrainLayer.
{ return _cache.get(); }
const std::string& osgEarth::TerrainLayer::getCacheFormat | ( | ) | const [inline] |
Definition at line 247 of file TerrainLayer.
{ return *_runtimeOptions->cacheFormat(); }
const CacheSpec& osgEarth::TerrainLayer::getCacheSpec | ( | ) | const [inline] |
Gets the key that this layer uses to access the cache
Definition at line 270 of file TerrainLayer.
{ return _cacheSpec; }
bool osgEarth::TerrainLayer::getEnabled | ( | ) | const [inline] |
Definition at line 214 of file TerrainLayer.
{ return *_runtimeOptions->enabled(); }
unsigned int TerrainLayer::getMaxDataLevel | ( | ) | const |
Gets the maximum data level of this MapLayer
Definition at line 254 of file TerrainLayer.cpp.
{ //Try the setting first if ( _runtimeOptions->maxDataLevel().isSet() ) { return _runtimeOptions->maxDataLevel().get(); } //Try the TileSource TileSource* ts = getTileSource(); if ( ts ) { return ts->getMaxDataLevel(); } //Just default return 20; }
const std::string& osgEarth::TerrainLayer::getName | ( | ) | const [inline] |
Gets the readable name of the map layer.
Definition at line 219 of file TerrainLayer.
{ return getTerrainLayerOptions().name(); }
const Profile * TerrainLayer::getProfile | ( | ) | const |
Gets the profile of this MapLayer
Definition at line 234 of file TerrainLayer.cpp.
{ if ( !_profile.valid() ) { if ( _runtimeOptions->cacheOnly() == false && !_tileSourceInitialized ) { // Call getTileSource to make sure the TileSource is initialized getTileSource(); } if ( _tileSource.valid() && !_profile.valid() ) { const_cast<TerrainLayer*>(this)->_profile = _tileSource->getProfile(); } } return _profile.get(); }
const TerrainLayerOptions& osgEarth::TerrainLayer::getTerrainLayerOptions | ( | ) | const [inline] |
The options data connected to this layer.
Reimplemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.
Definition at line 207 of file TerrainLayer.
{ return *_runtimeOptions; }
unsigned TerrainLayer::getTileSize | ( | ) | const |
Gets the tile size of the this MapLayer
Definition at line 275 of file TerrainLayer.cpp.
{ TileSource* ts = getTileSource(); return ts ? ts->getPixelsPerTile() : _tileSize; }
TileSource * TerrainLayer::getTileSource | ( | ) | const |
Gets the underlying TileSource engine that serves this map layer. Use with caution.
Definition at line 216 of file TerrainLayer.cpp.
{ if ((_tileSource.valid() && !_tileSourceInitialized) || (!_tileSource.valid() && _runtimeOptions->cacheOnly() == false) ) { OpenThreads::ScopedLock< OpenThreads::Mutex > lock(const_cast<TerrainLayer*>(this)->_initTileSourceMutex ); // double-check pattern if ((_tileSource.valid() && !_tileSourceInitialized) || (!_tileSource.valid() && _runtimeOptions->cacheOnly() == false)) { const_cast<TerrainLayer*>(this)->initTileSource(); } } return _tileSource.get(); }
void TerrainLayer::init | ( | ) | [private] |
Reimplemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.
Definition at line 147 of file TerrainLayer.cpp.
{ _tileSourceInitialized = false; _tileSize = 256; }
void TerrainLayer::initTileSource | ( | ) | [protected, virtual] |
Reimplemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.
Definition at line 297 of file TerrainLayer.cpp.
{ OE_DEBUG << LC << "Initializing tile source ..." << std::endl; // instantiate it from driver options if it has not already been created: if ( !_tileSource.valid() ) { if ( _runtimeOptions->driver().isSet() ) { _tileSource = TileSourceFactory::create( *_runtimeOptions->driver() ); } } // next check for an override-profile. The profile usually comes from the // TileSource itself, but you have the option of overriding: osg::ref_ptr<const Profile> overrideProfile; if ( _runtimeOptions->profile().isSet() ) { overrideProfile = Profile::create( *_runtimeOptions->profile() ); } // Initialize the profile with the context information: if ( _tileSource.valid() ) { _tileSource->initialize( _referenceURI, overrideProfile.get() ); if ( _tileSource->isOK() ) { _tileSize = _tileSource->getPixelsPerTile(); } else { OE_WARN << "Could not initialize TileSource for layer " << getName() << std::endl; _tileSource = NULL; } } // Set the cache format to the native format of the TileSource if it isn't already set. if ( _runtimeOptions->cacheFormat()->empty() ) { _runtimeOptions->cacheFormat() = suggestCacheFormat(); _cacheSpec = CacheSpec( _cacheSpec.cacheId(), *_runtimeOptions->cacheFormat(), _cacheSpec.name() ); } // Set the profile from the TileSource if possible: if ( _tileSource.valid() ) { _profile = _tileSource->getProfile(); } // Otherwise, force cache-only mode (since there is no tilesource). The layer will try to // establish a profile from the metadata in the cache instead. else if (_cache.valid()) { OE_NOTICE << "Could not initialize TileSource " << _name << " but cache is valid. Setting layer to cache_only." << std::endl; _runtimeOptions->cacheOnly() = true; } // check the environment to see if cache only should be enabled if ( _runtimeOptions->cacheOnly() == false && ::getenv("OSGEARTH_CACHE_ONLY") != 0 ) { _runtimeOptions->cacheOnly() = true; OE_INFO << "CACHE-ONLY mode enabled!!" << std::endl; } _tileSourceInitialized = true; }
bool osgEarth::TerrainLayer::isCacheOnly | ( | ) | const [inline] |
Whether this layer is in "cache only" mode (i.e. data will only be read from the cache and not from the tile source
Definition at line 284 of file TerrainLayer.
{ return *_runtimeOptions->cacheOnly(); }
bool TerrainLayer::isDynamic | ( | ) | const |
Whether the layer represents dynamic data, i.e. tile data that can change.
Definition at line 282 of file TerrainLayer.cpp.
{ TileSource* ts = getTileSource(); return ts ? ts->isDynamic() : false; }
bool TerrainLayer::isKeyValid | ( | const TileKey & | key | ) | const |
Whether the given key is valid for this layer
Definition at line 366 of file TerrainLayer.cpp.
{ if (!key.valid()) return false; // Check to see if explicit levels of detail are set if ( _runtimeOptions->minLevel().isSet() && (int)key.getLevelOfDetail() < _runtimeOptions->minLevel().value() ) return false; if ( _runtimeOptions->maxLevel().isSet() && (int)key.getLevelOfDetail() > _runtimeOptions->maxLevel().value() ) return false; // Check to see if levels of detail based on resolution are set if ( _runtimeOptions->minLevelResolution().isSet() ) { unsigned int minLevel = getProfile()->getLevelOfDetailForHorizResolution( _runtimeOptions->minLevelResolution().value(), getTileSize() ); OE_DEBUG << "Computed min level of " << minLevel << std::endl; if (key.getLevelOfDetail() < minLevel) return false; } if (_runtimeOptions->maxLevelResolution().isSet()) { unsigned int maxLevel = getProfile()->getLevelOfDetailForHorizResolution( _runtimeOptions->maxLevelResolution().value(), getTileSize() ); OE_DEBUG << "Computed max level of " << maxLevel << std::endl; if (key.getLevelOfDetail() > maxLevel) return false; } return true; }
void TerrainLayer::setCache | ( | Cache * | cache | ) |
Sets the cache to be used on this MapLayer TODO: is it legal to set this at any time?
Definition at line 154 of file TerrainLayer.cpp.
{ if (_cache.get() != cache) { _cache = cache; // Read properties from the cache if not already set if ( _cache.valid() && _runtimeOptions->cacheEnabled() == true ) { // create the unique cache ID for the tile configuration. std::string cacheId; if ( _runtimeOptions->cacheId().isSet() && !_runtimeOptions->cacheId()->empty() ) { // user expliticy set a cacheId in the terrain layer options. cacheId = *_runtimeOptions->cacheId(); } else { // system will generate a cacheId. Config hashConf = _runtimeOptions->driver()->getConfig(); // remove cache-control properties before hashing. hashConf.remove( "cache_only" ); hashConf.remove( "cache_enabled" ); std::stringstream buf; //OE_NOTICE << hashConf.toHashString() << std::endl; buf << std::fixed << std::setfill('0') << std::hex << osgEarth::hashString( hashConf.toHashString() ); cacheId = buf.str(); } // try to load the properties from the cache; if that is unsuccesful, // create new properties. osg::ref_ptr<const Profile> profile; _cache->loadProperties( cacheId, _cacheSpec, profile, _tileSize ); // Set the profile if it hasn't already been set if (!_profile.valid() && profile.valid()) { _profile = profile.get(); } // Set the cache format if it hasn't been explicitly set if ( !_runtimeOptions->cacheFormat().isSet() ) { _runtimeOptions->cacheFormat() = _cacheSpec.format(); } _cacheSpec = CacheSpec( cacheId, *_runtimeOptions->cacheFormat(), getName() ); } } }
void TerrainLayer::setCacheOnly | ( | bool | value | ) | [private] |
Definition at line 410 of file TerrainLayer.cpp.
{ _runtimeOptions->cacheOnly() = value; }
void TerrainLayer::setEnabled | ( | bool | value | ) |
Whether to draw this layer.
Definition at line 397 of file TerrainLayer.cpp.
{ _runtimeOptions->enabled() = value; fireCallback( &TerrainLayerCallback::onEnabledChanged ); }
void TerrainLayer::setReferenceURI | ( | const std::string & | uri | ) | [private] |
Definition at line 404 of file TerrainLayer.cpp.
{ _referenceURI = uri; }
void TerrainLayer::setTargetProfileHint | ( | const Profile * | profile | ) | [virtual] |
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.
Reimplemented in osgEarth::ImageLayer.
Definition at line 210 of file TerrainLayer.cpp.
{ _targetProfileHint = profile; }
std::string TerrainLayer::suggestCacheFormat | ( | ) | const [protected, virtual] |
Reimplemented in osgEarth::ElevationLayer.
Definition at line 290 of file TerrainLayer.cpp.
{ std::string ext = _tileSource.valid() ? _tileSource->getExtension() : ""; return !ext.empty() ? ext : "png"; }
friend class Map [friend] |
Definition at line 315 of file TerrainLayer.
osg::ref_ptr<Cache> osgEarth::TerrainLayer::_cache [protected] |
Definition at line 295 of file TerrainLayer.
osg::ref_ptr<const Profile> osgEarth::TerrainLayer::_cacheProfile [protected] |
Definition at line 299 of file TerrainLayer.
CacheSpec osgEarth::TerrainLayer::_cacheSpec [protected] |
Definition at line 296 of file TerrainLayer.
OpenThreads::Mutex osgEarth::TerrainLayer::_initTileSourceMutex [private] |
Definition at line 308 of file TerrainLayer.
std::string osgEarth::TerrainLayer::_name [private] |
Reimplemented from osgEarth::Layer.
Definition at line 306 of file TerrainLayer.
osg::ref_ptr<const Profile> osgEarth::TerrainLayer::_profile [protected] |
Definition at line 298 of file TerrainLayer.
std::string osgEarth::TerrainLayer::_referenceURI [private] |
Definition at line 307 of file TerrainLayer.
Reimplemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.
Definition at line 309 of file TerrainLayer.
osg::ref_ptr<const Profile> osgEarth::TerrainLayer::_targetProfileHint [protected] |
Definition at line 300 of file TerrainLayer.
unsigned osgEarth::TerrainLayer::_tileSize [protected] |
Definition at line 303 of file TerrainLayer.
osg::ref_ptr<TileSource> osgEarth::TerrainLayer::_tileSource [protected] |
Definition at line 294 of file TerrainLayer.
bool osgEarth::TerrainLayer::_tileSourceInitialized [protected] |
Definition at line 302 of file TerrainLayer.