|
osgEarth 2.1.1
|
Collaboration diagram for osgEarth::GeoImage:Public Member Functions | |
| GeoImage () | |
| GeoImage (osg::Image *image, const GeoExtent &extent) | |
| bool | valid () const |
| osg::Image * | getImage () const |
| const GeoExtent & | getExtent () const |
| const SpatialReference * | getSRS () const |
| GeoImage | crop (const GeoExtent &extent, bool exact=false, unsigned int width=0, unsigned int height=0) const |
| GeoImage | reproject (const SpatialReference *to_srs, const GeoExtent *to_extent=0, unsigned int width=0, unsigned int height=0) const |
| GeoImage | addTransparentBorder (bool leftBorder=true, bool rightBorder=true, bool bottomBorder=true, bool topBorder=true) |
| osg::Image * | takeImage () |
| double | getUnitsPerPixel () const |
Static Public Attributes | |
| static GeoImage | INVALID |
Private Attributes | |
| osg::ref_ptr< osg::Image > | _image |
| GeoExtent | _extent |
A georeferenced image; i.e. an osg::Image and an associated GeoExtent with SRS.
| GeoImage::GeoImage | ( | ) |
Construct an empty (invalid) geoimage.
Definition at line 483 of file GeoData.cpp.
: _image(0L), _extent( GeoExtent::INVALID ) { //nop }
Here is the caller graph for this function:| GeoImage::GeoImage | ( | osg::Image * | image, |
| const GeoExtent & | extent | ||
| ) |
Constructs a new goereferenced image.
Definition at line 491 of file GeoData.cpp.
| GeoImage GeoImage::addTransparentBorder | ( | bool | leftBorder = true, |
| bool | rightBorder = true, |
||
| bool | bottomBorder = true, |
||
| bool | topBorder = true |
||
| ) |
Adds a one-pixel transparent border around an image.
Definition at line 575 of file GeoData.cpp.
{
unsigned int buffer = 1;
unsigned int newS = _image->s();
if (leftBorder) newS += buffer;
if (rightBorder) newS += buffer;
unsigned int newT = _image->t();
if (topBorder) newT += buffer;
if (bottomBorder) newT += buffer;
osg::Image* newImage = new osg::Image;
newImage->allocateImage(newS, newT, _image->r(), _image->getPixelFormat(), _image->getDataType(), _image->getPacking());
newImage->setInternalTextureFormat(_image->getInternalTextureFormat());
memset(newImage->data(), 0, newImage->getImageSizeInBytes());
unsigned startC = leftBorder ? buffer : 0;
unsigned startR = bottomBorder ? buffer : 0;
ImageUtils::copyAsSubImage(_image.get(), newImage, startC, startR );
//double upp = getUnitsPerPixel();
double uppw = _extent.width() / (double)_image->s();
double upph = _extent.height() / (double)_image->t();
double xmin = leftBorder ? _extent.xMin() - buffer * uppw : _extent.xMin();
double ymin = bottomBorder ? _extent.yMin() - buffer * upph : _extent.yMin();
double xmax = rightBorder ? _extent.xMax() + buffer * uppw : _extent.xMax();
double ymax = topBorder ? _extent.yMax() + buffer * upph : _extent.yMax();
return GeoImage(newImage, GeoExtent(getSRS(), xmin, ymin, xmax, ymax));
}
Here is the call graph for this function:
Here is the caller graph for this function:| GeoImage GeoImage::crop | ( | const GeoExtent & | extent, |
| bool | exact = false, |
||
| unsigned int | width = 0, |
||
| unsigned int | height = 0 |
||
| ) | const |
Crops the image to a new geospatial extent.
| extent | New extent to which to crop the image. |
| exact | If "exact" is true, the output image will have exactly the extents requested; this process may require resampling and will therefore be more expensive. If "exact" is false, we do a simple crop of the image that is rounded to the nearest pixel. The resulting extent will be close but usually not exactly what was requested - however, this method is faster. |
| width,height | New pixel size for the output image. By default, the method will automatically calculate a new pixel size. |
Definition at line 521 of file GeoData.cpp.
{
//Check for equivalence
if ( extent.getSRS()->isEquivalentTo( getSRS() ) )
{
//If we want an exact crop or they want to specify the output size of the image, use GDAL
if (exact || width != 0 || height != 0 )
{
OE_DEBUG << "[osgEarth::GeoImage::crop] Performing exact crop" << std::endl;
//Suggest an output image size
if (width == 0 || height == 0)
{
double xRes = (getExtent().xMax() - getExtent().xMin()) / (double)_image->s();
double yRes = (getExtent().yMax() - getExtent().yMin()) / (double)_image->t();
width = osg::maximum(1u, (unsigned int)((extent.xMax() - extent.xMin()) / xRes));
height = osg::maximum(1u, (unsigned int)((extent.yMax() - extent.yMin()) / yRes));
OE_DEBUG << "[osgEarth::GeoImage::crop] Computed output image size " << width << "x" << height << std::endl;
}
//Note: Passing in the current SRS simply forces GDAL to not do any warping
return reproject( getSRS(), &extent, width, height);
}
else
{
OE_DEBUG << "[osgEarth::GeoImage::crop] Performing non-exact crop " << std::endl;
//If an exact crop is not desired, we can use the faster image cropping code that does no resampling.
double destXMin = extent.xMin();
double destYMin = extent.yMin();
double destXMax = extent.xMax();
double destYMax = extent.yMax();
osg::Image* new_image = ImageUtils::cropImage(
_image.get(),
_extent.xMin(), _extent.yMin(), _extent.xMax(), _extent.yMax(),
destXMin, destYMin, destXMax, destYMax );
//The destination extents may be different than the input extents due to not being able to crop along pixel boundaries.
return new_image?
GeoImage( new_image, GeoExtent( getSRS(), destXMin, destYMin, destXMax, destYMax ) ) :
GeoImage::INVALID;
}
}
else
{
//TODO: just reproject the image before cropping
OE_NOTICE << "[osgEarth::GeoImage::crop] Cropping extent does not have equivalent SpatialReference" << std::endl;
return GeoImage::INVALID;
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| const GeoExtent & GeoImage::getExtent | ( | ) | const |
Gets the geospatial extent of the image.
Definition at line 509 of file GeoData.cpp.
{
return _extent;
}
Here is the caller graph for this function:| osg::Image * GeoImage::getImage | ( | ) | const |
Gets a pointer to the underlying OSG image.
Definition at line 499 of file GeoData.cpp.
{
return _image.get();
}
Here is the caller graph for this function:| const SpatialReference * GeoImage::getSRS | ( | ) | const |
Shortcut to get the spatial reference system describing the projection of the image.
Definition at line 504 of file GeoData.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:| double GeoImage::getUnitsPerPixel | ( | ) | const |
Gets the units per pixel of this geoimage
Definition at line 514 of file GeoData.cpp.
{
double uppw = _extent.width() / (double)_image->s();
double upph = _extent.height() / (double)_image->t();
return (uppw + upph) / 2.0;
}
Here is the call graph for this function:
Here is the caller graph for this function:| GeoImage GeoImage::reproject | ( | const SpatialReference * | to_srs, |
| const GeoExtent * | to_extent = 0, |
||
| unsigned int | width = 0, |
||
| unsigned int | height = 0 |
||
| ) | const |
Warps the image into a new spatial reference system.
| to_srs | SRS into which to warp the image. |
| to_extent | Supply this extent if you wish to warp AND crop the image in one step. This is faster than calling reproject() and then crop(). |
| width,height | New pixel size for the output image. Be default, the method will automatically calculate a new pixel size. |
Definition at line 930 of file GeoData.cpp.
{
GeoExtent destExtent;
if (to_extent)
{
destExtent = *to_extent;
}
else
{
destExtent = getExtent().transform(to_srs);
}
osg::Image* resultImage = 0L;
if ( getSRS()->isUserDefined() || to_srs->isUserDefined() ||
( getSRS()->isMercator() && to_srs->isGeographic() ) ||
( getSRS()->isGeographic() && to_srs->isMercator() ) )
{
// if either of the SRS is a custom projection, we have to do a manual reprojection since
// GDAL will not recognize the SRS.
resultImage = manualReproject(getImage(), getExtent(), *to_extent, width, height);
}
else
{
// otherwise use GDAL.
resultImage = reprojectImage(getImage(),
getSRS()->getWKT(),
getExtent().xMin(), getExtent().yMin(), getExtent().xMax(), getExtent().yMax(),
to_srs->getWKT(),
destExtent.xMin(), destExtent.yMin(), destExtent.xMax(), destExtent.yMax(),
width, height);
}
return GeoImage(resultImage, destExtent);
}
Here is the call graph for this function:
Here is the caller graph for this function:| osg::Image * GeoImage::takeImage | ( | ) |
Returns the underlying OSG image and releases the reference pointer.
Definition at line 966 of file GeoData.cpp.
{
return _image.release();
}
Here is the caller graph for this function:| bool osgEarth::GeoImage::valid | ( | ) | const [inline] |
GeoExtent osgEarth::GeoImage::_extent [private] |
osg::ref_ptr<osg::Image> osgEarth::GeoImage::_image [private] |
GeoImage GeoImage::INVALID [static] |
1.7.3