本文整理汇总了C++中TileKey类的典型用法代码示例。如果您正苦于以下问题:C++ TileKey类的具体用法?C++ TileKey怎么用?C++ TileKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TileKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
MPGeometry::MPGeometry(const TileKey& key, const MapFrame& frame, int imageUnit) :
osg::Geometry ( ),
_frame ( frame ),
_imageUnit ( imageUnit )
{
_supportsGLSL = Registry::capabilities().supportsGLSL();
unsigned tw, th;
key.getProfile()->getNumTiles(key.getLOD(), tw, th);
_tileKeyValue.set( key.getTileX(), th-key.getTileY()-1.0f, key.getLOD(), -1.0f );
_imageUnitParent = _imageUnit + 1; // temp
// establish uniform name IDs.
_tileKeyUniformNameID = osg::Uniform::getNameID( "oe_tile_key" );
_birthTimeUniformNameID = osg::Uniform::getNameID( "oe_tile_birthtime" );
_uidUniformNameID = osg::Uniform::getNameID( "oe_layer_uid" );
_orderUniformNameID = osg::Uniform::getNameID( "oe_layer_order" );
_opacityUniformNameID = osg::Uniform::getNameID( "oe_layer_opacity" );
_texMatParentUniformNameID = osg::Uniform::getNameID( "oe_layer_parent_matrix" );
// we will set these later (in TileModelCompiler)
this->setUseVertexBufferObjects(false);
this->setUseDisplayList(false);
}
示例2: intersects
bool
TileMap::intersectsKey(const TileKey& tilekey)
{
osg::Vec3d keyMin, keyMax;
//double keyMinX, keyMinY, keyMaxX, keyMaxY;
//Check to see if the key overlaps the bounding box using lat/lon. This is necessary to check even in
//Mercator situations in case the BoundingBox is described using lat/lon coordinates such as those produced by GDAL2Tiles
//This should be considered a bug on the TMS production side, but we can work around it for now...
tilekey.getExtent().getBounds(keyMin.x(), keyMin.y(), keyMax.x(), keyMax.y());
//tilekey.getExtent().getBounds(keyMinX, keyMinY, keyMaxX, keyMaxY);
bool inter = intersects(_minX, _minY, _maxX, _maxY, keyMin.x(), keyMin.y(), keyMax.x(), keyMax.y() ); //keyMinX, keyMinY, keyMaxX, keyMaxY);
if (!inter && tilekey.getProfile()->getSRS()->isSphericalMercator())
{
tilekey.getProfile()->getSRS()->transform(keyMin, tilekey.getProfile()->getSRS()->getGeographicSRS(), keyMin );
tilekey.getProfile()->getSRS()->transform(keyMax, tilekey.getProfile()->getSRS()->getGeographicSRS(), keyMax );
inter = intersects(_minX, _minY, _maxX, _maxY, keyMin.x(), keyMin.y(), keyMax.x(), keyMax.y() );
//tilekey.getProfile()->getSRS()->transform2D(keyMinX, keyMinY, tilekey.getProfile()->getSRS()->getGeographicSRS(), keyMinX, keyMinY);
//tilekey.getProfile()->getSRS()->transform2D(keyMaxX, keyMaxY, tilekey.getProfile()->getSRS()->getGeographicSRS(), keyMaxX, keyMaxY);
//inter = intersects(_minX, _minY, _maxX, _maxY, keyMinX, keyMinY, keyMaxX, keyMaxY);
}
return inter;
}
示例3: while
bool
OSGTileFactory::createValidGeoImage(ImageLayer* layer,
const TileKey& key,
GeoImage& out_image,
TileKey& out_actualTileKey,
ProgressCallback* progress)
{
//TODO: Redo this to just grab images from the parent TerrainTiles
//Try to create the image with the given key
out_actualTileKey = key;
while (out_actualTileKey.valid())
{
if ( layer->isKeyValid(out_actualTileKey) )
{
out_image = layer->createImage( out_actualTileKey, progress );
if ( out_image.valid() )
{
return true;
}
}
out_actualTileKey = out_actualTileKey.createParentKey();
}
return false;
}
示例4: lock
GeoImage
ElevationProxyImageLayer::createImage(const TileKey& key, ProgressCallback* progress)
{
if ( _mapf.needsSync() )
{
Threading::ScopedMutexLock lock(_mapfMutex);
if ( _mapf.needsSync() )
{
_mapf.sync();
}
}
osg::ref_ptr<osg::HeightField> hf = HeightFieldUtils::createReferenceHeightField(key.getExtent(), 257,257, true );
if ( _mapf.populateHeightField(hf, key, true, 0L) )
{
// encode the heightfield as a 16-bit normalized LUNIMANCE image
osg::Image* image = new osg::Image();
image->allocateImage(hf->getNumColumns(), hf->getNumRows(), 1, GL_LUMINANCE, GL_UNSIGNED_SHORT);
image->setInternalTextureFormat( GL_LUMINANCE16 );
const osg::FloatArray* floats = hf->getFloatArray();
for( unsigned int i = 0; i < floats->size(); ++i )
{
int col = i % hf->getNumColumns();
int row = i / hf->getNumColumns();
*(unsigned short*)image->data( col, row ) = (unsigned short)(32768 + (short)floats->at(i));
}
return GeoImage( image, key.getExtent() );
}
else
{
return GeoImage::INVALID;
}
}
示例5: getTerrainLayerOptions
bool
TerrainLayer::isKeyValid(const TileKey& key) const
{
if (!key.valid()) return false;
const TerrainLayerOptions& opt = getTerrainLayerOptions();
//Check to see if explicit levels of detail are set
if ( opt.minLevel().isSet() && (int)key.getLevelOfDetail() < opt.minLevel().value() ) return false;
if ( opt.maxLevel().isSet() && (int)key.getLevelOfDetail() > opt.maxLevel().value() ) return false;
//Check to see if levels of detail based on resolution are set
if (opt.minLevelResolution().isSet())
{
unsigned int minLevel = getProfile()->getLevelOfDetailForHorizResolution( opt.minLevelResolution().value(), getTileSize());
OE_DEBUG << "Computed min level of " << minLevel << std::endl;
if (key.getLevelOfDetail() < minLevel) return false;
}
if (opt.maxLevelResolution().isSet())
{
unsigned int maxLevel = getProfile()->getLevelOfDetailForHorizResolution( opt.maxLevelResolution().value(), getTileSize());
OE_DEBUG << "Computed max level of " << maxLevel << std::endl;
if (key.getLevelOfDetail() > maxLevel) return false;
}
return true;
}
示例6:
// This will be called by AnnotationNode when a new terrain tile comes in.
void
FeatureNode::onTileAdded(const TileKey& key,
osg::Node* graph,
TerrainCallbackContext& context)
{
if (!_clampDirty)
{
bool needsClamp;
if (key.valid())
{
osg::Polytope tope;
key.getExtent().createPolytope(tope);
needsClamp = tope.contains(this->getBound());
}
else
{
// without a valid tilekey we don't know the extent of the change,
// so clamping is required.
needsClamp = true;
}
if (needsClamp)
{
_clampDirty = true;
ADJUST_UPDATE_TRAV_COUNT(this, +1);
//clamp(graph, context.getTerrain());
}
}
}
示例7: GetTileKeyByPoint
void SelectionShape::Render(ScreenBase const & screen, int zoomLevel, ref_ptr<dp::GpuProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms)
{
ShowHideAnimation::EState state = m_animation.GetState();
if (state == ShowHideAnimation::STATE_VISIBLE ||
state == ShowHideAnimation::STATE_SHOW_DIRECTION)
{
dp::UniformValuesStorage uniforms = commonUniforms;
TileKey const key = GetTileKeyByPoint(m_position, ClipTileZoomByMaxDataZoom(zoomLevel));
math::Matrix<float, 4, 4> mv = key.GetTileBasedModelView(screen);
uniforms.SetMatrix4x4Value("modelView", mv.m_data);
m2::PointD const pos = MapShape::ConvertToLocal(m_position, key.GetGlobalRect().Center(), kShapeCoordScalar);
uniforms.SetFloatValue("u_position", pos.x, pos.y, -m_positionZ);
float accuracy = m_mapping.GetValue(m_animation.GetT());
if (screen.isPerspective())
{
m2::PointD const pt1 = screen.GtoP(m_position);
m2::PointD const pt2(pt1.x + 1, pt1.y);
float const scale = screen.PtoP3d(pt2).x - screen.PtoP3d(pt1).x;
accuracy /= scale;
}
uniforms.SetFloatValue("u_accuracy", accuracy);
uniforms.SetFloatValue("u_opacity", 1.0f);
m_renderNode->Render(mng, uniforms);
}
}
示例8: while
bool
ElevationPool::getTile(const TileKey& key, const ElevationLayerVector& layers, osg::ref_ptr<ElevationPool::Tile>& output)
{
OE_START_TIMER(get);
const double timeout = 30.0;
osg::ref_ptr<Tile> tile;
while( tryTile(key, layers, tile) && !tile.valid() && OE_GET_TIMER(get) < timeout)
{
// condition: another thread is working on fetching the tile from the map,
// so wait and try again later. Do this until we succeed or time out.
OpenThreads::Thread::YieldCurrentThread();
}
if ( !tile.valid() && OE_GET_TIMER(get) >= timeout )
{
// this means we timed out trying to fetch the map tile.
OE_TEST << LC << "Timeout fetching tile " << key.str() << std::endl;
}
if ( tile.valid() )
{
if ( tile->_hf.valid() )
{
// got a valid tile, so push it to the query set.
output = tile.get();
}
else
{
OE_WARN << LC << "Got a tile with an invalid HF (" << key.str() << ")\n";
}
}
return tile.valid();
}
示例9: processKey
void TMSBackFiller::processKey( const TileKey& key )
{
if (_verbose) OE_NOTICE << "Processing key " << key.str() << std::endl;
//Get all of the child tiles for this key, load them and mosaic them into a new tile
TileKey ulKey = key.createChildKey( 0 );
TileKey urKey = key.createChildKey( 1 );
TileKey llKey = key.createChildKey( 2 );
TileKey lrKey = key.createChildKey( 3 );
osg::ref_ptr< osg::Image > ul = readTile( ulKey );
osg::ref_ptr< osg::Image > ur = readTile( urKey );
osg::ref_ptr< osg::Image > ll = readTile( llKey );
osg::ref_ptr< osg::Image > lr = readTile( lrKey );
if (ul.valid() && ur.valid() && ll.valid() && lr.valid())
{
//Merge them together
ImageMosaic mosaic;
mosaic.getImages().push_back( TileImage( ul.get(), ulKey ) );
mosaic.getImages().push_back( TileImage( ur.get(), urKey ) );
mosaic.getImages().push_back( TileImage( ll.get(), llKey ) );
mosaic.getImages().push_back( TileImage( lr.get(), lrKey ) );
osg::ref_ptr< osg::Image> merged = mosaic.createImage();
if (merged.valid())
{
//Resize the image so it's the same size as one of the input files
osg::ref_ptr<osg::Image> resized;
ImageUtils::resizeImage( merged.get(), ul->s(), ul->t(), resized );
std::string outputFilename = getFilename( key );
writeTile( key, resized.get() );
}
}
}
示例10: assembleImage
GeoImage
ImageLayer::createImageFromTileSource(const TileKey& key,
ProgressCallback* progress)
{
TileSource* source = getTileSource();
if ( !source )
return GeoImage::INVALID;
// If the profiles are different, use a compositing method to assemble the tile.
if ( !key.getProfile()->isHorizEquivalentTo( getProfile() ) )
{
return assembleImage( key, progress );
}
// Good to go, ask the tile source for an image:
osg::ref_ptr<TileSource::ImageOperation> op = getOrCreatePreCacheOp();
// Fail is the image is blacklisted.
if ( source->getBlacklist()->contains(key) )
{
OE_DEBUG << LC << "createImageFromTileSource: blacklisted(" << key.str() << ")" << std::endl;
return GeoImage::INVALID;
}
if (!mayHaveData(key))
{
OE_DEBUG << LC << "createImageFromTileSource: mayHaveData(" << key.str() << ") == false" << std::endl;
return GeoImage::INVALID;
}
//if ( !source->hasData( key ) )
//{
// OE_DEBUG << LC << "createImageFromTileSource: hasData(" << key.str() << ") == false" << std::endl;
// return GeoImage::INVALID;
//}
// create an image from the tile source.
osg::ref_ptr<osg::Image> result = source->createImage( key, op.get(), progress );
// Process images with full alpha to properly support MP blending.
if (result.valid() &&
options().featherPixels() == true)
{
ImageUtils::featherAlphaRegions( result.get() );
}
// If image creation failed (but was not intentionally canceled and
// didn't time out or end for any other recoverable reason), then
// blacklist this tile for future requests.
if (result == 0L)
{
if ( progress == 0L ||
( !progress->isCanceled() && !progress->needsRetry() ) )
{
source->getBlacklist()->add( key );
}
}
return GeoImage(result.get(), key.getExtent());
}
示例11:
void
TileModelFactory::buildElevation(const TileKey& key,
const MapFrame& frame,
bool accumulate,
TileModel* model,
ProgressCallback* progress)
{
const MapInfo& mapInfo = frame.getMapInfo();
const osgEarth::ElevationInterpolation& interp =
frame.getMapOptions().elevationInterpolation().get();
// Request a heightfield from the map, falling back on lower resolution tiles
// if necessary (fallback=true)
osg::ref_ptr<osg::HeightField> hf;
bool isFallback = false;
if (_hfCache->getOrCreateHeightField(frame, key, accumulate, hf, isFallback, SAMPLE_FIRST_VALID, interp, progress))
{
model->_elevationData = TileModel::ElevationData(
hf,
GeoLocator::createForKey( key, mapInfo ),
isFallback );
// Edge normalization: requires adjacency information
if ( _terrainOptions.normalizeEdges() == true )
{
for( int x=-1; x<=1; x++ )
{
for( int y=-1; y<=1; y++ )
{
if ( x != 0 || y != 0 )
{
TileKey nk = key.createNeighborKey(x, y);
if ( nk.valid() )
{
osg::ref_ptr<osg::HeightField> hf;
if (_hfCache->getOrCreateHeightField(frame, nk, accumulate, hf, isFallback, SAMPLE_FIRST_VALID, interp, progress) )
{
model->_elevationData.setNeighbor( x, y, hf.get() );
}
}
}
}
}
// parent too.
if ( key.getLOD() > 0 )
{
osg::ref_ptr<osg::HeightField> hf;
if ( _hfCache->getOrCreateHeightField(frame, key.createParentKey(), accumulate, hf, isFallback, SAMPLE_FIRST_VALID, interp, progress) )
{
model->_elevationData.setParent( hf.get() );
}
}
}
}
}
示例12: cacheTile
void
CacheSeed::processKey(const MapFrame& mapf, const TileKey& key ) const
{
unsigned int x, y, lod;
key.getTileXY(x, y);
lod = key.getLevelOfDetail();
bool gotData = true;
if ( _minLevel <= lod && _maxLevel >= lod )
{
gotData = cacheTile( mapf, key );
if (gotData)
{
incrementCompleted( 1 );
}
if ( _progress.valid() && _progress->isCanceled() )
return; // Task has been cancelled by user
if ( _progress.valid() && gotData && _progress->reportProgress(_completed, _total, std::string("Cached tile: ") + key.str()) )
return; // Canceled
}
if ( gotData && lod <= _maxLevel )
{
TileKey k0 = key.createChildKey(0);
TileKey k1 = key.createChildKey(1);
TileKey k2 = key.createChildKey(2);
TileKey k3 = key.createChildKey(3);
bool intersectsKey = false;
if (_extents.empty()) intersectsKey = true;
else
{
for (unsigned int i = 0; i < _extents.size(); ++i)
{
if (_extents[i].intersects( k0.getExtent() ) ||
_extents[i].intersects( k1.getExtent() ) ||
_extents[i].intersects( k2.getExtent() ) ||
_extents[i].intersects( k3.getExtent() ))
{
intersectsKey = true;
}
}
}
//Check to see if the bounds intersects ANY of the tile's children. If it does, then process all of the children
//for this level
if (intersectsKey)
{
processKey(mapf, k0);
processKey(mapf, k1);
processKey(mapf, k2);
processKey(mapf, k3);
}
}
}
示例13: TileModel
osg::Node*
MPTerrainEngineNode::createTile( const TileKey& key )
{
osg::ref_ptr<TileModel> model = new TileModel( _update_mapf->getRevision(), _update_mapf->getMapInfo() );
model->_tileKey = key;
model->_tileLocator = GeoLocator::createForKey(key, _update_mapf->getMapInfo());
// Build the heightfield
const MapInfo& mapInfo = _update_mapf->getMapInfo();
const osgEarth::ElevationInterpolation& interp = _update_mapf->getMapOptions().elevationInterpolation().get();
// Request a heightfield from the map, falling back on lower resolution tiles
osg::ref_ptr<osg::HeightField> hf;
TileKey sampleKey = key;
bool populated = false;
if (_update_mapf->elevationLayers().size() > 0)
{
while (!populated)
{
populated = _update_mapf->populateHeightField(hf, sampleKey, true, SAMPLE_FIRST_VALID);
if (!populated)
{
// Fallback on the parent
sampleKey = sampleKey.createParentKey();
if (!sampleKey.valid())
{
return 0;
}
}
}
}
if (!populated)
{
// We have no heightfield so just create a reference heightfield.
hf = HeightFieldUtils::createReferenceHeightField( key.getExtent(), 15, 15 );
sampleKey = key;
}
model->_elevationData = TileModel::ElevationData(
hf,
GeoLocator::createForKey( sampleKey, mapInfo ),
false );
bool optimizeTriangleOrientation = getMap()->getMapOptions().elevationInterpolation() != INTERP_TRIANGULATE;
osg::ref_ptr<TileModelCompiler> compiler = new TileModelCompiler(
_update_mapf->terrainMaskLayers(),
_update_mapf->modelLayers(),
_primaryUnit,
optimizeTriangleOrientation,
_terrainOptions );
return compiler->compile(model.get(), *_update_mapf, 0L);
}
示例14: sharedLock
void
OSGTileFactory::addPlaceholderHeightfieldLayer(StreamingTile* tile,
StreamingTile* ancestorTile,
GeoLocator* defaultLocator,
const TileKey& key,
const TileKey& ancestorKey)
{
osgTerrain::HeightFieldLayer* newHFLayer = 0L;
if ( ancestorTile && ancestorKey.valid() )
{
osg::ref_ptr<osgTerrain::HeightFieldLayer> ancestorLayer;
{
Threading::ScopedReadLock sharedLock( ancestorTile->getTileLayersMutex() );
ancestorLayer = dynamic_cast<osgTerrain::HeightFieldLayer*>(ancestorTile->getElevationLayer());
}
if ( ancestorLayer.valid() )
{
osg::ref_ptr<osg::HeightField> ancestorHF = ancestorLayer->getHeightField();
if ( ancestorHF.valid() )
{
osg::HeightField* newHF = HeightFieldUtils::createSubSample(
ancestorHF.get(),
ancestorKey.getExtent(),
key.getExtent());
newHFLayer = new osgTerrain::HeightFieldLayer( newHF );
newHFLayer->setLocator( defaultLocator );
// lock to set the elevation layerdata:
{
Threading::ScopedWriteLock exclusiveLock( tile->getTileLayersMutex() );
tile->setElevationLayer( newHFLayer );
tile->setElevationLOD( ancestorTile->getElevationLOD() );
}
}
}
}
// lock the tile to write the elevation data.
{
Threading::ScopedWriteLock exclusiveLock( tile->getTileLayersMutex() );
if ( !newHFLayer )
{
newHFLayer = new osgTerrain::HeightFieldLayer();
newHFLayer->setHeightField( createEmptyHeightField( key, 8, 8 ) );
newHFLayer->setLocator( defaultLocator );
tile->setElevationLOD( -1 );
}
if ( newHFLayer )
{
tile->setElevationLayer( newHFLayer );
}
}
}
示例15: update
void update( float x, float y, osgViewer::View* view )
{
bool yes = false;
// look under the mouse:
osg::Vec3d world;
osgUtil::LineSegmentIntersector::Intersections hits;
if ( view->computeIntersections(x, y, hits) )
{
world = hits.begin()->getWorldIntersectPoint();
// convert to map coords:
GeoPoint mapPoint;
mapPoint.fromWorld( s_mapNode->getMapSRS(), world );
// Depending on the level of detail key you request, you will get a mesh that should line up exactly with the highest resolution mesh that the terrain engine will draw.
// At level 15 that is a 257x257 heightfield. If you select a higher lod, the mesh will be less dense.
TileKey key = s_mapNode->getMap()->getProfile()->createTileKey(mapPoint.x(), mapPoint.y(), 15);
OE_NOTICE << "Creating tile " << key.str() << std::endl;
osg::ref_ptr<osg::Node> node = s_mapNode->getTerrainEngine()->createTile(key);
if (node.valid())
{
// Extract the triangles from the node that was created and do our own rendering. Simulates what you would do when passing in the triangles to a physics engine.
OE_NOTICE << "Created tile for " << key.str() << std::endl;
CollectTrianglesVisitor v;
node->accept(v);
node = v.buildNode();
if (_node.valid())
{
s_root->removeChild( _node.get() );
}
osg::Group* group = new osg::Group;
// Show the actual mesh.
group->addChild( node.get() );
_node = group;
// Clamp the marker to the intersection of the triangles created by osgEarth. This should line up with the mesh that is actually rendered.
double z = 0.0;
s_mapNode->getTerrain()->getHeight( node, s_mapNode->getMapSRS(), mapPoint.x(), mapPoint.y(), &z);
GeoTransform* xform = new GeoTransform();
xform->setPosition( osgEarth::GeoPoint(s_mapNode->getMapSRS(),mapPoint.x(), mapPoint.y(), z, ALTMODE_ABSOLUTE) );
xform->addChild( marker.get() );
group->addChild( xform );
s_root->addChild( _node.get() );
}
else
{
OE_NOTICE << "Failed to create tile for " << key.str() << std::endl;
}
}
}