osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/ImageLayer

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 #ifndef OSGEARTH_IMAGE_TERRAIN_LAYER_H
00021 #define OSGEARTH_IMAGE_TERRAIN_LAYER_H 1
00022 
00023 #include <osgEarth/Common>
00024 #include <osgEarth/Config>
00025 #include <osgEarth/TileSource>
00026 #include <osgEarth/Profile>
00027 #include <osgEarth/Caching>
00028 #include <osgEarth/TerrainLayer>
00029 #include <osgEarth/ThreadingUtils>
00030 
00031 namespace osgEarth
00032 {
00036     class OSGEARTH_EXPORT ImageLayerOptions : public TerrainLayerOptions
00037     {
00038     public:
00040         ImageLayerOptions( const ConfigOptions& options =ConfigOptions() );
00041 
00046         ImageLayerOptions( const std::string& name, const TileSourceOptions& driverOpt =TileSourceOptions() );
00047 
00048 
00049     public: // properties
00050 
00054         optional<float>& opacity() { return _opacity; }
00055         const optional<float>& opacity() const { return _opacity; }
00056 
00060         optional<float>& minVisibleRange() { return _minRange; }
00061         const optional<float>& minVisibleRange() const { return _minRange; }
00062 
00066         optional<float>& maxVisibleRange() { return _maxRange; }
00067         const optional<float>& maxVisibleRange() const { return _maxRange; }
00068 
00072         optional<std::string>& noDataImageFilename() { return _noDataImageFilename; }
00073         const optional<std::string>& noDataImageFilename() const { return _noDataImageFilename; }
00074 
00078                 optional<osg::Vec4ub>& transparentColor() { return _transparentColor; }
00079         const optional<osg::Vec4ub>& transparentColor() const { return _transparentColor; }
00080 
00084                 optional<osg::Texture::FilterMode>& magFilter(void) {return _magFilter;}
00085                 const optional<osg::Texture::FilterMode>& magFilter(void) const {return _magFilter;}
00086 
00090                 optional<osg::Texture::FilterMode>& minFilter(void) {return _minFilter;}
00091                 const optional<osg::Texture::FilterMode>& minFilter(void) const {return _minFilter;}
00092 
00096         optional<bool>& lodBlending() { return _lodBlending; }
00097         const optional<bool>& lodBlending() const { return _lodBlending; }
00098 
00099     public:
00100         virtual Config getConfig() const;
00101         virtual void mergeConfig( const Config& conf );
00102         
00103     private:
00104         void fromConfig( const Config& conf );
00105         void setDefaults();
00106 
00107                 optional<float>  _opacity;
00108         optional<float>  _minRange;
00109         optional<float>  _maxRange;
00110                 optional<osg::Vec4ub> _transparentColor;
00111             optional<std::string> _noDataImageFilename;
00112                 optional<osg::Texture::FilterMode> _magFilter;
00113         optional<osg::Texture::FilterMode> _minFilter;
00114         optional<bool> _lodBlending;
00115     };
00116 
00117     //--------------------------------------------------------------------
00118 
00122     struct ImageLayerCallback : public TerrainLayerCallback
00123     {
00124         virtual void onOpacityChanged( class ImageLayer* layer ) { }        
00125     };
00126 
00127     typedef void (ImageLayerCallback::*ImageLayerCallbackMethodPtr)(ImageLayer* layer);
00128 
00129     typedef std::list< osg::ref_ptr<ImageLayerCallback> > ImageLayerCallbackList;
00130 
00131     //--------------------------------------------------------------------
00132 
00137     class ImageLayerTileProcessor 
00138     {
00139     public:
00140         ImageLayerTileProcessor( const ImageLayerOptions& options =ImageLayerOptions() );
00141 
00142         void init( const ImageLayerOptions& options, bool layerInTargetProfile );
00143 
00144         void process( osg::ref_ptr<osg::Image>& image ) const;
00145 
00146     private:
00147         ImageLayerOptions _options;
00148         osg::Vec4f _chromaKey;
00149         osg::ref_ptr<const osg::Image> _noDataImage;
00150         bool _layerInTargetProfile;
00151     };
00152 
00153     //--------------------------------------------------------------------
00154 
00158     class OSGEARTH_EXPORT ImageLayer : public TerrainLayer
00159     {
00160     public:
00164         ImageLayer( const ImageLayerOptions& options );
00165 
00169         ImageLayer( const std::string& name, const TileSourceOptions& driverOptions );
00170 
00174         ImageLayer( const ImageLayerOptions& options, TileSource* tileSource );
00175 
00176     public:
00180         const ImageLayerOptions& getImageLayerOptions() const { return _runtimeOptions; }
00181         virtual const TerrainLayerOptions& getTerrainLayerOptions() const { return _runtimeOptions; }
00182 
00184         void addCallback( ImageLayerCallback* cb );
00185 
00187         void removeCallback( ImageLayerCallback* cb );
00188 
00190         virtual void setTargetProfileHint( const Profile* profile );
00191 
00192     public: // runtime properties
00193 
00194         void setOpacity( float opacity );
00195         float getOpacity() const { return *_runtimeOptions.opacity(); }
00196         
00197         void disableLODBlending();
00198         bool isLODBlendingEnabled() const { return *_runtimeOptions.lodBlending(); }
00199 
00200     public: // methods
00201 
00205                 GeoImage createImage( const TileKey& key, ProgressCallback* progress = 0);
00206 
00207     protected:
00208 
00209         osg::Image* createImageWrapper(
00210             const TileKey& key,
00211             bool cacheInLayerProfile,
00212             ProgressCallback* progress );
00213 
00214         virtual void initTileSource();
00215     private:
00216         //const ImageLayerOptions _options;
00217         ImageLayerOptions       _runtimeOptions;
00218 
00219         //float _actualOpacity;        
00220         //bool  _actualLODBlending;
00221 
00222         osg::ref_ptr<TileSource::ImageOperation> _preCacheOp;
00223         
00224         void initPreCacheOp();
00225 
00226         ImageLayerCallbackList _callbacks;
00227         virtual void fireCallback( TerrainLayerCallbackMethodPtr method );
00228         virtual void fireCallback( ImageLayerCallbackMethodPtr method );
00229 
00230         void init();
00231     };
00232 
00233     typedef std::vector< osg::ref_ptr<ImageLayer> > ImageLayerVector;
00234 
00235 } // namespace osgEarth
00236 
00237 #endif // OSGEARTH_IMAGE_TERRAIN_LAYER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines