osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/ImageMosaic.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #include <osgEarth/ImageMosaic>
00021 #include <osgEarth/ImageUtils>
00022 #include <osgEarth/HeightFieldUtils>
00023 #include <osg/Notify>
00024 #include <osg/Timer>
00025 #include <osg/io_utils>
00026 
00027 using namespace osgEarth;
00028 
00029 
00030 /***************************************************************************/
00031 
00032 TileImage::TileImage(osg::Image* image, const TileKey& key)
00033 {
00034     _image = image;
00035     key.getExtent().getBounds(_minX, _minY, _maxX, _maxY);
00036     key.getTileXY(_tileX, _tileY);
00037 }
00038 
00039 
00040 /***************************************************************************/
00041 
00042 ImageMosaic::ImageMosaic()
00043 {
00044 }
00045 
00046 ImageMosaic::~ImageMosaic()
00047 {
00048 }
00049 
00050 void ImageMosaic::getExtents(double &minX, double &minY, double &maxX, double &maxY)
00051 {
00052     minX = DBL_MAX;
00053     maxX = -DBL_MAX;
00054     minY = DBL_MAX;
00055     maxY = -DBL_MAX;
00056 
00057     for (TileImageList::iterator i = _images.begin(); i != _images.end(); ++i)
00058     {
00059         minX = osg::minimum(i->_minX, minX);
00060         minY = osg::minimum(i->_minY, minY);
00061         maxX = osg::maximum(i->_maxX, maxX);
00062         maxY = osg::maximum(i->_maxY, maxY);
00063     }
00064 }
00065 
00066 osg::Image*
00067 ImageMosaic::createImage()
00068 {
00069     if (_images.size() == 0)
00070     {
00071         OE_NOTICE << "ImageMosaic has no images..." << std::endl;
00072         return 0;
00073     }
00074 
00075     unsigned int tileWidth = _images[0]._image->s();
00076     unsigned int tileHeight = _images[0]._image->t();
00077 
00078     //OE_NOTICE << "TileDim " << tileWidth << ", " << tileHeight << std::endl;
00079 
00080     unsigned int minTileX = _images[0]._tileX;
00081     unsigned int minTileY = _images[0]._tileY;
00082     unsigned int maxTileX = _images[0]._tileX;
00083     unsigned int maxTileY = _images[0]._tileY;
00084 
00085     //Compute the tile size.
00086     for (TileImageList::iterator i = _images.begin(); i != _images.end(); ++i)
00087     {
00088         if (i->_tileX < minTileX) minTileX = i->_tileX;
00089         if (i->_tileY < minTileY) minTileY = i->_tileY;
00090 
00091         if (i->_tileX > maxTileX) maxTileX = i->_tileX;
00092         if (i->_tileY > maxTileY) maxTileY = i->_tileY;
00093     }
00094 
00095     unsigned int tilesWide = maxTileX - minTileX + 1;
00096     unsigned int tilesHigh = maxTileY - minTileY + 1;
00097 
00098     unsigned int pixelsWide = tilesWide * tileWidth;
00099     unsigned int pixelsHigh = tilesHigh * tileHeight;
00100 
00101     osg::ref_ptr<osg::Image> image = new osg::Image;
00102     image->allocateImage(pixelsWide, pixelsHigh, 1, _images[0]._image->getPixelFormat(), _images[0]._image->getDataType());
00103     image->setInternalTextureFormat(_images[0]._image->getInternalTextureFormat()); 
00104 
00105     //Composite the incoming images into the master image
00106     for (TileImageList::iterator i = _images.begin(); i != _images.end(); ++i)
00107     {
00108         //Determine the indices in the master image for this image
00109         int dstX = (i->_tileX - minTileX) * tileWidth;
00110         int dstY = (maxTileY - i->_tileY) * tileHeight;
00111         ImageUtils::copyAsSubImage(i->getImage(), image.get(), dstX, dstY);
00112     }
00113 
00114     return image.release();
00115 }
00116 
00117 /***************************************************************************/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines