本文整理汇总了C++中imagelayervector::const_iterator类的典型用法代码示例。如果您正苦于以下问题:C++ const_iterator类的具体用法?C++ const_iterator怎么用?C++ const_iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了const_iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mapf
void
TerrainEngineNode::postInitialize( const Map* map, const TerrainOptions& options )
{
if ( _map.valid() ) // i think this is always true [gw]
{
// manually trigger the map callbacks the first time:
if ( _map->getProfile() )
onMapInfoEstablished( MapInfo(_map.get()) );
// create a layer controller. This object affects the uniforms that control layer appearance properties
_imageLayerController = new ImageLayerController( _map.get(), this );
// register the layer Controller it with all pre-existing image layers:
MapFrame mapf( _map.get(), Map::IMAGE_LAYERS );
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
i->get()->addCallback( _imageLayerController.get() );
}
}
_initStage = INIT_POSTINIT_COMPLETE;
}
示例2: getElevationTaskService
void
StreamingTerrainNode::updateTaskServiceThreads( const MapFrame& mapf )
{
//Get the maximum elevation weight
float elevationWeight = 0.0f;
for (ElevationLayerVector::const_iterator itr = mapf.elevationLayers().begin(); itr != mapf.elevationLayers().end(); ++itr)
{
ElevationLayer* layer = itr->get();
float w = layer->getElevationLayerOptions().loadingWeight().value();
if (w > elevationWeight) elevationWeight = w;
}
float totalImageWeight = 0.0f;
for (ImageLayerVector::const_iterator itr = mapf.imageLayers().begin(); itr != mapf.imageLayers().end(); ++itr)
{
totalImageWeight += itr->get()->getImageLayerOptions().loadingWeight().value();
}
float totalWeight = elevationWeight + totalImageWeight;
if (elevationWeight > 0.0f)
{
//Determine how many threads each layer gets
int numElevationThreads = (int)osg::round((float)_numLoadingThreads * (elevationWeight / totalWeight ));
OE_INFO << LC << "Elevation Threads = " << numElevationThreads << std::endl;
getElevationTaskService()->setNumThreads( numElevationThreads );
}
for (ImageLayerVector::const_iterator itr = mapf.imageLayers().begin(); itr != mapf.imageLayers().end(); ++itr)
{
const TerrainLayerOptions& opt = itr->get()->getImageLayerOptions();
int imageThreads = (int)osg::round((float)_numLoadingThreads * (opt.loadingWeight().value() / totalWeight ));
OE_INFO << LC << "Image Threads for " << itr->get()->getName() << " = " << imageThreads << std::endl;
getImageryTaskService( itr->get()->getUID() )->setNumThreads( imageThreads );
}
}
示例3: mapf
void
TileBuilder::createTile(const TileKey& key,
bool parallelize,
osg::ref_ptr<Tile>& out_tile,
bool& out_hasRealData,
bool& out_hasLodBlendedLayers )
{
MapFrame mapf( _map, Map::MASKED_TERRAIN_LAYERS );
SourceRepo repo;
// init this to false, then search for real data. "Real data" is data corresponding
// directly to the key, as opposed to fallback data, which is derived from a lower
// LOD key.
out_hasRealData = false;
out_hasLodBlendedLayers = false;
const MapInfo& mapInfo = mapf.getMapInfo();
// If we need more than one layer, fetch them in parallel.
// TODO: change the test based on isKeyValid total.
if ( parallelize && (mapf.imageLayers().size() + mapf.elevationLayers().size() > 1) )
{
// count the valid layers.
int jobCount = 0;
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
if ( i->get()->isKeyValid( key ) )
++jobCount;
if ( i->get()->getImageLayerOptions().lodBlending() == true )
out_hasLodBlendedLayers = true;
}
if ( mapf.elevationLayers().size() > 0 )
++jobCount;
// A thread job monitoring event:
Threading::MultiEvent semaphore( jobCount );
// Start the image layer jobs:
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
if ( layer->isKeyValid(key) )
{
ParallelTask<BuildColorLayer>* j = new ParallelTask<BuildColorLayer>( &semaphore );
j->init( key, layer, mapInfo, _terrainOptions, repo );
j->setPriority( -(float)key.getLevelOfDetail() );
_service->add( j );
}
}
// If we have elevation layers, start an elevation job as well. Otherwise just create an
// empty one while we're waiting for the images to load.
if ( mapf.elevationLayers().size() > 0 )
{
ParallelTask<BuildElevLayer>* ej = new ParallelTask<BuildElevLayer>( &semaphore );
ej->init( key, mapf, _terrainOptions, repo );
ej->setPriority( -(float)key.getLevelOfDetail() );
_service->add( ej );
}
else
{
BuildElevLayer build;
build.init( key, mapf, _terrainOptions, repo );
build.execute();
}
// Wait for all the jobs to finish.
semaphore.wait();
}
// Fetch the image data serially:
else
{
// gather all the image layers serially.
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
//if ( layer->isKeyValid(key) ) // Wrong. no guarantee key is in the same profile.
if ( layer->getEnabled() )
{
BuildColorLayer build;
build.init( key, layer, mapInfo, _terrainOptions, repo );
build.execute();
if ( layer->getImageLayerOptions().lodBlending() == true )
out_hasLodBlendedLayers = true;
}
}
// make an elevation layer.
BuildElevLayer build;
build.init( key, mapf, _terrainOptions, repo );
build.execute();
}
//.........这里部分代码省略.........
示例4: CustomElevLayer
void
TileBuilder::finalizeJob(TileBuilder::Job* job,
osg::ref_ptr<Tile>& out_tile,
bool& out_hasRealData,
bool& out_hasLodBlending)
{
SourceRepo& repo = job->_repo;
out_hasRealData = false;
out_hasLodBlending = false;
// Bail out now if there's no data to be had.
if ( repo._colorLayers.size() == 0 && !repo._elevLayer.getHFLayer() )
{
return;
}
const TileKey& key = job->_key;
const MapInfo& mapInfo = job->_mapf.getMapInfo();
// OK we are making a tile, so if there's no heightfield yet, make an empty one.
if ( !repo._elevLayer.getHFLayer() )
{
osg::HeightField* hf = HeightFieldUtils::createReferenceHeightField( key.getExtent(), 8, 8 );
osgTerrain::HeightFieldLayer* hfLayer = new osgTerrain::HeightFieldLayer( hf );
hfLayer->setLocator( GeoLocator::createForKey(key, mapInfo) );
repo._elevLayer = CustomElevLayer( hfLayer, true );
}
// Now, if there are any color layers that did not get built, create them with an empty
// image so the shaders have something to draw.
osg::ref_ptr<osg::Image> emptyImage;
osgTerrain::Locator* locator = repo._elevLayer.getHFLayer()->getLocator();
for( ImageLayerVector::const_iterator i = job->_mapf.imageLayers().begin(); i != job->_mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
if ( layer->getEnabled() )
{
if ( !layer->isKeyValid(key) )
{
if ( !emptyImage.valid() )
emptyImage = ImageUtils::createEmptyImage();
repo.add( CustomColorLayer(
i->get(), emptyImage.get(),
locator,
key.getLevelOfDetail(),
key,
true ) );
}
if ( i->get()->getImageLayerOptions().lodBlending() == true )
out_hasLodBlending = true;
}
}
// Ready to create the actual tile.
AssembleTile assemble;
assemble.init( key, mapInfo, _terrainOptions, repo );
assemble.execute();
// Check the results and see if we have any real data.
for( ColorLayersByUID::const_iterator i = repo._colorLayers.begin(); i != repo._colorLayers.end(); ++i )
{
if ( !i->second.isFallbackData() )
{
out_hasRealData = true;
break;
}
}
if ( !out_hasRealData && !repo._elevLayer.isFallbackData() )
{
out_hasRealData = true;
}
out_tile = assemble._tile;
}
示例5: seed
void CacheSeed::seed( Map* map )
{
if ( !map->getCache() )
{
OE_WARN << LC << "Warning: No cache defined; aborting." << std::endl;
return;
}
std::vector<TileKey> keys;
map->getProfile()->getRootKeys(keys);
//Add the map's entire extent if we don't have one specified.
if (_extents.empty())
{
addExtent( map->getProfile()->getExtent() );
}
bool hasCaches = false;
int src_min_level = INT_MAX;
unsigned int src_max_level = 0;
MapFrame mapf( map, Map::TERRAIN_LAYERS, "CacheSeed::seed" );
//Assumes the the TileSource will perform the caching for us when we call createImage
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); i++ )
{
ImageLayer* layer = i->get();
TileSource* src = layer->getTileSource();
const ImageLayerOptions& opt = layer->getImageLayerOptions();
if ( layer->isCacheOnly() )
{
OE_WARN << LC << "Warning: Layer \"" << layer->getName() << "\" is set to cache-only; skipping." << std::endl;
}
else if ( !src )
{
OE_WARN << "Warning: Layer \"" << layer->getName() << "\" could not create TileSource; skipping." << std::endl;
}
//else if ( src->getCachePolicyHint(0L) == CachePolicy::NO_CACHE )
//{
// OE_WARN << LC << "Warning: Layer \"" << layer->getName() << "\" does not support seeding; skipping." << std::endl;
//}
else if ( !layer->getCache() )
{
OE_WARN << LC << "Notice: Layer \"" << layer->getName() << "\" has no cache defined; skipping." << std::endl;
}
else
{
hasCaches = true;
if (opt.minLevel().isSet() && (int)opt.minLevel().get() < src_min_level)
src_min_level = opt.minLevel().get();
if (opt.maxLevel().isSet() && opt.maxLevel().get() > src_max_level)
src_max_level = opt.maxLevel().get();
}
}
for( ElevationLayerVector::const_iterator i = mapf.elevationLayers().begin(); i != mapf.elevationLayers().end(); i++ )
{
ElevationLayer* layer = i->get();
TileSource* src = layer->getTileSource();
const ElevationLayerOptions& opt = layer->getElevationLayerOptions();
if ( layer->isCacheOnly() )
{
OE_WARN << LC << "Warning: Layer \"" << layer->getName() << "\" is set to cache-only; skipping." << std::endl;
}
else if (!src)
{
OE_WARN << "Warning: Layer \"" << layer->getName() << "\" could not create TileSource; skipping." << std::endl;
}
//else if ( src->getCachePolicyHint(0L) == CachePolicy::NO_CACHE )
//{
// OE_WARN << LC << "Warning: Layer \"" << layer->getName() << "\" does not support seeding; skipping." << std::endl;
//}
else if ( !layer->getCache() )
{
OE_WARN << LC << "Notice: Layer \"" << layer->getName() << "\" has no cache defined; skipping." << std::endl;
}
else
{
hasCaches = true;
if (opt.minLevel().isSet() && (int)opt.minLevel().get() < src_min_level)
src_min_level = opt.minLevel().get();
if (opt.maxLevel().isSet() && opt.maxLevel().get() > src_max_level)
src_max_level = opt.maxLevel().get();
}
}
if ( !hasCaches )
{
OE_WARN << LC << "There are either no caches defined in the map, or no sources to cache; aborting." << std::endl;
return;
}
if ( src_max_level > 0 && src_max_level < _maxLevel )
{
_maxLevel = src_max_level;
//.........这里部分代码省略.........
示例6: lock
bool
Map::sync( MapFrame& frame ) const
{
bool result = false;
if ( frame._mapDataModelRevision != _dataModelRevision || !frame._initialized )
{
// hold the read lock while copying the layer lists.
Threading::ScopedReadLock lock( const_cast<Map*>(this)->_mapDataMutex );
if ( frame._parts & IMAGE_LAYERS )
{
if ( !frame._initialized )
frame._imageLayers.reserve( _imageLayers.size() );
frame._imageLayers.clear();
if ( frame._copyValidDataOnly )
{
for( ImageLayerVector::const_iterator i = _imageLayers.begin(); i != _imageLayers.end(); ++i )
if ( i->get()->getProfile() )
frame._imageLayers.push_back( i->get() );
}
else
std::copy( _imageLayers.begin(), _imageLayers.end(), std::back_inserter(frame._imageLayers) );
}
if ( frame._parts & ELEVATION_LAYERS )
{
if ( !frame._initialized )
frame._elevationLayers.reserve( _elevationLayers.size() );
frame._elevationLayers.clear();
if ( frame._copyValidDataOnly )
{
for( ElevationLayerVector::const_iterator i = _elevationLayers.begin(); i != _elevationLayers.end(); ++i )
if ( i->get()->getProfile() )
frame._elevationLayers.push_back( i->get() );
}
else
std::copy( _elevationLayers.begin(), _elevationLayers.end(), std::back_inserter(frame._elevationLayers) );
}
if ( frame._parts & MODEL_LAYERS )
{
if ( !frame._initialized )
frame._modelLayers.reserve( _modelLayers.size() );
frame._modelLayers.clear();
std::copy( _modelLayers.begin(), _modelLayers.end(), std::back_inserter(frame._modelLayers) );
}
if ( frame._parts & MASK_LAYERS )
{
if ( !frame._initialized )
frame._maskLayers.reserve( _terrainMaskLayers.size() );
frame._maskLayers.clear();
std::copy( _terrainMaskLayers.begin(), _terrainMaskLayers.end(), std::back_inserter(frame._maskLayers) );
}
// sync the revision numbers.
frame._initialized = true;
frame._mapDataModelRevision = _dataModelRevision;
result = true;
}
return result;
}
示例7: exclusive
void
MPGeometry::renderPrimitiveSets(osg::State& state,
bool usingVBOs) const
{
// check the map frame to see if it's up to date
if ( _frame.needsSync() )
{
// this lock protects a MapFrame sync when we have multiple DRAW threads.
Threading::ScopedMutexLock exclusive( _frameSyncMutex );
if ( _frame.needsSync() && _frame.sync() ) // always double check
{
// This should only happen is the layer ordering changes;
// If layers are added or removed, the Tile gets rebuilt and
// the point is moot.
std::vector<Layer> reordered;
const ImageLayerVector& layers = _frame.imageLayers();
reordered.reserve( layers.size() );
for( ImageLayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i )
{
std::vector<Layer>::iterator j = std::find( _layers.begin(), _layers.end(), i->get()->getUID() );
if ( j != _layers.end() )
reordered.push_back( *j );
}
_layers.swap( reordered );
}
}
unsigned layersDrawn = 0;
osg::ref_ptr<osg::GL2Extensions> ext = osg::GL2Extensions::Get( state.getContextID(), true );
const osg::Program::PerContextProgram* pcp = state.getLastAppliedProgramObject();
GLint opacityLocation;
GLint uidLocation;
GLint orderLocation;
GLint texMatParentLocation;
// yes, it's possible that the PCP is not set up yet.
// TODO: can we optimize this so we don't need to get uni locations every time?
if ( pcp )
{
opacityLocation = pcp->getUniformLocation( _opacityUniform->getNameID() );
uidLocation = pcp->getUniformLocation( _layerUIDUniform->getNameID() );
orderLocation = pcp->getUniformLocation( _layerOrderUniform->getNameID() );
texMatParentLocation = pcp->getUniformLocation( _texMatParentUniform->getNameID() );
}
// activate the tile coordinate set - same for all layers
state.setTexCoordPointer( _imageUnit+1, _tileCoords.get() );
if ( _layers.size() > 0 )
{
float prev_opacity = -1.0f;
float prev_alphaThreshold = -1.0f;
// first bind any shared layers
// TODO: optimize by pre-storing shared indexes
for(unsigned i=0; i<_layers.size(); ++i)
{
const Layer& layer = _layers[i];
// a "shared" layer binds to a secondary texture unit so that other layers
// can see it and use it.
if ( layer._imageLayer->isShared() )
{
int sharedUnit = layer._imageLayer->shareImageUnit().get();
{
state.setActiveTextureUnit( sharedUnit );
state.setTexCoordPointer( sharedUnit, layer._texCoords.get() );
// bind the texture for this layer to the active share unit.
layer._tex->apply( state );
// no texture LOD blending for shared layers for now. maybe later.
}
}
}
// track the active image unit.
int activeImageUnit = -1;
// interate over all the image layers
for(unsigned i=0; i<_layers.size(); ++i)
{
const Layer& layer = _layers[i];
if ( layer._imageLayer->getVisible() )
{
// activate the visible unit if necessary:
if ( activeImageUnit != _imageUnit )
{
state.setActiveTextureUnit( _imageUnit );
activeImageUnit = _imageUnit;
}
// bind the texture for this layer:
layer._tex->apply( state );
// if we're using a parent texture for blending, activate that now
//.........这里部分代码省略.........
示例8: if
osg::Image*
CompositeTileSource::createImage(const TileKey& key,
ProgressCallback* progress )
{
ImageMixVector images;
images.reserve(_imageLayers.size());
// Try to get an image from each of the layers for the given key.
for (ImageLayerVector::const_iterator itr = _imageLayers.begin(); itr != _imageLayers.end(); ++itr)
{
ImageLayer* layer = itr->get();
ImageInfo imageInfo;
imageInfo.dataInExtents = layer->getTileSource()->hasDataInExtent( key.getExtent() );
imageInfo.opacity = layer->getOpacity();
if (imageInfo.dataInExtents)
{
GeoImage image = layer->createImage(key, progress);
if (image.valid())
{
imageInfo.image = image.getImage();
}
// If the progress got cancelled or it needs a retry then return NULL to prevent this tile from being built and cached with incomplete or partial data.
if (progress && (progress->isCanceled() || progress->needsRetry()))
{
OE_DEBUG << LC << " createImage was cancelled or needs retry for " << key.str() << std::endl;
return 0L;
}
}
images.push_back(imageInfo);
}
// Determine the output texture size to use based on the image that were creatd.
unsigned numValidImages = 0;
osg::Vec2s textureSize;
for (unsigned int i = 0; i < images.size(); i++)
{
ImageInfo& info = images[i];
if (info.image.valid())
{
if (numValidImages == 0)
{
textureSize.set( info.image->s(), info.image->t());
}
numValidImages++;
}
}
// Create fallback images if we have some valid data but not for all the layers
if (numValidImages > 0 && numValidImages < images.size())
{
for (unsigned int i = 0; i < images.size(); i++)
{
ImageInfo& info = images[i];
ImageLayer* layer = _imageLayers[i].get();
if (!info.image.valid() && info.dataInExtents)
{
TileKey parentKey = key.createParentKey();
GeoImage image;
while (!image.valid() && parentKey.valid())
{
image = layer->createImage(parentKey, progress);
if (image.valid())
{
break;
}
// If the progress got cancelled or it needs a retry then return NULL to prevent this tile from being built and cached with incomplete or partial data.
if (progress && (progress->isCanceled() || progress->needsRetry()))
{
OE_DEBUG << LC << " createImage was cancelled or needs retry for " << key.str() << std::endl;
return 0L;
}
parentKey = parentKey.createParentKey();
}
if (image.valid())
{
// TODO: Bilinear options?
bool bilinear = layer->isCoverage() ? false : true;
GeoImage cropped = image.crop( key.getExtent(), true, textureSize.x(), textureSize.y(), bilinear);
info.image = cropped.getImage();
}
}
}
}
// Now finally create the output image.
//Recompute the number of valid images
numValidImages = 0;
for (unsigned int i = 0; i < images.size(); i++)
{
ImageInfo& info = images[i];
if (info.image.valid()) numValidImages++;
}
//.........这里部分代码省略.........
示例9: TileModel
void
TileModelFactory::createTileModel(const TileKey& key,
const MapFrame& frame,
bool accumulate,
osg::ref_ptr<TileModel>& out_model,
ProgressCallback* progress)
{
osg::ref_ptr<TileModel> model = new TileModel( frame.getRevision(), frame.getMapInfo() );
model->_useParentData = _terrainReqs->parentTexturesRequired();
model->_tileKey = key;
model->_tileLocator = GeoLocator::createForKey(key, frame.getMapInfo());
OE_START_TIMER(fetch_imagery);
// Fetch the image data and make color layers.
unsigned index = 0;
unsigned order = 0;
for( ImageLayerVector::const_iterator i = frame.imageLayers().begin(); i != frame.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
if ( layer->getEnabled() && layer->isKeyInRange(key) )
{
BuildColorData build;
build.init( key, layer, order, frame.getMapInfo(), _terrainOptions, _liveTiles.get(), model.get() );
bool addedToModel = build.execute(progress);
if ( addedToModel )
{
// only bump the order if we added something to the data model.
order++;
}
}
}
if (progress)
progress->stats()["fetch_imagery_time"] += OE_STOP_TIMER(fetch_imagery);
// make an elevation layer.
OE_START_TIMER(fetch_elevation);
buildElevation(key, frame, accumulate, _terrainReqs->elevationTexturesRequired(), model.get(), progress);
if (progress)
progress->stats()["fetch_elevation_time"] += OE_STOP_TIMER(fetch_elevation);
// make a normal map layer (if necessary)
if ( _terrainReqs->normalTexturesRequired() )
{
OE_START_TIMER(fetch_normalmap);
buildNormalMap(key, frame, accumulate, model.get(), progress);
if (progress)
progress->stats()["fetch_normalmap_time"] += OE_STOP_TIMER(fetch_normalmap);
}
// If nothing was added, not even a fallback heightfield, something went
// horribly wrong. Leave without a tile model. Chances are that a parent tile
// not not found in the live-tile registry.
if ( model->_colorData.size() == 0 && !model->_elevationData.getHeightField() )
{
return;
}
// OK we are making a tile, so if there's no heightfield yet, make an empty one (and mark it
// as fallback data of course)
if ( !model->_elevationData.getHeightField() )
{
osg::HeightField* hf = HeightFieldUtils::createReferenceHeightField( key.getExtent(), 15, 15 );
model->_elevationData = TileModel::ElevationData(
hf,
GeoLocator::createForKey(key, frame.getMapInfo()),
true );
}
// look up the parent model and cache it.
osg::ref_ptr<TileNode> parentTile;
if ( _liveTiles->get(key.createParentKey(), parentTile) )
{
model->_parentModel = parentTile->getTileModel();
}
out_model = model.release();
}
示例10: mapf
void
TileModelFactory::createTileModel(const TileKey& key,
osg::ref_ptr<TileModel>& out_model,
bool& out_hasRealData,
bool& out_hasLodBlendedLayers )
{
MapFrame mapf( _map, Map::MASKED_TERRAIN_LAYERS );
const MapInfo& mapInfo = mapf.getMapInfo();
osg::ref_ptr<TileModel> model = new TileModel();
model->_tileKey = key;
model->_tileLocator = GeoLocator::createForKey(key, mapInfo);
// init this to false, then search for real data. "Real data" is data corresponding
// directly to the key, as opposed to fallback data, which is derived from a lower
// LOD key.
out_hasRealData = false;
out_hasLodBlendedLayers = false;
// Fetch the image data and make color layers.
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
if ( layer->getEnabled() )
{
BuildColorData build;
build.init( key, layer, mapInfo, _terrainOptions, model.get() );
build.execute();
if ( layer->getImageLayerOptions().lodBlending() == true )
{
out_hasLodBlendedLayers = true;
}
}
}
// make an elevation layer.
BuildElevationData build;
build.init( key, mapf, _terrainOptions, model.get(), _hfCache );
build.execute();
// Bail out now if there's no data to be had.
if ( model->_colorData.size() == 0 && !model->_elevationData.getHFLayer() )
{
return;
}
// OK we are making a tile, so if there's no heightfield yet, make an empty one.
if ( !model->_elevationData.getHFLayer() )
{
osg::HeightField* hf = HeightFieldUtils::createReferenceHeightField( key.getExtent(), 8, 8 );
osgTerrain::HeightFieldLayer* hfLayer = new osgTerrain::HeightFieldLayer( hf );
hfLayer->setLocator( GeoLocator::createForKey(key, mapInfo) );
model->_elevationData = TileModel::ElevationData( hfLayer, true );
}
// Now, if there are any color layers that did not get built, create them with an empty
// image so the shaders have something to draw.
osg::ref_ptr<osg::Image> emptyImage;
osgTerrain::Locator* locator = model->_elevationData.getHFLayer()->getLocator();
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
if ( layer->getEnabled() && !layer->isKeyValid(key) )
{
if ( !emptyImage.valid() )
emptyImage = ImageUtils::createEmptyImage();
model->_colorData[i->get()->getUID()] = TileModel::ColorData(
layer,
emptyImage.get(),
locator,
key.getLevelOfDetail(),
key,
true );
}
}
// Ready to create the actual tile.
//AssembleTile assemble;
//assemble.init( key, mapInfo, _terrainOptions, model.get(), mapf.terrainMaskLayers() );
//assemble.execute();
// if we're using LOD blending, find and add the parent's state set.
if ( out_hasLodBlendedLayers && key.getLevelOfDetail() > 0 && _liveTiles.valid() )
{
osg::ref_ptr<TileNode> parent;
if ( _liveTiles->get( key.createParentKey(), parent ) )
{
model->_parentStateSet = parent->getPublicStateSet();
}
}
if (!out_hasRealData)
{
//.........这里部分代码省略.........
示例11: contourLayer
osg::Node*
OSGTileFactory::createPopulatedTile(const MapFrame& mapf,
Terrain* terrain,
const TileKey& key,
bool wrapInPagedLOD,
bool fallback,
bool& validData )
{
const MapInfo& mapInfo = mapf.getMapInfo();
bool isPlateCarre = !mapInfo.isGeocentric() && mapInfo.isGeographicSRS();
typedef std::vector<GeoImageData> GeoImageDataVector;
GeoImageDataVector image_tiles;
// Collect the image layers
bool empty_map = mapf.imageLayers().size() == 0 && mapf.elevationLayers().size() == 0;
// Create the images for the tile
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
GeoImageData imageData;
// Only try to create images if the key is valid
if ( layer->isKeyValid( key ) )
{
imageData._image = layer->createImage( key );
imageData._layerUID = layer->getUID();
imageData._imageTileKey = key;
}
// always push images, even it they are empty, so that the image_tiles vector is one-to-one
// with the imageLayers() vector.
image_tiles.push_back( imageData );
}
bool hasElevation = false;
//Create the heightfield for the tile
osg::ref_ptr<osg::HeightField> hf;
if ( mapf.elevationLayers().size() > 0 )
{
mapf.getHeightField( key, false, hf, 0L, _terrainOptions.elevationInterpolation().value());
}
//If we are on the first LOD and we couldn't get a heightfield tile, just create an empty one. Otherwise you can run into the situation
//where you could have an inset heightfield on one hemisphere and the whole other hemisphere won't show up.
if ( mapInfo.isGeocentric() && key.getLevelOfDetail() <= 1 && !hf.valid())
{
hf = createEmptyHeightField( key );
}
hasElevation = hf.valid();
//Determine if we've created any images
unsigned int numValidImages = 0;
for (unsigned int i = 0; i < image_tiles.size(); ++i)
{
if (image_tiles[i]._image.valid()) numValidImages++;
}
//If we couldn't create any imagery or heightfields, bail out
if (!hf.valid() && (numValidImages == 0) && !empty_map)
{
OE_DEBUG << LC << "Could not create any imagery or heightfields for " << key.str() <<". Not building tile" << std::endl;
validData = false;
//If we're not asked to fallback on previous LOD's and we have no data, return NULL
if (!fallback)
{
return NULL;
}
}
else
{
validData = true;
}
//Try to interpolate any missing image layers from parent tiles
for (unsigned int i = 0; i < mapf.imageLayers().size(); i++ )
{
if (!image_tiles[i]._image.valid())
{
if (mapf.getImageLayerAt(i)->isKeyValid(key))
{
//If the key was valid and we have no image, then something possibly went wrong with the image creation such as a server being busy.
createValidGeoImage(mapf.getImageLayerAt(i), key, image_tiles[i]._image, image_tiles[i]._imageTileKey);
}
//If we still couldn't create an image, either something is really wrong or the key wasn't valid, so just create a transparent placeholder image
if (!image_tiles[i]._image.valid())
{
//If the image is not valid, create an empty texture as a placeholder
image_tiles[i]._image = GeoImage(ImageUtils::createEmptyImage(), key.getExtent());
image_tiles[i]._imageTileKey = key;
}
}
}
//Fill in missing heightfield information from parent tiles
//.........这里部分代码省略.........
示例12: mapf
void
TerrainEngineNode::updateImageUniforms()
{
// don't bother if this is a hurting old card
if ( !Registry::instance()->getCapabilities().supportsGLSL() )
return;
// update the layer uniform arrays:
osg::StateSet* stateSet = this->getOrCreateStateSet();
// get a copy of the image layer stack:
MapFrame mapf( _map.get(), Map::IMAGE_LAYERS );
_imageLayerController->_layerEnabledUniform.detach();
_imageLayerController->_layerOpacityUniform.detach();
_imageLayerController->_layerRangeUniform.detach();
#if 0
if ( _imageLayerController->_layerEnabledUniform.valid() )
_imageLayerController->_layerEnabledUniform->removeFrom( stateSet );
if ( _imageLayerController->_layerOpacityUniform.valid() )
_imageLayerController->_layerOpacityUniform->removeFrom( stateSet );
if ( _imageLayerController->_layerRangeUniform.valid() )
_imageLayerController->_layerRangeUniform->removeFrom( stateSet );
#endif
//stateSet->removeUniform( "osgearth_ImageLayerAttenuation" );
if ( mapf.imageLayers().size() > 0 )
{
// the "enabled" uniform is fixed size. this is handy to account for layers that are in flux...i.e., their source
// layer count has changed, but the shader has not yet caught up. In the future we might use this to disable
// "ghost" layers that used to exist at a given index, but no longer do.
_imageLayerController->_layerEnabledUniform.attach( "osgearth_ImageLayerEnabled", osg::Uniform::BOOL, stateSet, 64 );
_imageLayerController->_layerOpacityUniform.attach( "osgearth_ImageLayerOpacity", osg::Uniform::FLOAT, stateSet, mapf.imageLayers().size() );
_imageLayerController->_layerRangeUniform.attach ( "osgearth_ImageLayerRange", osg::Uniform::FLOAT, stateSet, 2 * mapf.imageLayers().size() );
//_imageLayerController->_layerEnabledUniform = new ArrayUniform( osg::Uniform::BOOL, "osgearth_ImageLayerEnabled", 64 ); //mapf.imageLayers().size() );
//_imageLayerController->_layerOpacityUniform = new ArrayUniform( osg::Uniform::FLOAT, "osgearth_ImageLayerOpacity", mapf.imageLayers().size() );
//_imageLayerController->_layerRangeUniform = new ArrayUniform( osg::Uniform::FLOAT, "osgearth_ImageLayerRange", 2 * mapf.imageLayers().size() );
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
int index = (int)(i - mapf.imageLayers().begin());
_imageLayerController->_layerOpacityUniform.setElement( index, layer->getOpacity() );
_imageLayerController->_layerEnabledUniform.setElement( index, layer->getEnabled() );
_imageLayerController->_layerRangeUniform.setElement( (2*index), layer->getImageLayerOptions().minVisibleRange().value() );
_imageLayerController->_layerRangeUniform.setElement( (2*index)+1, layer->getImageLayerOptions().maxVisibleRange().value() );
}
// set the remainder of the layers to disabled
for( int j=mapf.imageLayers().size(); j<64; ++j )
_imageLayerController->_layerEnabledUniform.setElement( j, false );
//_imageLayerController->_layerOpacityUniform->addTo( stateSet );
//_imageLayerController->_layerEnabledUniform->addTo( stateSet );
//_imageLayerController->_layerRangeUniform->addTo( stateSet );
}
}
示例13: if
// called from the UPDATE TRAVERSAL, because this method can potentially alter
// the scene graph.
bool
StreamingTile::serviceCompletedRequests( const MapFrame& mapf, bool tileTableLocked )
{
//Don't do anything until we have been added to the scene graph
if (!_hasBeenTraversed) return false;
bool tileModified = false;
if ( !_requestsInstalled )
return false;
// First service the tile generator:
if ( _tileGenRequest.valid() && _tileGenRequest->isCompleted() )
{
CustomTerrainTechnique* tech = dynamic_cast<CustomTerrainTechnique*>( getTerrainTechnique() );
if ( tech )
{
//TODO: consider waiting to apply if there are still more tile updates in the queue.
if ( _tileUpdates.size() == 0 )
{
tileModified = tech->applyTileUpdates();
}
}
_tileGenRequest = 0L;
}
// now deal with imagery.
const LoadingPolicy& lp = getStreamingTerrain()->getLoadingPolicy();
StreamingTerrainNode* terrain = getStreamingTerrain();
//Check each layer independently.
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* imageLayer = i->get();
bool checkForFinalImagery = false;
CustomColorLayer colorLayer;
if ( getCustomColorLayer( imageLayer->getUID(), colorLayer ) )
{
if ( lp.mode() == LoadingPolicy::MODE_PREEMPTIVE )
{
// in preemptive mode, always check for the final imagery - there are no intermediate
// placeholders.
checkForFinalImagery = true;
}
else if (lp.mode() == LoadingPolicy::MODE_SEQUENTIAL &&
readyForNewImagery(imageLayer, colorLayer.getLevelOfDetail()) )
{
// in sequential mode, we have to incrementally increase imagery resolution by
// creating placeholders based of parent tiles, one LOD at a time.
if ( colorLayer.getLevelOfDetail() + 1 < (int)_key.getLevelOfDetail() )
{
// if the parent's image LOD is higher than ours, replace ours with the parent's
// since it is a higher-resolution placeholder:
if ( _family[Relative::PARENT].getImageLOD(colorLayer.getUID()) > colorLayer.getLevelOfDetail() )
{
osg::ref_ptr<Tile> parentTile;
getStreamingTerrain()->getTile( _family[Relative::PARENT].tileID, parentTile, !tileTableLocked );
// Set the color layer to the parent color layer as a placeholder.
CustomColorLayer parentColorLayer;
if ( parentTile->getCustomColorLayer( colorLayer.getUID(), parentColorLayer ) )
{
this->setCustomColorLayer( parentColorLayer );
}
// ... and queue up an update request.
queueTileUpdate( TileUpdate::UPDATE_IMAGE_LAYER, colorLayer.getUID() );
}
}
else
{
// we've gone as far as we can with placeholders; time to check for the
// final imagery tile.
checkForFinalImagery = true;
}
}
}
if ( checkForFinalImagery )
{
// Then the image requests:
for( TaskRequestList::iterator itr = _requests.begin(); itr != _requests.end(); )
{
bool increment = true;
TileColorLayerRequest* r = static_cast<TileColorLayerRequest*>( itr->get() );
//We only care about the current layer we are checking
if ( r->_layerUID == imageLayer->getUID() )
{
if ( itr->get()->isCompleted() )
{
if ( r->wasCanceled() )
{
//Reset the cancelled task to IDLE and give it a new progress callback.
r->setState( TaskRequest::STATE_IDLE );
//.........这里部分代码省略.........
示例14: mapf
void
TileModelFactory::createTileModel(const TileKey& key,
osg::ref_ptr<TileModel>& out_model,
bool& out_hasRealData)
{
MapFrame mapf( _map, Map::MASKED_TERRAIN_LAYERS );
const MapInfo& mapInfo = mapf.getMapInfo();
osg::ref_ptr<TileModel> model = new TileModel();
model->_map = _map;
model->_tileKey = key;
model->_tileLocator = GeoLocator::createForKey(key, mapInfo);
// init this to false, then search for real data. "Real data" is data corresponding
// directly to the key, as opposed to fallback data, which is derived from a lower
// LOD key.
out_hasRealData = false;
// Fetch the image data and make color layers.
unsigned order = 0;
for( ImageLayerVector::const_iterator i = mapf.imageLayers().begin(); i != mapf.imageLayers().end(); ++i )
{
ImageLayer* layer = i->get();
if ( layer->getEnabled() )
{
BuildColorData build;
build.init( key, layer, order, mapInfo, _terrainOptions, model.get() );
bool addedToModel = build.execute();
if ( addedToModel )
{
// only bump the order if we added something to the data model.
order++;
}
}
}
// make an elevation layer.
BuildElevationData build;
build.init( key, mapf, _terrainOptions, model.get(), _hfCache );
build.execute();
// Bail out now if there's no data to be had.
if ( model->_colorData.size() == 0 && !model->_elevationData.getHeightField() )
{
return;
}
// OK we are making a tile, so if there's no heightfield yet, make an empty one.
if ( !model->_elevationData.getHeightField() )
{
osg::HeightField* hf = HeightFieldUtils::createReferenceHeightField( key.getExtent(), 8, 8 );
model->_elevationData = TileModel::ElevationData(
hf,
GeoLocator::createForKey(key, mapInfo),
true );
}
if (!out_hasRealData)
{
// Check the results and see if we have any real data.
for( TileModel::ColorDataByUID::const_iterator i = model->_colorData.begin(); i != model->_colorData.end(); ++i )
{
if ( !i->second.isFallbackData() )
{
out_hasRealData = true;
break;
}
}
}
if ( !out_hasRealData && !model->_elevationData.isFallbackData() )
{
out_hasRealData = true;
}
// look up the parent model and cache it.
osg::ref_ptr<TileNode> parentTile;
if ( _liveTiles->get(key.createParentKey(), parentTile) )
model->_parentModel = parentTile->getTileModel();
out_model = model.release();
}
示例15: getProfile
bool
MapFrame::isCached( const osgEarth::TileKey& key ) const
{
const Profile* mapProfile = getProfile();
//Check the imagery layers
for( ImageLayerVector::const_iterator i = imageLayers().begin(); i != imageLayers().end(); i++ )
{
ImageLayer* layer = i->get();
osg::ref_ptr< Cache > cache = layer->getCache();
if ( !cache.valid() || !layer->getProfile() )
return false;
std::vector< TileKey > keys;
if ( mapProfile->isEquivalentTo( layer->getProfile() ) )
{
keys.push_back( key );
}
else
{
layer->getProfile()->getIntersectingTiles( key, keys );
}
for (unsigned int j = 0; j < keys.size(); ++j)
{
if ( layer->isKeyValid( keys[j] ) )
{
if ( !cache->isCached( keys[j], layer->getCacheSpec() ) )
{
return false;
}
}
}
}
for( ElevationLayerVector::const_iterator i = elevationLayers().begin(); i != elevationLayers().end(); ++i )
{
ElevationLayer* layer = i->get();
osg::ref_ptr< Cache > cache = layer->getCache();
if ( !cache.valid() || !layer->getProfile() )
return false;
std::vector<TileKey> keys;
if ( mapProfile->isEquivalentTo( layer->getProfile() ) )
{
keys.push_back( key );
}
else
{
layer->getProfile()->getIntersectingTiles( key, keys );
}
for (unsigned int j = 0; j < keys.size(); ++j)
{
if ( layer->isKeyValid( keys[j] ) )
{
if ( !cache->isCached( keys[j], layer->getCacheSpec() ) )
{
return false;
}
}
}
}
return true;
}