本文整理汇总了C++中TileKey::getTileY方法的典型用法代码示例。如果您正苦于以下问题:C++ TileKey::getTileY方法的具体用法?C++ TileKey::getTileY怎么用?C++ TileKey::getTileY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileKey
的用法示例。
在下文中一共展示了TileKey::getTileY方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOrCreateHeightFieldsForDeformation
/**
* Gets or creates the heightfields that would be effected by the given deformation
*/
void getOrCreateHeightFieldsForDeformation(const Deformation& deformation, unsigned int level, HeightFieldMap& results)
{
OpenThreads::ScopedLock< OpenThreads::Mutex > lk(_mutex);
// Get the extent of the deformation feature.
GeoExtent extent(deformation._feature->getSRS(), deformation._feature->getGeometry()->getBounds());
TileKey ll = getProfile()->createTileKey(extent.xMin(), extent.yMin(), level);
TileKey ur = getProfile()->createTileKey(extent.xMax(), extent.yMax(), level);
for (unsigned int c = ll.getTileX(); c <= ur.getTileX(); c++)
{
for (unsigned int r = ur.getTileY(); r <= ll.getTileY(); r++)
{
TileKey key(level, c, r, getProfile());
osg::ref_ptr< osg::HeightField > hf;
HeightFieldMap::iterator itr = _heightfields.find( key );
if (itr == _heightfields.end())
{
//Allocate a new heightfield
hf = new osg::HeightField;
hf->allocate(getPixelsPerTile(), getPixelsPerTile());
for (unsigned int i = 0; i < hf->getHeightList().size(); ++i) hf->getHeightList()[i] = NO_DATA_VALUE;
_heightfields[ key ] = hf.get();
results[ key ] = hf.get();
}
else
{
results[ key ] = itr->second.get();
}
}
}
}
示例2:
unsigned int
CacheEstimator::getNumTiles() const
{
unsigned int total = 0;
for (unsigned int level = _minLevel; level <= _maxLevel; level++)
{
if (_extents.empty())
{
unsigned int wide, high;
_profile->getNumTiles( level, wide, high );
total += (wide * high);
}
else
{
for (std::vector< GeoExtent >::const_iterator itr = _extents.begin(); itr != _extents.end(); ++itr)
{
const GeoExtent& extent = *itr;
TileKey ll = _profile->createTileKey(extent.xMin(), extent.yMin(), level);
TileKey ur = _profile->createTileKey(extent.xMax(), extent.yMax(), level);
if (!ll.valid() || !ur.valid()) continue;
int tilesWide = ur.getTileX() - ll.getTileX() + 1;
int tilesHigh = ll.getTileY() - ur.getTileY() + 1;
int tilesAtLevel = tilesWide * tilesHigh;
total += tilesAtLevel;
}
}
}
return total;
}
示例3:
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);
}
示例4: createFeatureCursor
FeatureCursor* createFeatureCursor( const Symbology::Query& query )
{
TileKey key = *query.tileKey();
int z = key.getLevelOfDetail();
int tileX = key.getTileX();
int tileY = key.getTileY();
unsigned int numRows, numCols;
key.getProfile()->getNumTiles(key.getLevelOfDetail(), numCols, numRows);
tileY = numRows - tileY - 1;
//Get the image
sqlite3_stmt* select = NULL;
std::string queryStr = "SELECT tile_data from tiles where zoom_level = ? AND tile_column = ? AND tile_row = ?";
int rc = sqlite3_prepare_v2( _database, queryStr.c_str(), -1, &select, 0L );
if ( rc != SQLITE_OK )
{
OE_WARN << LC << "Failed to prepare SQL: " << queryStr << "; " << sqlite3_errmsg(_database) << std::endl;
return NULL;
}
bool valid = true;
sqlite3_bind_int( select, 1, z );
sqlite3_bind_int( select, 2, tileX );
sqlite3_bind_int( select, 3, tileY );
rc = sqlite3_step( select );
FeatureList features;
if ( rc == SQLITE_ROW)
{
// the pointer returned from _blob gets freed internally by sqlite, supposedly
const char* data = (const char*)sqlite3_column_blob( select, 0 );
int dataLen = sqlite3_column_bytes( select, 0 );
std::string dataBuffer( data, dataLen );
std::stringstream in(dataBuffer);
MVT::read(in, key, features);
}
else
{
OE_DEBUG << LC << "SQL QUERY failed for " << queryStr << ": " << std::endl;
valid = false;
}
sqlite3_finalize( select );
// apply filters before returning.
applyFilters( features );
if (!features.empty())
{
//OE_NOTICE << "Returning " << features.size() << " features" << std::endl;
return new FeatureListCursor(features);
}
return 0;
}
示例5: process
void TMSBackFiller::process( const std::string& tms, osgDB::Options* options )
{
std::string fullPath = getFullPath( "", tms );
_options = options;
//Read the tilemap
_tileMap = TileMapReaderWriter::read( fullPath, 0 );
if (_tileMap)
{
//The max level is where we are going to read data from, so we need to start one level up.
osg::ref_ptr< const Profile> profile = _tileMap->createProfile();
//If the bounds aren't valid just use the full extent of the profile.
if (!_bounds.valid())
{
_bounds = profile->getExtent().bounds();
}
int firstLevel = _maxLevel-1;
GeoExtent extent( profile->getSRS(), _bounds );
//Process each level in it's entirety
for (int level = firstLevel; level >= static_cast<int>(_minLevel); level--)
{
if (_verbose) OE_NOTICE << "Processing level " << level << std::endl;
TileKey ll = profile->createTileKey(extent.xMin(), extent.yMin(), level);
TileKey ur = profile->createTileKey(extent.xMax(), extent.yMax(), level);
for (unsigned int x = ll.getTileX(); x <= ur.getTileX(); x++)
{
for (unsigned int y = ur.getTileY(); y <= ll.getTileY(); y++)
{
TileKey key = TileKey(level, x, y, profile.get());
processKey( key );
}
}
}
}
else
{
OE_NOTICE << "Failed to load TileMap from " << _tmsPath << std::endl;
}
}
示例6: pow
MPGeometry::MPGeometry(const TileKey& key, const MapFrame& frame, int imageUnit) :
osg::Geometry ( ),
_frame ( frame ),
_imageUnit ( imageUnit ),
_uidUniformNameID(0),
_birthTimeUniformNameID(0u),
_orderUniformNameID(0u),
_opacityUniformNameID(0u),
_texMatParentUniformNameID(0u),
_tileKeyUniformNameID(0u),
_minRangeUniformNameID(0u),
_maxRangeUniformNameID(0u),
_imageUnitParent(0),
_elevUnit(0),
_supportsGLSL(false)
{
_supportsGLSL = Registry::capabilities().supportsGLSL();
// Encode the tile key in a uniform. Note! The X and Y components are presented
// modulo 2^16 form so they don't overrun single-precision space.
unsigned tw, th;
key.getProfile()->getNumTiles(key.getLOD(), tw, th);
const double m = pow(2.0, 16.0);
double x = (double)key.getTileX();
double y = (double)(th - key.getTileY()-1);
_tileKeyValue.set(
(float)fmod(x, m),
(float)fmod(y, m),
(float)key.getLOD(),
-1.0f);
_imageUnitParent = _imageUnit + 1; // temp
_elevUnit = _imageUnit + 2; // 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_texmat" );
_minRangeUniformNameID = osg::Uniform::getNameID( "oe_layer_minRange" );
_maxRangeUniformNameID = osg::Uniform::getNameID( "oe_layer_maxRange" );
// we will set these later (in TileModelCompiler)
this->setUseDisplayList(false);
this->setUseVertexBufferObjects(true);
}
示例7: exclusiveLock
bool
MBTilesTileSource::storeImage(const TileKey& key,
osg::Image* image,
ProgressCallback* progress)
{
if ( (getMode() & MODE_WRITE) == 0 )
return false;
Threading::ScopedMutexLock exclusiveLock(_mutex);
// encode the data stream:
std::stringstream buf;
osgDB::ReaderWriter::WriteResult wr;
if ( _forceRGB && ImageUtils::hasAlphaChannel(image) )
{
osg::ref_ptr<osg::Image> rgb = ImageUtils::convertToRGB8(image);
wr = _rw->writeImage(*(rgb.get()), buf, _dbOptions.get());
}
else
{
wr = _rw->writeImage(*image, buf, _dbOptions.get());
}
if ( wr.error() )
{
OE_WARN << LC << "Image encoding failed: " << wr.message() << std::endl;
return false;
}
std::string value = buf.str();
// compress if necessary:
if ( _compressor.valid() )
{
std::ostringstream output;
if ( !_compressor->compress(output, value) )
{
OE_WARN << LC << "Compressor failed" << std::endl;
return false;
}
value = output.str();
}
int z = key.getLOD();
int x = key.getTileX();
int y = key.getTileY();
// flip Y axis
unsigned int numRows, numCols;
key.getProfile()->getNumTiles(key.getLevelOfDetail(), numCols, numRows);
y = numRows - y - 1;
// Prep the insert statement:
sqlite3_stmt* insert = NULL;
std::string query = "INSERT OR REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES (?, ?, ?, ?)";
int rc = sqlite3_prepare_v2( _database, query.c_str(), -1, &insert, 0L );
if ( rc != SQLITE_OK )
{
OE_WARN << LC << "Failed to prepare SQL: " << query << "; " << sqlite3_errmsg(_database) << std::endl;
return false;
}
// bind parameters:
sqlite3_bind_int( insert, 1, z );
sqlite3_bind_int( insert, 2, x );
sqlite3_bind_int( insert, 3, y );
// bind the data blob:
sqlite3_bind_blob( insert, 4, value.c_str(), value.length(), SQLITE_STATIC );
// run the sql.
bool ok = true;
int tries = 0;
do {
rc = sqlite3_step(insert);
}
while (++tries < 100 && (rc == SQLITE_BUSY || rc == SQLITE_LOCKED));
if (SQLITE_OK != rc && SQLITE_DONE != rc)
{
#if SQLITE_VERSION_NUMBER >= 3007015
OE_WARN << LC << "Failed query: " << query << "(" << rc << ")" << sqlite3_errstr(rc) << "; " << sqlite3_errmsg(_database) << std::endl;
#else
OE_WARN << LC << "Failed query: " << query << "(" << rc << ")" << rc << "; " << sqlite3_errmsg(_database) << std::endl;
#endif
ok = false;
}
sqlite3_finalize( insert );
return ok;
}
示例8: createFeatureCursor
FeatureCursor* createFeatureCursor( const Symbology::Query& query )
{
TileKey key = *query.tileKey();
int z = key.getLevelOfDetail();
int tileX = key.getTileX();
int tileY = key.getTileY();
unsigned int numRows, numCols;
key.getProfile()->getNumTiles(key.getLevelOfDetail(), numCols, numRows);
tileY = numRows - tileY - 1;
//Get the image
sqlite3_stmt* select = NULL;
std::string queryStr = "SELECT tile_data from tiles where zoom_level = ? AND tile_column = ? AND tile_row = ?";
int rc = sqlite3_prepare_v2( _database, queryStr.c_str(), -1, &select, 0L );
if ( rc != SQLITE_OK )
{
OE_WARN << LC << "Failed to prepare SQL: " << queryStr << "; " << sqlite3_errmsg(_database) << std::endl;
return NULL;
}
bool valid = true;
sqlite3_bind_int( select, 1, z );
sqlite3_bind_int( select, 2, tileX );
sqlite3_bind_int( select, 3, tileY );
rc = sqlite3_step( select );
FeatureList features;
if ( rc == SQLITE_ROW)
{
// the pointer returned from _blob gets freed internally by sqlite, supposedly
const char* data = (const char*)sqlite3_column_blob( select, 0 );
int dataLen = sqlite3_column_bytes( select, 0 );
std::string dataBuffer( data, dataLen );
// decompress if necessary:
if ( _compressor.valid() )
{
std::istringstream inputStream(dataBuffer);
std::string value;
if ( !_compressor->decompress(inputStream, value) )
{
OE_WARN << LC << "Decompression failed" << std::endl;
valid = false;
}
else
{
dataBuffer = value;
}
}
mapnik::vector::tile tile;
if (tile.ParseFromString(dataBuffer))
{
// Get the layer in question
for (unsigned int i = 0; i < tile.layers().size(); i++)
{
const mapnik::vector::tile_layer &layer = tile.layers().Get(i);
//OE_NOTICE << layer.name() << std::endl;
//if (layer.name() != "road") continue;
//if (layer.name() != "building") continue;
for (unsigned int j = 0; j < layer.features().size(); j++)
{
const mapnik::vector::tile_feature &feature = layer.features().Get(j);
osg::ref_ptr< osgEarth::Symbology::Geometry > geometry;
eGeomType geomType = static_cast<eGeomType>(feature.type());
if (geomType == ::Polygon)
{
//OE_NOTICE << "Polygon " << std::endl;
geometry = new osgEarth::Symbology::Polygon();
}
else if (geomType == ::LineString)
{
//OE_NOTICE << "LineString" << std::endl;
geometry = new osgEarth::Symbology::LineString();
}
else if (geomType == ::Point)
{
//OE_NOTICE << "Point" << std::endl;
geometry = new osgEarth::Symbology::PointSet();
}
else
{
//OE_NOTICE << "uknown" << std::endl;
geometry = new osgEarth::Symbology::LineString();
}
osg::ref_ptr< Feature > oeFeature = new Feature(geometry, key.getProfile()->getSRS());
//.........这里部分代码省略.........
示例9: bestKey
bool
ElevationLayerVector::populateHeightFieldAndNormalMap(osg::HeightField* hf,
NormalMap* normalMap,
const TileKey& key,
const Profile* haeProfile,
ElevationInterpolation interpolation,
ProgressCallback* progress ) const
{
// heightfield must already exist.
if ( !hf )
return false;
METRIC_SCOPED("ElevationLayer.populateHeightField");
// if the caller provided an "HAE map profile", he wants an HAE elevation grid even if
// the map profile has a vertical datum. This is the usual case when building the 3D
// terrain, for example. Construct a temporary key that doesn't have the vertical
// datum info and use that to query the elevation data.
TileKey keyToUse = key;
if ( haeProfile )
{
keyToUse = TileKey(key.getLOD(), key.getTileX(), key.getTileY(), haeProfile );
}
// Collect the valid layers for this tile.
LayerDataVector contenders;
LayerDataVector offsets;
#ifdef ANALYZE
struct LayerAnalysis {
LayerAnalysis() : samples(0), used(false), failed(false), fallback(false), actualKeyValid(true) { }
int samples; bool used; bool failed; bool fallback; bool actualKeyValid; std::string message;
};
std::map<ElevationLayer*, LayerAnalysis> layerAnalysis;
#endif
// Track the number of layers that would return fallback data.
unsigned numFallbackLayers = 0;
// Check them in reverse order since the highest priority is last.
for (int i = size()-1; i>=0; --i)
//for(ElevationLayerVector::const_reverse_iterator i = this->rbegin(); i != this->rend(); ++i)
{
ElevationLayer* layer = (*this)[i].get(); //i->get();
if ( layer->getEnabled() && layer->getVisible() )
{
// calculate the resolution-mapped key (adjusted for tile resolution differential).
TileKey mappedKey = keyToUse.mapResolution(
hf->getNumColumns(),
layer->getTileSize() );
bool useLayer = true;
TileKey bestKey( mappedKey );
// Check whether the non-mapped key is valid according to the user's min/max level settings:
if ( !layer->isKeyInLegalRange(key) )
{
useLayer = false;
}
// Find the "best available" mapped key from the tile source:
else
{
bestKey = layer->getBestAvailableTileKey(mappedKey);
if (bestKey.valid())
{
// If the bestKey is not the mappedKey, this layer is providing
// fallback data (data at a lower resolution than requested)
if ( mappedKey != bestKey )
{
numFallbackLayers++;
}
}
else
{
useLayer = false;
}
}
if ( useLayer )
{
if ( layer->isOffset() )
{
offsets.push_back(LayerData());
LayerData& ld = offsets.back();
ld.layer = layer;
ld.key = bestKey;
ld.index = i;
}
else
{
contenders.push_back(LayerData());
LayerData& ld = contenders.back();
ld.layer = layer;
ld.key = bestKey;
ld.index = i;
}
#ifdef ANALYZE
//.........这里部分代码省略.........
示例10: seed
//.........这里部分代码省略.........
{
_maxLevel = src_max_level;
}
OE_NOTICE << LC << "Maximum cache level will be " << _maxLevel << std::endl;
osg::Timer_t startTime = osg::Timer::instance()->tick();
//Estimate the number of tiles
_total = 0;
for (unsigned int level = _minLevel; level <= _maxLevel; level++)
{
double coverageRatio = 0.0;
if (_extents.empty())
{
unsigned int wide, high;
map->getProfile()->getNumTiles( level, wide, high );
_total += (wide * high);
}
else
{
for (std::vector< GeoExtent >::const_iterator itr = _extents.begin(); itr != _extents.end(); itr++)
{
const GeoExtent& extent = *itr;
double boundsArea = extent.area();
TileKey ll = map->getProfile()->createTileKey(extent.xMin(), extent.yMin(), level);
TileKey ur = map->getProfile()->createTileKey(extent.xMax(), extent.yMax(), level);
if (!ll.valid() || !ur.valid()) continue;
int tilesWide = ur.getTileX() - ll.getTileX() + 1;
int tilesHigh = ll.getTileY() - ur.getTileY() + 1;
int tilesAtLevel = tilesWide * tilesHigh;
//OE_NOTICE << "Tiles at level " << level << "=" << tilesAtLevel << std::endl;
/*
bool hasData = false;
for (ImageLayerVector::const_iterator itr = mapf.imageLayers().begin(); itr != mapf.imageLayers().end(); itr++)
{
TileSource* src = itr->get()->getTileSource();
if (src)
{
if (src->hasDataAtLOD( level ))
{
//Compute the percent coverage of this dataset on the current extent
if (src->getDataExtents().size() > 0)
{
double cov = 0.0;
for (unsigned int j = 0; j < src->getDataExtents().size(); j++)
{
GeoExtent b = src->getDataExtents()[j].transform( extent.getSRS());
GeoExtent intersection = b.intersectionSameSRS( extent );
if (intersection.isValid())
{
double coverage = intersection.area() / boundsArea;
cov += coverage; //Assumes the extents aren't overlapping
}
}
if (coverageRatio < cov) coverageRatio = cov;
}
else
{
//We have no way of knowing how much coverage we have
示例11: if
bool
ElevationLayerVector::createHeightField(const TileKey& key,
bool fallback,
const Profile* haeProfile,
ElevationInterpolation interpolation,
ElevationSamplePolicy samplePolicy,
osg::ref_ptr<osg::HeightField>& out_result,
bool* out_isFallback,
ProgressCallback* progress ) const
{
unsigned lowestLOD = key.getLevelOfDetail();
bool hfInitialized = false;
//Get a HeightField for each of the enabled layers
GeoHeightFieldVector heightFields;
//The number of fallback heightfields we have
int numFallbacks = 0;
//Default to being fallback data.
if ( out_isFallback )
{
*out_isFallback = true;
}
// if the caller provided an "HAE map profile", he wants an HAE elevation grid even if
// the map profile has a vertical datum. This is the usual case when building the 3D
// terrain, for example. Construct a temporary key that doesn't have the vertical
// datum info and use that to query the elevation data.
TileKey keyToUse = key;
if ( haeProfile )
{
keyToUse = TileKey(key.getLevelOfDetail(), key.getTileX(), key.getTileY(), haeProfile );
}
// Generate a heightfield for each elevation layer.
unsigned defElevSize = 8;
for( ElevationLayerVector::const_iterator i = this->begin(); i != this->end(); i++ )
{
ElevationLayer* layer = i->get();
if ( layer->getVisible() )
{
GeoHeightField geoHF = layer->createHeightField( keyToUse, progress );
// if "fallback" is set, try to fall back on lower LODs.
if ( !geoHF.valid() && fallback )
{
TileKey hf_key = keyToUse.createParentKey();
while ( hf_key.valid() && !geoHF.valid() )
{
geoHF = layer->createHeightField( hf_key, progress );
if ( !geoHF.valid() )
hf_key = hf_key.createParentKey();
}
if ( geoHF.valid() )
{
if ( hf_key.getLevelOfDetail() < lowestLOD )
lowestLOD = hf_key.getLevelOfDetail();
//This HeightField is fallback data, so increment the count.
numFallbacks++;
}
}
if ( geoHF.valid() )
{
heightFields.push_back( geoHF );
}
}
}
//If any of the layers produced valid data then it's not considered a fallback
if ( out_isFallback )
{
*out_isFallback = (numFallbacks == heightFields.size());
//OE_NOTICE << "Num fallbacks=" << numFallbacks << " numHeightFields=" << heightFields.size() << " is fallback " << *out_isFallback << std::endl;
}
if ( heightFields.size() == 0 )
{
//If we got no heightfields but were requested to fallback, create an empty heightfield.
if ( fallback )
{
out_result = HeightFieldUtils::createReferenceHeightField( keyToUse.getExtent(), defElevSize, defElevSize );
return true;
}
else
{
//We weren't requested to fallback so just return.
return false;
}
}
else if (heightFields.size() == 1)
{
if ( lowestLOD == key.getLevelOfDetail() )
//.........这里部分代码省略.........
示例12: heightFields
bool
ElevationLayerVector::populateHeightField(osg::HeightField* hf,
const TileKey& key,
const Profile* haeProfile,
ElevationInterpolation interpolation,
ProgressCallback* progress ) const
{
// heightfield must already exist.
if ( !hf )
return false;
// if the caller provided an "HAE map profile", he wants an HAE elevation grid even if
// the map profile has a vertical datum. This is the usual case when building the 3D
// terrain, for example. Construct a temporary key that doesn't have the vertical
// datum info and use that to query the elevation data.
TileKey keyToUse = key;
if ( haeProfile )
{
keyToUse = TileKey(key.getLOD(), key.getTileX(), key.getTileY(), haeProfile );
}
// Collect the valid layers for this tile.
ElevationLayerVector contenders;
ElevationLayerVector offsets;
for(ElevationLayerVector::const_reverse_iterator i = this->rbegin(); i != this->rend(); ++i)
{
ElevationLayer* layer = i->get();
if ( layer->getEnabled() && layer->getVisible() )
{
// calculate the resolution-mapped key (adjusted for tile resolution differential).
TileKey mappedKey =
keyToUse.mapResolution(hf->getNumColumns(), layer->getTileSize());
// Note: isKeyInRange tests the key, but haData tests the mapped key.
// I think that's right!
if ((layer->getTileSource() == 0L) ||
(layer->isKeyInRange(key) && layer->getTileSource()->hasData(mappedKey)))
{
if (layer->isOffset())
offsets.push_back(layer);
else
contenders.push_back(layer);
}
}
}
// nothing? bail out.
if ( contenders.empty() && offsets.empty() )
{
return false;
}
// Sample the layers into our target.
unsigned numColumns = hf->getNumColumns();
unsigned numRows = hf->getNumRows();
double xmin = key.getExtent().xMin();
double ymin = key.getExtent().yMin();
double dx = key.getExtent().width() / (double)(numColumns-1);
double dy = key.getExtent().height() / (double)(numRows-1);
// We will load the actual heightfields on demand. We might not need them all.
GeoHeightFieldVector heightFields(contenders.size());
GeoHeightFieldVector offsetFields(offsets.size());
std::vector<bool> heightFailed (contenders.size(), false);
std::vector<bool> offsetFailed(offsets.size(), false);
const SpatialReference* keySRS = keyToUse.getProfile()->getSRS();
bool realData = false;
for (unsigned c = 0; c < numColumns; ++c)
{
double x = xmin + (dx * (double)c);
for (unsigned r = 0; r < numRows; ++r)
{
double y = ymin + (dy * (double)r);
// Collect elevations from each layer as necessary.
bool resolved = false;
for(int i=0; i<contenders.size() && !resolved; ++i)
{
if ( heightFailed[i] )
continue;
GeoHeightField& layerHF = heightFields[i];
if ( !layerHF.valid() )
{
TileKey mappedKey =
keyToUse.mapResolution(hf->getNumColumns(), contenders[i]->getTileSize());
layerHF = contenders[i]->createHeightField(mappedKey, progress);
if ( !layerHF.valid() )
{
heightFailed[i] = true;
continue;
}
}
//.........这里部分代码省略.........
示例13: bestKey
bool
ElevationLayerVector::populateHeightField(osg::HeightField* hf,
const TileKey& key,
const Profile* haeProfile,
ElevationInterpolation interpolation,
ProgressCallback* progress ) const
{
//osg::Timer_t startTime = osg::Timer::instance()->tick();
// heightfield must already exist.
if ( !hf )
return false;
// if the caller provided an "HAE map profile", he wants an HAE elevation grid even if
// the map profile has a vertical datum. This is the usual case when building the 3D
// terrain, for example. Construct a temporary key that doesn't have the vertical
// datum info and use that to query the elevation data.
TileKey keyToUse = key;
if ( haeProfile )
{
keyToUse = TileKey(key.getLOD(), key.getTileX(), key.getTileY(), haeProfile );
}
// Collect the valid layers for this tile.
LayerAndKeyVector contenders;
LayerAndKeyVector offsets;
// Track the number of layers that would return fallback data.
unsigned numFallbackLayers = 0;
// Check them in reverse order since the highest priority is last.
for(ElevationLayerVector::const_reverse_iterator i = this->rbegin(); i != this->rend(); ++i)
{
ElevationLayer* layer = i->get();
if ( layer->getEnabled() && layer->getVisible() )
{
// calculate the resolution-mapped key (adjusted for tile resolution differential).
TileKey mappedKey = keyToUse.mapResolution(
hf->getNumColumns(),
layer->getTileSize() );
bool useLayer = true;
TileKey bestKey( mappedKey );
// Is there a tilesource? If not we are cache-only and cannot reject the layer.
if ( layer->getTileSource() )
{
// Check whether the non-mapped key is valid according to the user's min/max level settings:
if ( !layer->isKeyInRange(key) )
{
useLayer = false;
}
// Find the "best available" mapped key from the tile source:
else
{
if ( layer->getTileSource()->getBestAvailableTileKey(mappedKey, bestKey) )
{
// If the bestKey is not the mappedKey, this layer is providing
// fallback data (data at a lower resolution than requested)
if ( mappedKey != bestKey )
{
numFallbackLayers++;
}
}
else
{
useLayer = false;
}
}
}
if ( useLayer )
{
if ( layer->isOffset() )
{
offsets.push_back( std::make_pair(layer, bestKey) );
}
else
{
contenders.push_back( std::make_pair(layer, bestKey) );
}
}
}
}
// nothing? bail out.
if ( contenders.empty() && offsets.empty() )
{
return false;
}
// if everything is fallback data, bail out.
if ( contenders.size() + offsets.size() == numFallbackLayers )
{
return false;
}
// Sample the layers into our target.
//.........这里部分代码省略.........
示例14: bestKey
bool
ElevationLayerVector::populateHeightField(osg::HeightField* hf,
const TileKey& key,
const Profile* haeProfile,
ElevationInterpolation interpolation,
ProgressCallback* progress ) const
{
// heightfield must already exist.
if ( !hf )
return false;
// if the caller provided an "HAE map profile", he wants an HAE elevation grid even if
// the map profile has a vertical datum. This is the usual case when building the 3D
// terrain, for example. Construct a temporary key that doesn't have the vertical
// datum info and use that to query the elevation data.
TileKey keyToUse = key;
if ( haeProfile )
{
keyToUse = TileKey(key.getLOD(), key.getTileX(), key.getTileY(), haeProfile );
}
// Collect the valid layers for this tile.
LayerAndKeyVector contenders;
LayerAndKeyVector offsets;
// Track the number of layers that would return fallback data.
unsigned numFallbackLayers = 0;
// Check them in reverse order since the highest priority is last.
for(ElevationLayerVector::const_reverse_iterator i = this->rbegin(); i != this->rend(); ++i)
{
ElevationLayer* layer = i->get();
if ( layer->getEnabled() && layer->getVisible() )
{
// calculate the resolution-mapped key (adjusted for tile resolution differential).
TileKey mappedKey = keyToUse.mapResolution(
hf->getNumColumns(),
layer->getTileSize() );
bool useLayer = true;
TileKey bestKey( mappedKey );
// Is there a tilesource? If not we are cache-only and cannot reject the layer.
if ( layer->getTileSource() )
{
// Check whether the non-mapped key is valid according to the user's min/max level settings:
if ( !layer->isKeyInRange(key) )
{
useLayer = false;
}
// Find the "best available" mapped key from the tile source:
else
{
if ( layer->getTileSource()->getBestAvailableTileKey(mappedKey, bestKey) )
{
// If the bestKey is not the mappedKey, this layer is providing
// fallback data (data at a lower resolution than requested)
if ( mappedKey != bestKey )
{
numFallbackLayers++;
}
}
else
{
useLayer = false;
}
}
}
if ( useLayer )
{
if ( layer->isOffset() )
{
offsets.push_back( std::make_pair(layer, bestKey) );
}
else
{
contenders.push_back( std::make_pair(layer, bestKey) );
}
}
}
}
// nothing? bail out.
if ( contenders.empty() && offsets.empty() )
{
return false;
}
// if everything is fallback data, bail out.
if ( contenders.size() + offsets.size() == numFallbackLayers )
{
return false;
}
// Sample the layers into our target.
unsigned numColumns = hf->getNumColumns();
//.........这里部分代码省略.........