osgEarth 2.1.1
|
Public Member Functions | |
CompositeTileSource (const TileSourceOptions &options=TileSourceOptions()) | |
virtual osg::Image * | createImage (const TileKey &key, ProgressCallback *progress=0) |
virtual bool | isDynamic () const |
virtual void | initialize (const std::string &referenceURI, const Profile *overrideProfile=0L) |
Protected Attributes | |
CompositeTileSourceOptions | _options |
bool | _initialized |
bool | _dynamic |
CompositeTileSourceOptions::ComponentVector | _components |
A "virtual" TileSource that contains one or more other TileSources and composites them into a single TileSource for a layer to use.
Definition at line 75 of file CompositeTileSource.
CompositeTileSource::CompositeTileSource | ( | const TileSourceOptions & | options = TileSourceOptions() | ) |
Constructs a new composite tile source
Definition at line 130 of file CompositeTileSource.cpp.
: _options( options ), _initialized( false ), _dynamic( false ) { for(CompositeTileSourceOptions::ComponentVector::iterator i = _options._components.begin(); i != _options._components.end(); ) { if ( i->_imageLayerOptions.isSet() ) { if ( i->_imageLayerOptions->driver().isSet() ) i->_tileSourceOptions = i->_imageLayerOptions->driver().value(); } if ( i->_tileSourceOptions.isSet() ) { if ( !i->_tileSourceInstance->valid() ) i->_tileSourceInstance = TileSourceFactory::create( i->_tileSourceOptions.value() ); if ( !i->_tileSourceInstance->valid() ) OE_WARN << LC << "Could not find a TileSource for driver [" << i->_tileSourceOptions->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 { ++i; } } }
osg::Image * CompositeTileSource::createImage | ( | const TileKey & | key, |
ProgressCallback * | progress = 0 |
||
) | [virtual] |
Creates a new image for the given key
Implements osgEarth::TileSource.
Definition at line 167 of file CompositeTileSource.cpp.
{ ImageMixVector images; images.reserve( _options._components.size() ); for(CompositeTileSourceOptions::ComponentVector::const_iterator i = _options._components.begin(); i != _options._components.end(); ++i ) { if ( progress && progress->isCanceled() ) return 0L; TileSource* source = i->_tileSourceInstance->get(); if ( source ) { //TODO: This duplicates code in ImageLayer::isKeyValid. Maybe should move that to TileSource::isKeyValid instead int minLevel = 0; int maxLevel = INT_MAX; if (i->_imageLayerOptions->minLevel().isSet()) { minLevel = i->_imageLayerOptions->minLevel().value(); } else if (i->_imageLayerOptions->minLevelResolution().isSet()) { minLevel = source->getProfile()->getLevelOfDetailForHorizResolution( i->_imageLayerOptions->minLevelResolution().value(), source->getPixelsPerTile()); } if (i->_imageLayerOptions->maxLevel().isSet()) { maxLevel = i->_imageLayerOptions->maxLevel().value(); } else if (i->_imageLayerOptions->maxLevelResolution().isSet()) { maxLevel = source->getProfile()->getLevelOfDetailForHorizResolution( i->_imageLayerOptions->maxLevelResolution().value(), source->getPixelsPerTile()); } // check that this source is within the level bounds: if (minLevel > key.getLevelOfDetail() || maxLevel < key.getLevelOfDetail() ) { continue; } if ( !source->getBlacklist()->contains( key.getTileId() ) ) { //Only try to get data if the source actually has data if ( source->hasData( key ) ) { osg::ref_ptr< ImageLayerPreCacheOperation > preCacheOp; if ( i->_imageLayerOptions.isSet() ) { preCacheOp = new ImageLayerPreCacheOperation(); preCacheOp->_processor.init( i->_imageLayerOptions.value(), true ); } ImageOpacityPair imagePair( source->createImage( key, preCacheOp.get(), progress ), 1.0f ); //If the image is not valid and the progress was not cancelled, blacklist if (!imagePair.first.valid() && (!progress || !progress->isCanceled())) { //Add the tile to the blacklist OE_DEBUG << LC << "Adding tile " << key.str() << " to the blacklist" << std::endl; source->getBlacklist()->add( key.getTileId() ); } if ( imagePair.first.valid() ) { // check for opacity: imagePair.second = i->_imageLayerOptions.isSet() ? i->_imageLayerOptions->opacity().value() : 1.0f; images.push_back( imagePair ); } } else { OE_DEBUG << LC << "Source has no data at " << key.str() << std::endl; } } else { OE_DEBUG << LC << "Tile " << key.str() << " is blacklisted, not checking" << std::endl; } } } if ( progress && progress->isCanceled() ) { return 0L; } else if ( images.size() == 0 ) { return 0L; } else if ( images.size() == 1 ) { return images[0].first.release(); } else { osg::Image* result = new osg::Image( *images[0].first.get() ); for( unsigned int i=1; i<images.size(); ++i ) { ImageOpacityPair& pair = images[i]; if ( pair.first.valid() ) { ImageUtils::mix( result, pair.first.get(), pair.second ); } } return result; } }
void CompositeTileSource::initialize | ( | const std::string & | referenceURI, |
const Profile * | overrideProfile = 0L |
||
) | [virtual] |
Initializes the tile source
Implements osgEarth::TileSource.
Definition at line 292 of file CompositeTileSource.cpp.
{ osg::ref_ptr<const Profile> profile = overrideProfile; for(CompositeTileSourceOptions::ComponentVector::iterator i = _options._components.begin(); i != _options._components.end(); ++i) { TileSource* source = i->_tileSourceInstance->get(); //.get(); if ( source ) { osg::ref_ptr<const Profile> localOverrideProfile = overrideProfile; const TileSourceOptions& opt = source->getOptions(); if ( opt.profile().isSet() ) localOverrideProfile = Profile::create( opt.profile().value() ); source->initialize( referenceURI, localOverrideProfile.get() ); 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 ); } } } setProfile( profile.get() ); _initialized = true; }
virtual bool osgEarth::CompositeTileSource::isDynamic | ( | ) | const [inline, virtual] |
Whether one of the underlying tile source's is dynamic
Reimplemented from osgEarth::TileSource.
Definition at line 87 of file CompositeTileSource.
{ return _dynamic; }
Definition at line 98 of file CompositeTileSource.
bool osgEarth::CompositeTileSource::_dynamic [protected] |
Definition at line 95 of file CompositeTileSource.
bool osgEarth::CompositeTileSource::_initialized [protected] |
Definition at line 94 of file CompositeTileSource.
Reimplemented from osgEarth::TileSource.
Definition at line 93 of file CompositeTileSource.