osgEarth 2.1.1
Public Member Functions | Private Attributes

OSGTileSource Class Reference

Inheritance diagram for OSGTileSource:
Collaboration diagram for OSGTileSource:

List of all members.

Public Member Functions

 OSGTileSource (const TileSourceOptions &options)
void initialize (const std::string &referenceURI, const Profile *overrideProfile)
unsigned int getMaxDataLevel () const
osg::Image * createImage (const TileKey &key, ProgressCallback *progress)
std::string getExtension () const

Private Attributes

std::string _extension
int _maxDataLevel
GeoImage _image
const OSGOptions _options

Detailed Description

Definition at line 54 of file OSGTileSource.cpp.


Constructor & Destructor Documentation

OSGTileSource::OSGTileSource ( const TileSourceOptions options) [inline]

Definition at line 57 of file OSGTileSource.cpp.

                                                      :
      TileSource( options ),      
      _maxDataLevel( 21 ),
      _options( options )
    {
        //nop
    }

Member Function Documentation

osg::Image* OSGTileSource::createImage ( const TileKey key,
ProgressCallback progress 
) [inline, virtual]

Creates an image for the given TileKey. The returned object is new and is the responsibility of the caller.

Implements osgEarth::TileSource.

Definition at line 133 of file OSGTileSource.cpp.

    {
        if ( !_image.valid() || key.getLevelOfDetail() > getMaxDataLevel() )
            return NULL;

        GeoImage cropped = _image.crop( key.getExtent(), true, getPixelsPerTile(), getPixelsPerTile() );
        return cropped.valid() ? cropped.takeImage() : 0L;
    }

Here is the call graph for this function:

std::string OSGTileSource::getExtension ( ) const [inline, virtual]

Gets the preferred extension for this TileSource

Reimplemented from osgEarth::TileSource.

Definition at line 143 of file OSGTileSource.cpp.

    {
        return _extension;
    }
unsigned int OSGTileSource::getMaxDataLevel ( ) const [inline, virtual]

Gets the maximum level of detail available from the tile source. Unlike getMaxLevel(), which reports the maximum level at which to use this tile source in a Map, this method reports the maximum level for which the tile source is able to return data.

Reimplemented from osgEarth::TileSource.

Definition at line 127 of file OSGTileSource.cpp.

    {
        return _maxDataLevel;
    }
void OSGTileSource::initialize ( const std::string &  referenceURI,
const Profile overrideProfile 
) [inline, virtual]

Initialize the TileSource. The profile should be computed and set here using setProfile()

Implements osgEarth::TileSource.

Definition at line 65 of file OSGTileSource.cpp.

    {
        if ( !overrideProfile )
        {
            OE_WARN << LC << "An explicit profile definition is required by the OSG driver." << std::endl;
            return;
        }

        setProfile( overrideProfile );

        osg::ref_ptr<osg::Image> image;

        URI url = _options.url().value();
        if ( !url.empty() )
        {
            url = URI( url.full(), referenceURI ); // obselete?
            HTTPClient::ResultCode code = HTTPClient::readImageFile( url.full(), image );
            if ( code != HTTPClient::RESULT_OK )
            {
                OE_WARN << LC << "Failed to load data from \"" << url.full() << "\", because: " << 
                    HTTPClient::getResultCodeString(code) << std::endl;
            }
        }

        if ( !image.valid() )
            OE_WARN << LC << "Faild to load data from \"" << url.full() << "\"" << std::endl;

        // calculate and store the maximum LOD for which to return data
        if ( image.valid() )
        {
            int minSpan = osg::minimum( image->s(), image->t() );
            int tileSize = _options.tileSize().value();
            _maxDataLevel = (int)LOG2((minSpan/tileSize)+1);
            //OE_NOTICE << "[osgEarth::OSG driver] minSpan=" << minSpan << ", _tileSize=" << tileSize << ", maxDataLevel = " << _maxDataLevel << std::endl;

            
            getDataExtents().push_back( DataExtent(overrideProfile->getExtent(), 0, _maxDataLevel) );

            bool computeAlpha =
                (_options.convertLuminanceToRGBA() == true && image->getPixelFormat() == GL_LUMINANCE) ||
                (_options.addAlpha() == true && !ImageUtils::hasAlphaChannel( image.get() ) );

            if ( computeAlpha )
            {
                image = makeRGBAandComputeAlpha( image.get() );
            }
            else if ( ImageUtils::hasAlphaChannel( image.get() ))
            {
                image = ImageUtils::convertToRGBA8( image.get() );
            }
            else
            {
                image = ImageUtils::convertToRGB8( image.get() );
            }

            _image = GeoImage( image.get(), getProfile()->getExtent() );
        }

        _extension = osgDB::getFileExtension( url.full() );
    }

Here is the call graph for this function:


Member Data Documentation

std::string OSGTileSource::_extension [private]

Definition at line 149 of file OSGTileSource.cpp.

Definition at line 151 of file OSGTileSource.cpp.

Definition at line 150 of file OSGTileSource.cpp.

Reimplemented from osgEarth::TileSource.

Definition at line 152 of file OSGTileSource.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines