예제 #1
0
TileSource*
TileSourceFactory::create( const TileSourceOptions& options )
{
    TileSource* result = 0L;

    std::string driver = options.getDriver();
    if ( driver.empty() )
    {
        OE_WARN << "ILLEGAL- no driver set for tile source" << std::endl;
        return 0L;
    }

    osg::ref_ptr<osgDB::Options> rwopt = Registry::instance()->cloneOrCreateOptions();
    rwopt->setPluginData( TILESOURCEOPTIONS_TAG, (void*)&options );

    std::string driverExt = std::string( ".osgearth_" ) + driver;
    result = dynamic_cast<TileSource*>( osgDB::readObjectFile( driverExt, rwopt.get() ) );
    if ( !result )
    {
        OE_WARN << "WARNING: Failed to load TileSource driver for \"" << driver << "\"" << std::endl;
    }

    // apply an Override Profile if provided.
    if ( result && options.profile().isSet() )
    {
        const Profile* profile = Profile::create(*options.profile());
        if ( profile )
        {
            result->setProfile( profile );
        }
    }

    return result;
}
TileSource::Status
CompositeTileSource::initialize(const osgDB::Options* dbOptions)
{
    _dbOptions = Registry::instance()->cloneOrCreateOptions(dbOptions);

    osg::ref_ptr<const Profile> profile = getProfile();

    for(CompositeTileSourceOptions::ComponentVector::iterator i = _options._components.begin();
        i != _options._components.end(); )
    {
        if ( i->_imageLayerOptions.isSet() )
        {
            if ( !i->_tileSourceInstance.valid() )
            {
                i->_tileSourceInstance = TileSourceFactory::create( i->_imageLayerOptions->driver().value() );
            
                if ( !i->_tileSourceInstance.valid() )
                {
                    OE_WARN << LC << "Could not find a TileSource for driver [" << i->_imageLayerOptions->driver()->getDriver() << "]" << std::endl;
                }
            }
        }

        if ( !i->_tileSourceInstance.valid() )
        {
            OE_WARN << LC << "A component has no valid TileSource ... removing." << std::endl;
            i = _options._components.erase( i );
        }
        else
        {
            TileSource* source = i->_tileSourceInstance.get();
            if ( source )
            {
                osg::ref_ptr<const Profile> localOverrideProfile = profile.get();

                const TileSourceOptions& opt = source->getOptions();
                if ( opt.profile().isSet() )
                {
                    localOverrideProfile = Profile::create( opt.profile().value() );
                    source->setProfile( localOverrideProfile.get() );
                }

                // initialize the component tile source:
                TileSource::Status compStatus = source->startup( _dbOptions.get() );

                if ( compStatus == TileSource::STATUS_OK )
                {
                    if ( !profile.valid() )
                    {
                        // assume the profile of the first source to be the overall profile.
                        profile = source->getProfile();
                    }
                    else if ( !profile->isEquivalentTo( source->getProfile() ) )
                    {
                        // if sub-sources have different profiles, print a warning because this is
                        // not supported!
                        OE_WARN << LC << "Components with differing profiles are not supported. " 
                            << "Visual anomalies may result." << std::endl;
                    }
                
                    _dynamic = _dynamic || source->isDynamic();

                    // gather extents
                    const DataExtentList& extents = source->getDataExtents();
                    for( DataExtentList::const_iterator j = extents.begin(); j != extents.end(); ++j )
                    {
                        getDataExtents().push_back( *j );
                    }
                }

                else
                {
                    // if even one of the components fails to initialize, the entire
                    // composite tile source is invalid.
                    return Status::Error("At least one component is invalid");
                }
            }
        }

        ++i;
    }

    // set the new profile that was derived from the components
    setProfile( profile.get() );

    _initialized = true;
    return STATUS_OK;
}