本文整理汇总了C++中GeoHeightField类的典型用法代码示例。如果您正苦于以下问题:C++ GeoHeightField类的具体用法?C++ GeoHeightField怎么用?C++ GeoHeightField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeoHeightField类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool CacheTileHandler::handleTile(const TileKey& key, const TileVisitor& tv)
{
ImageLayer* imageLayer = dynamic_cast< ImageLayer* >( _layer.get() );
ElevationLayer* elevationLayer = dynamic_cast< ElevationLayer* >( _layer.get() );
// Just call createImage or createHeightField on the layer and the it will be cached!
if (imageLayer)
{
GeoImage image = imageLayer->createImage( key );
if (image.valid())
{
return true;
}
}
else if (elevationLayer )
{
GeoHeightField hf = elevationLayer->createHeightField(key, 0L);
if (hf.valid())
{
return true;
}
}
// If we didn't produce a result but the key isn't within range then we should continue to
// traverse the children b/c a min level was set.
if (!_layer->isKeyInLegalRange(key))
{
return true;
}
return false;
}
示例2: createImage
osg::Image*
createImage( const TileKey& key, ProgressCallback* progress )
{
// Use the underlying ElevationLayer to create a heightfield and then color it.
GeoHeightField geoHF = _layer->createHeightField(key, progress);
if (geoHF.valid())
{
osg::HeightField* hf = geoHF.getHeightField();
osg::Image* image = new osg::Image();
image->allocateImage(hf->getNumColumns(),hf->getNumRows(),1, GL_RGBA, GL_UNSIGNED_BYTE);
memset(image->data(), 0, image->getImageSizeInBytes());
ImageUtils::PixelWriter writer(image);
for (unsigned int c = 0; c < hf->getNumColumns(); c++)
{
for (unsigned int r = 0; r < hf->getNumRows(); r++)
{
float v = hf->getHeight(c, r );
if (v != NO_DATA_VALUE)
{
osg::Vec4 color = _transferFunction->getColor(v);
writer(color, c, r);
}
}
}
return image;
}
return NULL;
}
示例3: handleTile
bool handleTile(const TileKey& key)
{
bool ok = false;
GeoHeightField hf = _source->createHeightField(key, 0L);
if ( hf.valid() )
ok = _dest->storeHeightField(key, hf.getHeightField(), 0L);
return ok;
}
示例4: getWorld
osg::Vec3d getWorld( const GeoHeightField& geoHF, unsigned int c, unsigned int r)
{
double x = geoHF.getExtent().xMin() + (double)c * geoHF.getXInterval();
double y = geoHF.getExtent().yMin() + (double)r * geoHF.getYInterval();
double h = geoHF.getHeightField()->getHeight(c,r);
osg::Vec3d world;
GeoPoint point(geoHF.getExtent().getSRS(), x, y, h );
point.toWorld( world );
return world;
}
示例5: if
bool CacheTileHandler::handleTile( const TileKey& key )
{
ImageLayer* imageLayer = dynamic_cast< ImageLayer* >( _layer.get() );
ElevationLayer* elevationLayer = dynamic_cast< ElevationLayer* >( _layer.get() );
// Just call createImage or createHeightField on the layer and the it will be cached!
if (imageLayer)
{
GeoImage image = imageLayer->createImage( key );
if (image.valid())
{
return true;
}
}
else if (elevationLayer )
{
GeoHeightField hf = elevationLayer->createHeightField( key );
if (hf.valid())
{
return true;
}
}
return false;
}
示例6: METRIC_SCOPED
//.........这里部分代码省略.........
ld.layer = layer;
ld.key = bestKey;
ld.index = i;
}
#ifdef ANALYZE
layerAnalysis[layer].used = true;
#endif
}
}
}
// 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();
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> heightFallback(contenders.size(), false);
std::vector<bool> heightFailed(contenders.size(), false);
std::vector<bool> offsetFailed(offsets.size(), false);
// The maximum number of heightfields to keep in this local cache
const unsigned maxHeightFields = 50;
unsigned numHeightFieldsInCache = 0;
const SpatialReference* keySRS = keyToUse.getProfile()->getSRS();
bool realData = false;
unsigned int total = numColumns * numRows;
// query resolution interval (x, y) of each sample.
osg::ref_ptr<osg::ShortArray> deltaLOD = new osg::ShortArray(total);
int nodataCount = 0;
TileKey scratchKey; // Storage if a new key needs to be constructed
bool requiresResample = true;
// If we only have a single contender layer, and the tile is the same size as the requested
// heightfield then we just use it directly and avoid having to resample it
if (contenders.size() == 1 && offsets.empty())
{
ElevationLayer* layer = contenders[0].layer.get();
TileKey& contenderKey = contenders[0].key;
GeoHeightField layerHF = layer->createHeightField(contenderKey, 0);
示例7: METRIC_SCOPED_EX
GeoHeightField
ElevationLayer::createHeightField(const TileKey& key,
ProgressCallback* progress )
{
METRIC_SCOPED_EX("ElevationLayer::createHeightField", 2,
"key", key.str().c_str(),
"name", getName().c_str());
if (getStatus().isError())
{
return GeoHeightField::INVALID;
}
// If the layer is disabled, bail out.
if ( getEnabled() == false )
{
return GeoHeightField::INVALID;
}
GeoHeightField result;
osg::ref_ptr<osg::HeightField> hf;
osg::ref_ptr<NormalMap> normalMap;
// Check the memory cache first
bool fromMemCache = false;
// cache key combines the key with the full signature (incl vdatum)
// the cache key combines the Key and the horizontal profile.
std::string cacheKey = Cache::makeCacheKey(
Stringify() << key.str() << "-" << key.getProfile()->getHorizSignature(),
"elevation");
const CachePolicy& policy = getCacheSettings()->cachePolicy().get();
if ( _memCache.valid() )
{
CacheBin* bin = _memCache->getOrCreateDefaultBin();
ReadResult cacheResult = bin->readObject(cacheKey, 0L);
if ( cacheResult.succeeded() )
{
result = GeoHeightField(
static_cast<osg::HeightField*>(cacheResult.releaseObject()),
key.getExtent());
fromMemCache = true;
}
}
if ( !result.valid() )
{
// See if there's a persistent cache.
CacheBin* cacheBin = getCacheBin( key.getProfile() );
// Can we continue? Only if either:
// a) there is a valid tile source plugin;
// b) a tile source is not expected, meaning the subclass overrides getHeightField; or
// c) we are in cache-only mode and there is a valid cache bin.
bool canContinue =
getTileSource() ||
!isTileSourceExpected() ||
(policy.isCacheOnly() && cacheBin != 0L);
if (!canContinue)
{
disable("Error: layer does not have a valid TileSource, cannot create heightfield");
return GeoHeightField::INVALID;
}
// validate the existance of a valid layer profile.
if ( !policy.isCacheOnly() && !getProfile() )
{
disable("Could not establish a valid profile.. did you set one?");
return GeoHeightField::INVALID;
}
// Now attempt to read from the cache. Since the cached data is stored in the
// map profile, we can try this first.
bool fromCache = false;
osg::ref_ptr< osg::HeightField > cachedHF;
if ( cacheBin && policy.isCacheReadable() )
{
ReadResult r = cacheBin->readObject(cacheKey, 0L);
if ( r.succeeded() )
{
bool expired = policy.isExpired(r.lastModifiedTime());
cachedHF = r.get<osg::HeightField>();
if ( cachedHF && validateHeightField(cachedHF.get()) )
{
if (!expired)
{
hf = cachedHF;
fromCache = true;
}
}
}
}
// if we're cache-only, but didn't get data from the cache, fail silently.
if ( !hf.valid() && policy.isCacheOnly() )
//.........这里部分代码省略.........
示例8: getMaxLevel
bool
ElevationQuery::getElevationImpl(const GeoPoint& point,
double& out_elevation,
double desiredResolution,
double* out_actualResolution)
{
osg::Timer_t start = osg::Timer::instance()->tick();
if ( _mapf.elevationLayers().empty() )
{
// this means there are no heightfields.
out_elevation = 0.0;
return true;
}
// tile size (resolution of elevation tiles)
unsigned tileSize = std::max(_mapf.getMapOptions().elevationTileSize().get(), 2u);
//This is the max resolution that we actually have data at this point
unsigned int bestAvailLevel = getMaxLevel( point.x(), point.y(), point.getSRS(), _mapf.getProfile());
if (desiredResolution > 0.0)
{
unsigned int desiredLevel = _mapf.getProfile()->getLevelOfDetailForHorizResolution( desiredResolution, tileSize );
if (desiredLevel < bestAvailLevel) bestAvailLevel = desiredLevel;
}
OE_DEBUG << LC << "Best available data level " << point.x() << ", " << point.y() << " = " << bestAvailLevel << std::endl;
// transform the input coords to map coords:
GeoPoint mapPoint = point;
if ( point.isValid() && !point.getSRS()->isHorizEquivalentTo( _mapf.getProfile()->getSRS() ) )
{
mapPoint = point.transform(_mapf.getProfile()->getSRS());
if ( !mapPoint.isValid() )
{
OE_WARN << LC << "Fail: coord transform failed" << std::endl;
return false;
}
}
// get the tilekey corresponding to the tile we need:
TileKey key = _mapf.getProfile()->createTileKey( mapPoint.x(), mapPoint.y(), bestAvailLevel );
if ( !key.valid() )
{
OE_WARN << LC << "Fail: coords fall outside map" << std::endl;
return false;
}
bool result = false;
while (!result)
{
GeoHeightField geoHF;
TileCache::Record record;
// Try to get the hf from the cache
if ( _cache.get( key, record ) )
{
geoHF = record.value();
}
else
{
// Create it
osg::ref_ptr<osg::HeightField> hf = new osg::HeightField();
hf->allocate( tileSize, tileSize );
// Initialize the heightfield to nodata
for (unsigned int i = 0; i < hf->getFloatArray()->size(); i++)
{
hf->getFloatArray()->at( i ) = NO_DATA_VALUE;
}
if (_mapf.populateHeightField( hf, key ) )
{
geoHF = GeoHeightField( hf.get(), key.getExtent() );
_cache.insert( key, geoHF );
}
}
if (geoHF.valid())
{
float elevation = 0.0f;
result = geoHF.getElevation( mapPoint.getSRS(), mapPoint.x(), mapPoint.y(), _mapf.getMapInfo().getElevationInterpolation(), mapPoint.getSRS(), elevation);
if (result && elevation != NO_DATA_VALUE)
{
// see what the actual resolution of the heightfield is.
if ( out_actualResolution )
*out_actualResolution = geoHF.getXInterval();
out_elevation = (double)elevation;
break;
}
else
{
result = false;
}
}
if (!result)
{
key = key.createParentKey();
if (!key.valid())
//.........这里部分代码省略.........
示例9: TileKey
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() )
//.........这里部分代码省略.........
示例10: GeoHeightField
GeoHeightField
ElevationLayer::createHeightField(const TileKey& key,
ProgressCallback* progress )
{
GeoHeightField result;
osg::ref_ptr<osg::HeightField> hf;
// If the layer is disabled, bail out.
if ( getEnabled() == false )
{
return GeoHeightField::INVALID;
}
// Check the memory cache first
if ( _memCache.valid() )
{
CacheBin* bin = _memCache->getOrCreateBin( key.getProfile()->getFullSignature() );
ReadResult cacheResult = bin->readObject(key.str() );
if ( cacheResult.succeeded() )
{
result = GeoHeightField(
static_cast<osg::HeightField*>(cacheResult.releaseObject()),
key.getExtent());
}
//_memCache->dumpStats(key.getProfile()->getFullSignature());
}
if ( !result.valid() )
{
// See if there's a persistent cache.
CacheBin* cacheBin = getCacheBin( key.getProfile() );
// validate that we have either a valid tile source, or we're cache-only.
if ( ! (getTileSource() || (isCacheOnly() && cacheBin) ) )
{
OE_WARN << LC << "Error: layer does not have a valid TileSource, cannot create heightfield" << std::endl;
_runtimeOptions.enabled() = false;
return GeoHeightField::INVALID;
}
// validate the existance of a valid layer profile.
if ( !isCacheOnly() && !getProfile() )
{
OE_WARN << LC << "Could not establish a valid profile" << std::endl;
_runtimeOptions.enabled() = false;
return GeoHeightField::INVALID;
}
// Now attempt to read from the cache. Since the cached data is stored in the
// map profile, we can try this first.
bool fromCache = false;
osg::ref_ptr< osg::HeightField > cachedHF;
if ( cacheBin && getCachePolicy().isCacheReadable() )
{
ReadResult r = cacheBin->readObject( key.str() );
if ( r.succeeded() )
{
bool expired = getCachePolicy().isExpired(r.lastModifiedTime());
cachedHF = r.get<osg::HeightField>();
if ( cachedHF && validateHeightField(cachedHF) )
{
if (!expired)
{
hf = cachedHF;
fromCache = true;
}
}
}
}
// if we're cache-only, but didn't get data from the cache, fail silently.
if ( !hf.valid() && isCacheOnly() )
{
return GeoHeightField::INVALID;
}
if ( !hf.valid() )
{
// bad tilesource? fail
if ( !getTileSource() || !getTileSource()->isOK() )
return GeoHeightField::INVALID;
if ( !isKeyInRange(key) )
return GeoHeightField::INVALID;
// build a HF from the TileSource.
hf = createHeightFieldFromTileSource( key, progress );
// validate it to make sure it's legal.
if ( hf.valid() && !validateHeightField(hf.get()) )
{
OE_WARN << LC << "Driver " << getTileSource()->getName() << " returned an illegal heightfield" << std::endl;
hf = 0L; // to fall back on cached data if possible.
}
// memory cache first:
if ( hf && _memCache.valid() )
{
//.........这里部分代码省略.........
示例11: TileKey
//.........这里部分代码省略.........
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();
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);
// The maximum number of heightfields to keep in this local cache
unsigned int maxHeightFields = 50;
unsigned numHeightFieldsInCache = 0;
//double fallBackTime = 0;
const SpatialReference* keySRS = keyToUse.getProfile()->getSRS();
bool realData = false;
//unsigned int numFallback = 0;
unsigned int total = numColumns * numRows;
unsigned int completed = 0;
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)
{
示例12: start
//.........这里部分代码省略.........
// tile size (resolution of elevation tiles)
unsigned tileSize = std::max(_mapf.getMapOptions().elevationTileSize().get(), 2u);
//This is the max resolution that we actually have data at this point
unsigned int bestAvailLevel = getMaxLevel( point.x(), point.y(), point.getSRS(), _mapf.getProfile());
if (desiredResolution > 0.0)
{
unsigned int desiredLevel = _mapf.getProfile()->getLevelOfDetailForHorizResolution( desiredResolution, tileSize );
if (desiredLevel < bestAvailLevel) bestAvailLevel = desiredLevel;
}
OE_DEBUG << LC << "Best available data level " << point.x() << ", " << point.y() << " = " << bestAvailLevel << std::endl;
// transform the input coords to map coords:
GeoPoint mapPoint = point;
if ( point.isValid() && !point.getSRS()->isHorizEquivalentTo( _mapf.getProfile()->getSRS() ) )
{
mapPoint = point.transform(_mapf.getProfile()->getSRS());
if ( !mapPoint.isValid() )
{
OE_WARN << LC << "Fail: coord transform failed" << std::endl;
return false;
}
}
// get the tilekey corresponding to the tile we need:
TileKey key = _mapf.getProfile()->createTileKey( mapPoint.x(), mapPoint.y(), bestAvailLevel );
if ( !key.valid() )
{
OE_WARN << LC << "Fail: coords fall outside map" << std::endl;
return false;
}
bool result = false;
while (!result)
{
GeoHeightField geoHF;
TileCache::Record record;
// Try to get the hf from the cache
if ( _cache.get( key, record ) )
{
geoHF = record.value();
}
else
{
// Create it
osg::ref_ptr<osg::HeightField> hf = new osg::HeightField();
hf->allocate( tileSize, tileSize );
// Initialize the heightfield to nodata
for (unsigned int i = 0; i < hf->getFloatArray()->size(); i++)
{
hf->getFloatArray()->at( i ) = NO_DATA_VALUE;
}
if (_mapf.populateHeightField(hf, key, false))
{
geoHF = GeoHeightField( hf.get(), key.getExtent() );
_cache.insert( key, geoHF );
}
}
if (geoHF.valid())
{
float elevation = 0.0f;
result = geoHF.getElevation( mapPoint.getSRS(), mapPoint.x(), mapPoint.y(), _mapf.getMapInfo().getElevationInterpolation(), mapPoint.getSRS(), elevation);
if (result && elevation != NO_DATA_VALUE)
{
// see what the actual resolution of the heightfield is.
if ( out_actualResolution )
*out_actualResolution = geoHF.getXInterval();
out_elevation = (double)elevation;
break;
}
else
{
result = false;
}
}
if (!result)
{
key = key.createParentKey();
if (!key.valid())
{
break;
}
}
}
osg::Timer_t end = osg::Timer::instance()->tick();
_queries++;
_totalTime += osg::Timer::instance()->delta_s( begin, end );
return result;
}