osgEarth 2.1.1
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends

osgEarth::TerrainLayer Class Reference

Inheritance diagram for osgEarth::TerrainLayer:
Collaboration diagram for osgEarth::TerrainLayer:

List of all members.

Public Member Functions

const TerrainLayerOptionsgetTerrainLayerOptions () const
void setEnabled (bool value)
bool getEnabled () const
const std::string & getName () const
const ProfilegetProfile () const
TileSourcegetTileSource () const
unsigned int getTileSize () const
unsigned int getMaxDataLevel () const
bool isDynamic () const
const std::string & getCacheFormat () const
bool isKeyValid (const TileKey &key) const
CachegetCache () const
void setCache (Cache *cache)
const CacheSpecgetCacheSpec () 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

Detailed Description

A layer that comprises the terrain skin (image or elevation layer)

Definition at line 195 of file TerrainLayer.


Constructor & Destructor Documentation

TerrainLayer::TerrainLayer ( TerrainLayerOptions options) [protected]

Definition at line 133 of file TerrainLayer.cpp.

                                                         :
_runtimeOptions( options )
{
    init();
}

Here is the call graph for this function:

TerrainLayer::TerrainLayer ( TerrainLayerOptions options,
TileSource tileSource 
) [protected]

Definition at line 139 of file TerrainLayer.cpp.

                                                                                 :
_runtimeOptions( options ),
_tileSource    ( tileSource )
{
    init();
}

Here is the call graph for this function:


Member Function Documentation

virtual void osgEarth::TerrainLayer::fireCallback ( TerrainLayerCallbackMethodPtr  method) [private, pure virtual]

Implemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.

Here is the caller graph for this function:

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(); }

Here is the caller graph for this function:

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; }

Here is the caller graph for this function:

bool osgEarth::TerrainLayer::getEnabled ( ) const [inline]

Definition at line 214 of file TerrainLayer.

{ return *_runtimeOptions->enabled(); }

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

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(); }

Here is the caller graph for this function:

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();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TerrainLayer::init ( ) [private]

Reimplemented in osgEarth::ElevationLayer, and osgEarth::ImageLayer.

Definition at line 147 of file TerrainLayer.cpp.

{
    _tileSourceInitialized = false;
    _tileSize              = 256;
}

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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(); }

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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() );
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TerrainLayer::setCacheOnly ( bool  value) [private]

Definition at line 410 of file TerrainLayer.cpp.

{
    _runtimeOptions->cacheOnly() = value;
}

Here is the call graph for this function:

void TerrainLayer::setEnabled ( bool  value)

Whether to draw this layer.

Definition at line 397 of file TerrainLayer.cpp.

Here is the call graph for this function:

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;
}

Here is the caller graph for this function:

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";
}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class Map [friend]

Definition at line 315 of file TerrainLayer.


Member Data Documentation

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.

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.

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.

Definition at line 294 of file TerrainLayer.

Definition at line 302 of file TerrainLayer.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines