本文整理汇总了C++中GeoExtent::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ GeoExtent::scale方法的具体用法?C++ GeoExtent::scale怎么用?C++ GeoExtent::scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoExtent
的用法示例。
在下文中一共展示了GeoExtent::scale方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
//.........这里部分代码省略.........
示例2: renderFeaturesForStyle
//.........这里部分代码省略.........
if ( Units::canConvert(strokeUnits, featureUnits) )
{
// linear to linear, no problem
lineWidth = strokeUnits.convertTo( featureUnits, lineWidth );
}
else if ( strokeUnits.isLinear() && featureUnits.isAngular() )
{
// linear to angular? approximate degrees per meter at the
// latitude of the tile's centroid.
lineWidth = masterLine->stroke()->widthUnits()->convertTo(Units::METERS, lineWidth);
double circ = featureSRS->getEllipsoid()->getRadiusEquator() * 2.0 * osg::PI;
double x, y;
context.profile()->getExtent().getCentroid(x, y);
double radians = (lineWidth/circ) * cos(osg::DegreesToRadians(y));
lineWidth = osg::RadiansToDegrees(radians);
}
}
// enfore a minimum width of one pixel.
float minPixels = masterLine->stroke()->minPixels().getOrUse( 1.0f );
lineWidth = osg::clampAbove(lineWidth, pixelWidth*minPixels);
}
else // pixels
{
lineWidth *= pixelWidth;
}
}
}
buffer.distance() = lineWidth * 0.5; // since the distance is for one side
buffer.push( lines, context );
}
// Transform the features into the map's SRS:
TransformFilter xform( imageExtent.getSRS() );
xform.setLocalizeCoordinates( false );
FilterContext polysContext = xform.push( polygons, context );
FilterContext linesContext = xform.push( lines, context );
// set up the AGG renderer:
agg::rendering_buffer rbuf( image->data(), image->s(), image->t(), image->s()*4 );
// Create the renderer and the rasterizer
agg::renderer<agg::span_abgr32> ren(rbuf);
agg::rasterizer ras;
// Setup the rasterizer
ras.gamma(1.3);
ras.filling_rule(agg::fill_even_odd);
// construct an extent for cropping the geometry to our tile.
// extend just outside the actual extents so we don't get edge artifacts:
GeoExtent cropExtent = GeoExtent(imageExtent);
cropExtent.scale(1.1, 1.1);
osg::ref_ptr<Symbology::Polygon> cropPoly = new Symbology::Polygon( 4 );
cropPoly->push_back( osg::Vec3d( cropExtent.xMin(), cropExtent.yMin(), 0 ));
cropPoly->push_back( osg::Vec3d( cropExtent.xMax(), cropExtent.yMin(), 0 ));
cropPoly->push_back( osg::Vec3d( cropExtent.xMax(), cropExtent.yMax(), 0 ));
cropPoly->push_back( osg::Vec3d( cropExtent.xMin(), cropExtent.yMax(), 0 ));
// render the polygons
for(FeatureList::iterator i = polygons.begin(); i != polygons.end(); i++)
{
Feature* feature = i->get();
Geometry* geometry = feature->getGeometry();
osg::ref_ptr<Geometry> croppedGeometry;
if ( geometry->crop( cropPoly.get(), croppedGeometry ) )
{
const PolygonSymbol* poly =
feature->style().isSet() && feature->style()->has<PolygonSymbol>() ? feature->style()->get<PolygonSymbol>() :
masterPoly;
const osg::Vec4 color = poly ? static_cast<osg::Vec4>(poly->fill()->color()) : osg::Vec4(1,1,1,1);
rasterize(croppedGeometry.get(), color, frame, ras, ren);
}
}
// render the lines
for(FeatureList::iterator i = lines.begin(); i != lines.end(); i++)
{
Feature* feature = i->get();
Geometry* geometry = feature->getGeometry();
osg::ref_ptr<Geometry> croppedGeometry;
if ( geometry->crop( cropPoly.get(), croppedGeometry ) )
{
const LineSymbol* line =
feature->style().isSet() && feature->style()->has<LineSymbol>() ? feature->style()->get<LineSymbol>() :
masterLine;
const osg::Vec4 color = line ? static_cast<osg::Vec4>(line->stroke()->color()) : osg::Vec4(1,1,1,1);
rasterize(croppedGeometry.get(), color, frame, ras, ren);
}
}
return true;
}
示例3: getProfile
GeoImage
ImageLayer::assembleImageFromTileSource(const TileKey& key,
ProgressCallback* progress,
bool& out_isFallback)
{
GeoImage mosaicedImage, result;
out_isFallback = false;
// 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( ext, 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 foundAtLeastOneRealTile = false;
bool retry = false;
ImageMosaic mosaic;
for( std::vector<TileKey>::iterator k = intersectingKeys.begin(); k != intersectingKeys.end(); ++k )
{
double minX, minY, maxX, maxY;
k->getExtent().getBounds(minX, minY, maxX, maxY);
bool isFallback = false;
GeoImage image = createImageFromTileSource( *k, progress, true, isFallback );
if ( image.valid() )
{
// make sure the image is RGBA.
// (TODO: investigate whether we still need this -gw 6/25/2012)
if (image.getImage()->getPixelFormat() != GL_RGBA || image.getImage()->getDataType() != GL_UNSIGNED_BYTE || image.getImage()->getInternalTextureFormat() != GL_RGBA8 )
{
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) );
if ( !isFallback )
foundAtLeastOneRealTile = true;
}
else
{
// the tile source did not return a tile, so make a note of it.
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;
}
// all set. Mosaic all the images together.
double rxmin, rymin, rxmax, rymax;
mosaic.getExtents( rxmin, rymin, rxmax, rymax );
mosaicedImage = GeoImage(
mosaic.createImage(),
GeoExtent( getProfile()->getSRS(), rxmin, rymin, rxmax, rymax ) );
if ( !foundAtLeastOneRealTile )
out_isFallback = true;
}
else
{
OE_DEBUG << LC << "assembleImageFromTileSource: no intersections (" << key.str() << ")" << std::endl;
}
// Final step: transform the mosaic into the requesting key's extent.
if ( mosaicedImage.valid() )
{
// GeoImage::reproject() will automatically crop the image to the correct extents.
// so there is no need to crop after reprojection. Also note that if the SRS's are the
// same (even though extents are different), then this operation is technically not a
// reprojection but merely a resampling.
result = mosaicedImage.reproject(
key.getProfile()->getSRS(),
//.........这里部分代码省略.........
示例4: renderFeaturesForStyle
//.........这里部分代码省略.........
buffer.capStyle() = masterLine->stroke()->lineCap().value();
if ( masterLine->stroke()->width().isSet() )
lineWidth = masterLine->stroke()->width().value();
}
// "relative line size" means that the line width is expressed in (approx) pixels
// rather than in map units
if ( _options.relativeLineSize() == true )
buffer.distance() = xres * lineWidth;
else
buffer.distance() = lineWidth;
buffer.push( linesToBuffer, context );
}
// First, transform the features into the map's SRS:
TransformFilter xform( imageExtent.getSRS() );
xform.setLocalizeCoordinates( false );
context = xform.push( features, context );
// set up the AGG renderer:
agg::rendering_buffer rbuf( image->data(), image->s(), image->t(), image->s()*4 );
// Create the renderer and the rasterizer
agg::renderer<agg::span_abgr32> ren(rbuf);
agg::rasterizer ras;
// Setup the rasterizer
ras.gamma(1.3);
ras.filling_rule(agg::fill_even_odd);
GeoExtent cropExtent = GeoExtent(imageExtent);
cropExtent.scale(1.1, 1.1);
osg::ref_ptr<Symbology::Polygon> cropPoly = new Symbology::Polygon( 4 );
cropPoly->push_back( osg::Vec3d( cropExtent.xMin(), cropExtent.yMin(), 0 ));
cropPoly->push_back( osg::Vec3d( cropExtent.xMax(), cropExtent.yMin(), 0 ));
cropPoly->push_back( osg::Vec3d( cropExtent.xMax(), cropExtent.yMax(), 0 ));
cropPoly->push_back( osg::Vec3d( cropExtent.xMin(), cropExtent.yMax(), 0 ));
double lineWidth = 1.0;
if ( masterLine )
lineWidth = (double)masterLine->stroke()->width().value();
osg::Vec4 color = osg::Vec4(1, 1, 1, 1);
if ( masterLine )
color = masterLine->stroke()->color();
// render the features
for(FeatureList::iterator i = features.begin(); i != features.end(); i++)
{
Feature* feature = i->get();
//bool first = bd->_pass == 0 && i == features.begin();
Geometry* geometry = feature->getGeometry();
osg::ref_ptr< Geometry > croppedGeometry;
if ( ! geometry->crop( cropPoly.get(), croppedGeometry ) )
continue;
// set up a default color:
osg::Vec4 c = color;
unsigned int a = (unsigned int)(127+(c.a()*255)/2); // scale alpha up
agg::rgba8 fgColor( (unsigned int)(c.r()*255), (unsigned int)(c.g()*255), (unsigned int)(c.b()*255), a );