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

osgEarth::Symbology::ResourceLibrary Class Reference

Inheritance diagram for osgEarth::Symbology::ResourceLibrary:
Collaboration diagram for osgEarth::Symbology::ResourceLibrary:

List of all members.

Public Member Functions

 ResourceLibrary (const Config &conf=Config())
void addResource (Resource *resource)
void removeResource (Resource *resource)
SkinResourcegetSkin (const std::string &name) const
void getSkins (SkinResourceVector &output) const
void getSkins (const SkinSymbol *symbol, SkinResourceVector &output) const
SkinResourcegetSkin (const SkinSymbol *symbol, Random &prng) const
void mergeConfig (const Config &conf)

Static Public Member Functions

static ResourceLibrarycreate (const URI &uri)

Protected Types

typedef std::map< const Symbol
*, Random
RandomMap

Protected Member Functions

bool matches (const SkinSymbol *symbol, SkinResource *skin) const

Protected Attributes

Threading::ReadWriteMutex _mutex
SkinResourceMap _skins

Detailed Description

ResourceLibrary manages a collection of external resources that a build system can use the construct geometries.

TODO: This class PROBABLY NEEDS the ability to share a mutex with whatever session is using it... like in osgGIS...

Definition at line 38 of file ResourceLibrary.


Member Typedef Documentation

typedef std::map< const Symbol*, Random > osgEarth::Symbology::ResourceLibrary::RandomMap [protected]

Definition at line 100 of file ResourceLibrary.


Constructor & Destructor Documentation

ResourceLibrary::ResourceLibrary ( const Config conf = Config())

Creates a new resource library

Definition at line 66 of file ResourceLibrary.cpp.

{
    mergeConfig( conf );
}

Member Function Documentation

void ResourceLibrary::addResource ( Resource resource)

Adds a resoure to the library.

Definition at line 85 of file ResourceLibrary.cpp.

{
    if ( dynamic_cast<SkinResource*>( resource ) )
    {
        Threading::ScopedWriteLock exclusive(_mutex);
        _skins[resource->name()] = static_cast<SkinResource*>(resource);
    }
    else
    {
        OE_WARN << LC << "Added a resource type that is not supported; ignoring." << std::endl;
    }
}

Here is the call graph for this function:

ResourceLibrary * ResourceLibrary::create ( const URI uri) [static]

Attempts to create and load a resource library from an XML resource catalog residing at the specified URL.

Definition at line 37 of file ResourceLibrary.cpp.

{
    osg::ref_ptr<XmlDocument> xml = XmlDocument::load( uri ); // buf, uri.full() );
    if ( !xml.valid() )
    {
        OE_WARN << LC << "Failed to parse XML for resource library \"" << uri.full() << "\"" << std::endl;
        return 0L;
    }

    Config conf = xml->getConfig();

    if ( conf.key() == "resources" )
    {
        return new ResourceLibrary( conf );
    }
    else
    {
        const Config& child = conf.child("resources");
        if ( !child.empty() )
            return new ResourceLibrary( child );
    }

    OE_WARN << LC << "Could not find top level 'resources' entry in resource library \""
        << uri.full() << "\"; load failed." << std::endl;
    return 0L;
}

Here is the call graph for this function:

SkinResource * ResourceLibrary::getSkin ( const std::string &  name) const

Finds and returns a Skin resource by name.

Definition at line 109 of file ResourceLibrary.cpp.

{
    Threading::ScopedReadLock shared( const_cast<ResourceLibrary*>(this)->_mutex );
    SkinResourceMap::const_iterator i = _skins.find( name );
    return i != _skins.end() ? i->second.get() : 0L;
}
SkinResource * ResourceLibrary::getSkin ( const SkinSymbol symbol,
Random prng 
) const

Returns a skin that matches the criteria specified in the symbol. The method will randomly select a suitable skin if there are more than one match. If the symbol contains a random seed, it will use that to seed the selection in order to provide consistency.

Definition at line 141 of file ResourceLibrary.cpp.

{
    SkinResourceVector candidates;
    getSkins( symbol, candidates );
    unsigned size = candidates.size();
    if ( size == 0 )
    {
        return 0L;
    }
    else if ( size == 1 )
    {
        return candidates[0].get();
    }
    else
    {
        return candidates[ prng.next(size) ].get();
    }
}

Here is the call graph for this function:

void ResourceLibrary::getSkins ( SkinResourceVector output) const

Returns a list of all Skin resources.

Definition at line 117 of file ResourceLibrary.cpp.

{
    Threading::ScopedReadLock shared( const_cast<ResourceLibrary*>(this)->_mutex );
    output.reserve( _skins.size() );
    for( SkinResourceMap::const_iterator i = _skins.begin(); i != _skins.end(); ++i )
        output.push_back( i->second.get() );
}
void ResourceLibrary::getSkins ( const SkinSymbol symbol,
SkinResourceVector output 
) const

Returns a list of all Skin resources that match the criteria specified in the symbol.

Definition at line 126 of file ResourceLibrary.cpp.

{
    Threading::ScopedReadLock shared( const_cast<ResourceLibrary*>(this)->_mutex );

    for( SkinResourceMap::const_iterator i = _skins.begin(); i != _skins.end(); ++i )
    {
        SkinResource* skin = i->second.get();
        if ( matches(symbol, skin) )
        {
            output.push_back( skin );
        }
    }
}
bool ResourceLibrary::matches ( const SkinSymbol symbol,
SkinResource skin 
) const [protected]

Definition at line 161 of file ResourceLibrary.cpp.

{
    if (q->objectHeight().isSet())
    {
        if (s->minObjectHeight().isSet() && 
            q->objectHeight().value() < s->minObjectHeight().value() )
        {
            return false;
        }
        if (s->maxObjectHeight().isSet() && 
            q->objectHeight().value() > s->maxObjectHeight().value() )
        {
            return false;
        }
    }

    if (q->minObjectHeight().isSet() && 
        s->maxObjectHeight().isSet() && 
        q->minObjectHeight().value() > s->maxObjectHeight().value() )
    {
        return false;
    }

    if (q->maxObjectHeight().isSet() && 
        s->minObjectHeight().isSet() &&
        q->maxObjectHeight().value() < s->minObjectHeight().value() )
    {
        return false;
    }

    if (q->isTiled().isSet() && 
        q->isTiled().value() != s->isTiled().value() )
    {
        return false;
    }

    if (q->tags().size() > 0 && !s->containsTags(q->tags()) )
    {
        return false;
    }

    return true;
}

Here is the call graph for this function:

void ResourceLibrary::mergeConfig ( const Config conf)

Definition at line 72 of file ResourceLibrary.cpp.

{
    // read skins
    const ConfigSet skins = conf.children( "skin" );
    for( ConfigSet::const_iterator i = skins.begin(); i != skins.end(); ++i )
    {
        addResource( new SkinResource(*i) );
    }

    //todo: other types later..
}

Here is the call graph for this function:

void ResourceLibrary::removeResource ( Resource resource)

Removes a resource from the library.

Definition at line 99 of file ResourceLibrary.cpp.

{
    if ( dynamic_cast<SkinResource*>( resource ) )
    {
        Threading::ScopedWriteLock exclusive(_mutex);
        _skins.erase( resource->name() );
    }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 102 of file ResourceLibrary.

Definition at line 103 of file ResourceLibrary.


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