osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthFeatures/FeatureTileSource

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 OSGEARTHFEATURES_FEATURE_TILE_SOURCE_H
00021 #define OSGEARTHFEATURES_FEATURE_TILE_SOURCE_H 1
00022 
00023 #include <osgEarthFeatures/Common>
00024 #include <osgEarthFeatures/FeatureSource>
00025 #include <osgEarthSymbology/Style>
00026 #include <osgEarth/TileSource>
00027 #include <osgEarth/Map>
00028 #include <osg/Node>
00029 #include <osgDB/ReaderWriter>
00030 #include <list>
00031 
00032 namespace osgEarth { namespace Features
00033 {
00034     using namespace osgEarth;
00035     using namespace osgEarth::Symbology;
00036 
00037     class OSGEARTHFEATURES_EXPORT FeatureTileSourceOptions : public TileSourceOptions
00038     {
00039     public: // serializable properties
00040 
00041         optional<FeatureSourceOptions>& featureOptions() { return _featureOptions; }
00042         const optional<FeatureSourceOptions>& featureOptions() const { return _featureOptions; }
00043 
00044         osg::ref_ptr<StyleSheet>& styles() { return _styles; }
00045         const osg::ref_ptr<StyleSheet>& styles() const { return _styles; }
00046 
00047         //TODO: deprecate in favor of convert filter
00048         optional<Geometry::Type>& geometryTypeOverride() { return _geomTypeOverride; }
00049         const optional<Geometry::Type>& geometryTypeOverride() const { return _geomTypeOverride; }
00050 
00051     public:
00053         osg::ref_ptr<FeatureSource>& featureSource() { return _featureSource; }
00054         const osg::ref_ptr<FeatureSource>& featureSource() const { return _featureSource; }
00055 
00056         FeatureTileSourceOptions( const ConfigOptions& rhs =ConfigOptions() );
00057 
00058     public:
00059         virtual Config getConfig() const;
00060 
00061     protected:
00062         virtual void mergeConfig( const Config& conf );
00063 
00064         optional<FeatureSourceOptions> _featureOptions;
00065         osg::ref_ptr<StyleSheet>       _styles;
00066         optional<Geometry::Type>       _geomTypeOverride;
00067         osg::ref_ptr<FeatureSource>    _featureSource;
00068 
00069     private:
00070         void fromConfig( const Config& conf );
00071     };
00072 
00073 
00078     class OSGEARTHFEATURES_EXPORT FeatureTileSource : public TileSource
00079     {
00080     public:      
00084         FeatureTileSource( const TileSourceOptions& options =TileSourceOptions() );
00085 
00086         //override
00087         virtual void initialize( const std::string& referenceURI, const Profile* overrideProfile = NULL);
00088 
00089         //override
00090         virtual osg::Image* createImage( const TileKey& key, ProgressCallback* progress );
00091 
00092     public: // properties:
00093 
00095         FeatureSource* getFeatureSource() { return _features.get(); }
00096 
00100         void setFeatureSource( FeatureSource* source );
00101 
00102     protected:
00103 
00105         virtual osg::Referenced* createBuildData() {
00106             return NULL; }     
00107 
00122         virtual bool renderFeaturesForStyle(
00123             const Style&       style,
00124             const FeatureList& features,
00125             osg::Referenced*   buildData,
00126             const GeoExtent&   imageExtent,
00127             osg::Image*        out_image ) { return false; }            
00128             
00133         virtual bool preProcess(
00134             osg::Image* image,
00135             osg::Referenced* buildData ) { return true; }
00136             
00141         virtual bool postProcess(
00142             osg::Image* image,
00143             osg::Referenced* buildData ) { return true; }
00144 
00145     public:
00146 
00147         // META_Object specialization:
00148         virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate
00149         virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate
00150         virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const FeatureTileSource*>(obj)!=NULL; }
00151         virtual const char* className() const { return "FeatureTileSource"; }
00152         virtual const char* libraryName() const { return "osgEarthFeatures"; }
00153 
00154     protected:
00155 
00157         virtual ~FeatureTileSource() { }
00158 
00159         osg::ref_ptr<FeatureSource> _features;
00160         const FeatureTileSourceOptions _options;
00161         //osg::ref_ptr<const FeatureTileSourceOptions> _options;
00162         osg::ref_ptr<const osgEarth::Map> _map;
00163         bool _initialized;
00164         
00165         bool queryAndRenderFeaturesForStyle(
00166             const Style&     style,
00167             const Query&     query,
00168             osg::Referenced* data,
00169             const GeoExtent& imageExtent,
00170             osg::Image*      out_image );
00171     };
00172 
00173     } } // namespace osgEarth::Features
00174 
00175 #endif // OSGEARTHFEATURES_FEATURE_TILE_SOURCE_H
00176 
00177 
00178 
00179 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines