本文整理汇总了C++中GeoImage::crop方法的典型用法代码示例。如果您正苦于以下问题:C++ GeoImage::crop方法的具体用法?C++ GeoImage::crop怎么用?C++ GeoImage::crop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoImage
的用法示例。
在下文中一共展示了GeoImage::crop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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++;
}
//.........这里部分代码省略.........
示例2: getProfile
GeoImage
ImageLayer::assembleImageFromTileSource(const TileKey& key,
ProgressCallback* progress)
{
GeoImage mosaicedImage, result;
// Scale the extent if necessary to apply an "edge buffer"
GeoExtent ext = key.getExtent();
if ( _runtimeOptions.edgeBufferRatio().isSet() )
{
double ratio = _runtimeOptions.edgeBufferRatio().get();
ext.scale(ratio, ratio);
}
// Get a set of layer tiles that intersect the requested extent.
std::vector<TileKey> intersectingKeys;
getProfile()->getIntersectingTiles( key, intersectingKeys );
if ( intersectingKeys.size() > 0 )
{
double dst_minx, dst_miny, dst_maxx, dst_maxy;
key.getExtent().getBounds(dst_minx, dst_miny, dst_maxx, dst_maxy);
// if we find at least one "real" tile in the mosaic, then the whole result tile is
// "real" (i.e. not a fallback tile)
bool retry = false;
ImageMosaic mosaic;
// keep track of failed tiles.
std::vector<TileKey> failedKeys;
for( std::vector<TileKey>::iterator k = intersectingKeys.begin(); k != intersectingKeys.end(); ++k )
{
GeoImage image = createImageFromTileSource( *k, progress );
if ( image.valid() )
{
if ( !isCoverage() )
{
ImageUtils::fixInternalFormat(image.getImage());
// Make sure all images in mosaic are based on "RGBA - unsigned byte" pixels.
// This is not the smarter choice (in some case RGB would be sufficient) but
// it ensure consistency between all images / layers.
//
// The main drawback is probably the CPU memory foot-print which would be reduced by allocating RGB instead of RGBA images.
// On GPU side, this should not change anything because of data alignements : often RGB and RGBA textures have the same memory footprint
//
if ( (image.getImage()->getDataType() != GL_UNSIGNED_BYTE)
|| (image.getImage()->getPixelFormat() != GL_RGBA) )
{
osg::ref_ptr<osg::Image> convertedImg = ImageUtils::convertToRGBA8(image.getImage());
if (convertedImg.valid())
{
image = GeoImage(convertedImg, image.getExtent());
}
}
}
mosaic.getImages().push_back( TileImage(image.getImage(), *k) );
}
else
{
// the tile source did not return a tile, so make a note of it.
failedKeys.push_back( *k );
if (progress && (progress->isCanceled() || progress->needsRetry()))
{
retry = true;
break;
}
}
}
if ( mosaic.getImages().empty() || retry )
{
// if we didn't get any data, fail.
OE_DEBUG << LC << "Couldn't create image for ImageMosaic " << std::endl;
return GeoImage::INVALID;
}
// We got at least one good tile, so go through the bad ones and try to fall back on
// lower resolution data to fill in the gaps. The entire mosaic must be populated or
// this qualifies as a bad tile.
for(std::vector<TileKey>::iterator k = failedKeys.begin(); k != failedKeys.end(); ++k)
{
GeoImage image;
for(TileKey parentKey = k->createParentKey();
parentKey.valid() && !image.valid();
parentKey = parentKey.createParentKey())
{
image = createImageFromTileSource( parentKey, progress );
if ( image.valid() )
{
GeoImage cropped;
if ( !isCoverage() )
{
ImageUtils::fixInternalFormat(image.getImage());
//.........这里部分代码省略.........