osgEarth 2.1.1
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

osgEarth::Registry Class Reference

Inheritance diagram for osgEarth::Registry:
Collaboration diagram for osgEarth::Registry:

List of all members.

Public Member Functions

const ProfilegetNamedProfile (const std::string &name) const
const ProfilegetGlobalGeodeticProfile () const
const ProfilegetGlobalMercatorProfile () const
const ProfilegetCubeProfile () const
OpenThreads::ReentrantMutex & getGDALMutex ()
CachegetCacheOverride () const
void setCacheOverride (Cache *cacheOverride)
void addMimeTypeExtensionMapping (const std::string fromMimeType, const std::string toExt)
osgDB::ReaderWriter * getReaderWriterForMimeType (const std::string &mimeType)
bool isBlacklisted (const std::string &filename)
void blacklist (const std::string &filename)
unsigned int getNumBlacklistedFilenames ()
void clearBlacklist ()
const VerticalSpatialReferencegetDefaultVSRS () const
const CapabilitiesgetCapabilities () const
ShaderFactorygetShaderFactory () const
void setShaderFactory (ShaderFactory *lib)
TaskServiceManagergetTaskServiceManager ()
UID createUID ()
void setCacheDirectory (const std::string &dir)
const std::string & getCacheDirectory () const
const osgDB::OptionsgetDefaultOptions () const
osgDB::OptionscloneOrCreateOptions (const osgDB::Options *options=0L) const

Static Public Member Functions

static Registryinstance (bool erase=false)

Protected Types

typedef std::map< std::string,
std::string > 
MimeTypeExtensionMap
typedef std::set< std::string > StringSet

Protected Member Functions

virtual ~Registry ()
 Registry ()
void destruct ()
void initCapabilities ()

Protected Attributes

OpenThreads::ReentrantMutex _gdal_mutex
bool _gdal_registered
osg::ref_ptr< const Profile_global_geodetic_profile
osg::ref_ptr< const Profile_global_mercator_profile
osg::ref_ptr< const Profile_cube_profile
OpenThreads::Mutex _regMutex
int _numGdalMutexGets
MimeTypeExtensionMap _mimeTypeExtMap
osg::ref_ptr< Cache_cacheOverride
StringSet _blacklistedFilenames
OpenThreads::Mutex _blacklistMutex
osg::ref_ptr< const
VerticalSpatialReference
_defaultVSRS
osg::ref_ptr< ShaderFactory_shaderLib
osg::ref_ptr< TaskServiceManager_taskServiceManager
int _uidGen
osg::ref_ptr< Capabilities_caps
osg::ref_ptr< osgDB::Options_defaultOptions

Detailed Description

Application-wide global repository.

Definition at line 44 of file Registry.


Member Typedef Documentation

typedef std::map< std::string, std::string> osgEarth::Registry::MimeTypeExtensionMap [protected]

Definition at line 163 of file Registry.

typedef std::set<std::string> osgEarth::Registry::StringSet [protected]

Definition at line 169 of file Registry.


Constructor & Destructor Documentation

Registry::~Registry ( ) [protected, virtual]

Definition at line 88 of file Registry.cpp.

{
}
Registry::Registry ( ) [protected]

Definition at line 42 of file Registry.cpp.

                   :
osg::Referenced(true),
_gdal_registered( false ),
_numGdalMutexGets( 0 ),
_uidGen( 0 ),
_caps( 0L )
{
    OGRRegisterAll();
    GDALAllRegister();

    // add built-in mime-type extension mappings
    for( int i=0; ; i+=2 )
    {
        std::string mimeType = builtinMimeTypeExtMappings[i];
        if ( mimeType.length() == 0 )
            break;
        addMimeTypeExtensionMapping( mimeType, builtinMimeTypeExtMappings[i+1] );
    }

    _shaderLib = new ShaderFactory();
    _taskServiceManager = new TaskServiceManager();

    // activate KMZ support
    osgDB::Registry::instance()->addFileExtensionAlias( "kmz", "kml" );
    osgDB::Registry::instance()->addArchiveExtension( "kmz" );    
#if OSG_MIN_VERSION_REQUIRED(3,0,0)
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kml+xml", "kml" );
    osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kmz", "kmz" );
#endif

    // set up our default r/w options to NOT cache archives!
    _defaultOptions = new osgDB::Options();
    _defaultOptions->setObjectCacheHint( (osgDB::Options::CacheHintOptions)
        ((int)_defaultOptions->getObjectCacheHint() & ~osgDB::Options::CACHE_ARCHIVES) );

    // see if there's a cache in the envvar
    const char* cachePath = ::getenv("OSGEARTH_CACHE_PATH");
    if ( cachePath )
    {
        TMSCacheOptions tmso;
        tmso.setPath( std::string(cachePath) );
        setCacheOverride( new TMSCache(tmso) );
        OE_INFO << LC << "Setting cache (from env.var.) to " << tmso.path() << std::endl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

void Registry::addMimeTypeExtensionMapping ( const std::string  fromMimeType,
const std::string  toExt 
)

Registers a mapping of a mime-type to an extension. A process fetching data over HTTP can use this facility to determine the proper ReaderWriter to use when there is no filename extension to rely upon.

Definition at line 210 of file Registry.cpp.

{
    _mimeTypeExtMap[fromMimeType] = toExt;
}

Here is the caller graph for this function:

void Registry::blacklist ( const std::string &  filename)

Blacklist the given filename

Definition at line 232 of file Registry.cpp.

{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_blacklistMutex);
    _blacklistedFilenames.insert( filename );
    OE_DEBUG << "Blacklist size = " << _blacklistedFilenames.size() << std::endl;
}

Here is the caller graph for this function:

void Registry::clearBlacklist ( )

Clears the blacklist

Definition at line 240 of file Registry.cpp.

{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_blacklistMutex);
    _blacklistedFilenames.clear();
    OE_DEBUG << "Blacklist size = " << _blacklistedFilenames.size() << std::endl;
}

Here is the caller graph for this function:

osgDB::Options * Registry::cloneOrCreateOptions ( const osgDB::Options options = 0L) const

Clones an options structure (fixing the archive caching), or creates a new one.

Definition at line 294 of file Registry.cpp.

{
    osgDB::Options* newOptions = input ? static_cast<osgDB::Options*>(input->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::Options();

    // clear the CACHE_ARCHIVES flag because it is evil
    if ( ((int)newOptions->getObjectCacheHint() & osgDB::Options::CACHE_ARCHIVES) != 0 )
    {
        newOptions->setObjectCacheHint( (osgDB::Options::CacheHintOptions)
            ((int)newOptions->getObjectCacheHint() & ~osgDB::Options::CACHE_ARCHIVES) );
    }

    return newOptions;
}

Here is the caller graph for this function:

UID Registry::createUID ( )

Generates an instance-wide global unique ID.

Definition at line 286 of file Registry.cpp.

{
    static Mutex s_uidGenMutex;
    ScopedLock<Mutex> lock( s_uidGenMutex );
    return (UID)( _uidGen++ );
}

Here is the caller graph for this function:

void Registry::destruct ( ) [protected]

Definition at line 105 of file Registry.cpp.

{
    _cacheOverride = 0;
}
const std::string& osgEarth::Registry::getCacheDirectory ( ) const
osgEarth::Cache * Registry::getCacheOverride ( ) const

Global override of map caching settings.

Definition at line 199 of file Registry.cpp.

{
        return _cacheOverride.get();
}

Here is the caller graph for this function:

const Capabilities & Registry::getCapabilities ( ) const

Gets the graphics hardware capabilities for this platform

Definition at line 255 of file Registry.cpp.

{
    if ( !_caps.valid() )
        const_cast<Registry*>(this)->initCapabilities();

    return *_caps;
}

Here is the caller graph for this function:

const Profile * Registry::getCubeProfile ( ) const

Gets the unified cube builtin profile

Definition at line 163 of file Registry.cpp.

{
    if ( !_cube_profile.valid() )
    {
        GDAL_SCOPED_LOCK;

        if ( !_cube_profile.valid() ) // double-check pattern
        {
            const_cast<Registry*>(this)->_cube_profile = new UnifiedCubeProfile();
        }
    }
    return _cube_profile.get();
}

Here is the caller graph for this function:

const osgDB::Options* osgEarth::Registry::getDefaultOptions ( ) const [inline]

Gets the default set of osgDB::Options to use.

Definition at line 138 of file Registry.

{ return _defaultOptions.get(); }
const VerticalSpatialReference * Registry::getDefaultVSRS ( ) const

The system wide default vertical spatial reference system.

Definition at line 191 of file Registry.cpp.

{
    if ( !_defaultVSRS.valid() )
        const_cast<Registry*>(this)->_defaultVSRS = new VerticalSpatialReference( Units::METERS );
    return _defaultVSRS.get();
}

Here is the caller graph for this function:

OpenThreads::ReentrantMutex & Registry::getGDALMutex ( )

Access to the application-wide GDAL serialization mutex. GDAL is not thread-safe.

Definition at line 112 of file Registry.cpp.

{
    //_numGdalMutexGets++;
    //OE_NOTICE << "GDAL = " << _numGdalMutexGets << std::endl;
    return _gdal_mutex;
}
const Profile * Registry::getGlobalGeodeticProfile ( ) const

Gets the global-geodetic builtin profile

Definition at line 121 of file Registry.cpp.

{
    if ( !_global_geodetic_profile.valid() )
    {
        GDAL_SCOPED_LOCK;

        if ( !_global_geodetic_profile.valid() ) // double-check pattern
        {
            const_cast<Registry*>(this)->_global_geodetic_profile = Profile::create(
                "epsg:4326",
                -180.0, -90.0, 180.0, 90.0,
                "",
                2, 1 );
        }
    }
    return _global_geodetic_profile.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

const Profile * Registry::getGlobalMercatorProfile ( ) const

Gets the global-meractor builtin profile

Definition at line 141 of file Registry.cpp.

{
    if ( !_global_mercator_profile.valid() )
    {
        GDAL_SCOPED_LOCK;

        if ( !_global_mercator_profile.valid() ) // double-check pattern
        {
            // automatically figure out proper mercator extents:
            const SpatialReference* srs = SpatialReference::create( "spherical-mercator" );
            //double e, dummy;
            //srs->getGeographicSRS()->transform( 180.0, 0.0, srs, e, dummy );            
            /*const_cast<Registry*>(this)->_global_mercator_profile = Profile::create(
                srs, -e, -e, e, e, 0L, 1, 1 );*/
            const_cast<Registry*>(this)->_global_mercator_profile = Profile::create(
                srs, MERC_MINX, MERC_MINY, MERC_MAXX, MERC_MAXY, 0L, 1, 1 );
        }
    }
    return _global_mercator_profile.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

const Profile * Registry::getNamedProfile ( const std::string &  name) const

Gets a well-known named profile instance.

Definition at line 178 of file Registry.cpp.

{
    if ( name == STR_GLOBAL_GEODETIC )
        return getGlobalGeodeticProfile();
    else if ( name == STR_GLOBAL_MERCATOR )
        return getGlobalMercatorProfile();
    else if ( name == STR_CUBE )
        return getCubeProfile();
    else
        return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int Registry::getNumBlacklistedFilenames ( )

Gets the number of blacklisted filenames

Definition at line 248 of file Registry.cpp.

{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_blacklistMutex);
    return _blacklistedFilenames.size();
}

Here is the caller graph for this function:

osgDB::ReaderWriter * Registry::getReaderWriterForMimeType ( const std::string &  mimeType)

gets a reader/writer that handles the extension mapped to by one of the registered mime-types.

Definition at line 216 of file Registry.cpp.

{
    MimeTypeExtensionMap::const_iterator i = _mimeTypeExtMap.find( mimeType );
    return i != _mimeTypeExtMap.end()?
        osgDB::Registry::instance()->getReaderWriterForExtension( i->second ) :
        NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ShaderFactory * Registry::getShaderFactory ( ) const

Gets or sets the default shader factory. You can replace the default shader factory if you want to alter any of osgEarth's baseline shaders (advanced usage).

Definition at line 273 of file Registry.cpp.

{
    return _shaderLib.get();
}

Here is the caller graph for this function:

TaskServiceManager* osgEarth::Registry::getTaskServiceManager ( ) [inline]

Gets a reference to the global task service manager.

Definition at line 120 of file Registry.

                                                    {
            return _taskServiceManager.get(); }

Here is the call graph for this function:

void Registry::initCapabilities ( ) [protected]

Definition at line 265 of file Registry.cpp.

{
    ScopedLock<Mutex> lock( s_initCapsMutex ); // double-check pattern (see getCapabilities)
    if ( !_caps.valid() )
        _caps = new Capabilities();
}
Registry * Registry::instance ( bool  erase = false) [static]

Access the global Registry singleton.

Definition at line 92 of file Registry.cpp.

{
    static osg::ref_ptr<Registry> s_registry = new Registry;

    if (erase) 
    {   
        s_registry->destruct();
        s_registry = 0;
    }

    return s_registry.get(); // will return NULL on erase
}

Here is the call graph for this function:

bool Registry::isBlacklisted ( const std::string &  filename)

Whether the given filename is blacklisted

Definition at line 225 of file Registry.cpp.

{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_blacklistMutex);
    return (_blacklistedFilenames.count(filename)==1);
}

Here is the caller graph for this function:

void osgEarth::Registry::setCacheDirectory ( const std::string &  dir)

Gets or sets the local root of the system default cache.

void Registry::setCacheOverride ( osgEarth::Cache cacheOverride)

Definition at line 205 of file Registry.cpp.

{
        _cacheOverride = cacheOverride;
}

Here is the caller graph for this function:

void Registry::setShaderFactory ( ShaderFactory lib)

Definition at line 279 of file Registry.cpp.

{
    if ( lib != 0L && lib != _shaderLib.get() )
        _shaderLib = lib;
}

Member Data Documentation

Definition at line 170 of file Registry.

OpenThreads::Mutex osgEarth::Registry::_blacklistMutex [protected]

Definition at line 171 of file Registry.

osg::ref_ptr<Cache> osgEarth::Registry::_cacheOverride [protected]

Definition at line 167 of file Registry.

osg::ref_ptr< Capabilities > osgEarth::Registry::_caps [protected]

Definition at line 181 of file Registry.

osg::ref_ptr<const Profile> osgEarth::Registry::_cube_profile [protected]

Definition at line 158 of file Registry.

Definition at line 184 of file Registry.

Definition at line 173 of file Registry.

OpenThreads::ReentrantMutex osgEarth::Registry::_gdal_mutex [protected]

Definition at line 153 of file Registry.

Definition at line 154 of file Registry.

osg::ref_ptr<const Profile> osgEarth::Registry::_global_geodetic_profile [protected]

Definition at line 156 of file Registry.

osg::ref_ptr<const Profile> osgEarth::Registry::_global_mercator_profile [protected]

Definition at line 157 of file Registry.

Definition at line 165 of file Registry.

Definition at line 161 of file Registry.

OpenThreads::Mutex osgEarth::Registry::_regMutex [protected]

Definition at line 160 of file Registry.

osg::ref_ptr<ShaderFactory> osgEarth::Registry::_shaderLib [protected]

Definition at line 175 of file Registry.

Definition at line 177 of file Registry.

int osgEarth::Registry::_uidGen [protected]

Definition at line 179 of file Registry.


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