osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthFeatures/FeatureModelSource

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_MODEL_SOURCE_H
00021 #define OSGEARTHFEATURES_FEATURE_MODEL_SOURCE_H 1
00022 
00023 #include <osgEarthFeatures/Common>
00024 #include <osgEarthFeatures/FeatureSource>
00025 #include <osgEarthFeatures/FeatureGridder>
00026 #include <osgEarthFeatures/FeatureDisplayLayout>
00027 #include <osgEarthFeatures/GeometryCompiler>
00028 #include <osgEarthSymbology/Style>
00029 #include <osgEarth/ModelSource>
00030 #include <osgEarth/Map>
00031 #include <osg/Node>
00032 #include <osgDB/ReaderWriter>
00033 #include <list>
00034 
00035 namespace osgEarth { namespace Features
00036 {
00037     using namespace osgEarth;
00038     using namespace osgEarth::Symbology;
00039 
00040     class OSGEARTHFEATURES_EXPORT FeatureModelSourceOptions : public ModelSourceOptions
00041     {
00042     public: //properties
00043 
00044         optional<FeatureSourceOptions>& featureOptions() { return _featureOptions; }
00045         const optional<FeatureSourceOptions>& featureOptions() const { return _featureOptions; }
00046 
00047         osg::ref_ptr<StyleSheet>& styles() { return _styles; }
00048         const osg::ref_ptr<StyleSheet>& styles() const { return _styles; }
00049 
00051         optional<double>& maxGranularity() { return _maxGranularity_deg; }
00052         const optional<double>& maxGranularity() const { return _maxGranularity_deg; }
00053 
00055         optional<bool>& mergeGeometry() { return _mergeGeometry; }
00056         const optional<bool>& mergeGeometry() const { return _mergeGeometry; }
00057 
00059         optional<bool>& enableLighting() { return _lit; }
00060         const optional<bool>& enableLighting() const { return _lit; }
00061 
00062         optional<FeatureDisplayLayout>& levels() { return _levels; }
00063         const optional<FeatureDisplayLayout>& levels() const { return _levels; }
00064 
00065         optional<bool>& clusterCulling() { return _clusterCulling; }
00066         const optional<bool>& clusterCulling() const { return _clusterCulling; }
00067 
00068         optional<StringExpression>& featureName() { return _featureNameExpr; }
00069         const optional<StringExpression>& featureName() const { return _featureNameExpr; }
00070 
00071     public: // deprecated
00072 
00074         optional<GriddingPolicy>& gridding() { return _gridding; }
00075         const optional<GriddingPolicy>& gridding() const { return _gridding; }
00076 
00078         optional<Symbology::Geometry::Type>& geometryTypeOverride() { return _geomTypeOverride; }
00079         const optional<Symbology::Geometry::Type>& geometryTypeOverride() const { return _geomTypeOverride; }
00080 
00081     public:
00083         osg::ref_ptr<FeatureSource>& featureSource() { return _featureSource; }
00084         const osg::ref_ptr<FeatureSource>& featureSource() const { return _featureSource; }
00085 
00086     public:
00087         FeatureModelSourceOptions( const ConfigOptions& rhs =ConfigOptions() );
00088 
00089         virtual Config getConfig() const;
00090 
00091     protected:
00092         virtual void mergeConfig( const Config& conf ) {
00093             ModelSourceOptions::mergeConfig( conf );
00094             fromConfig( conf );
00095         }
00096 
00097     private:
00098         void fromConfig( const Config& conf );
00099 
00100         optional<FeatureSourceOptions>  _featureOptions;
00101         optional<FeatureDisplayLayout>  _levels;
00102         optional<StringExpression>      _featureNameExpr;
00103         optional<bool>                  _lit;
00104         optional<double>                _maxGranularity_deg;
00105         optional<bool>                  _mergeGeometry;
00106         optional<bool>                  _clusterCulling;
00107 
00108         osg::ref_ptr<StyleSheet>        _styles;
00109         osg::ref_ptr<FeatureSource>     _featureSource;
00110 
00112         optional<GriddingPolicy>        _gridding;
00113         optional<Geometry::Type>        _geomTypeOverride;
00114         
00115         //optional<Symbology::StyleSheet> _styles;
00116     };
00117 
00123     class OSGEARTHFEATURES_EXPORT FeatureNodeFactory : public osg::Referenced
00124     {
00125     public:
00130         virtual bool createOrUpdateNode(
00131             FeatureCursor*            cursor,
00132             const Style&              style,
00133             const FilterContext&      context,
00134             osg::ref_ptr<osg::Node>&  node ) =0;
00135 
00141         virtual osg::Group* getOrCreateStyleGroup(
00142             const Style& style,
00143             Session*     session ) { return new osg::Group(); }
00144     };
00145 
00146     class OSGEARTHFEATURES_EXPORT GeomFeatureNodeFactory : public FeatureNodeFactory
00147     {
00148     public:
00149         GeomFeatureNodeFactory( const GeometryCompilerOptions& options = GeometryCompilerOptions() );
00150 
00151         bool createOrUpdateNode(       
00152             FeatureCursor*            features,
00153             const Style&              style,
00154             const FilterContext&      context,
00155             osg::ref_ptr<osg::Node>&  node );
00156 
00157     public:
00158         GeometryCompilerOptions _options;
00159     };
00160 
00161 
00165     class OSGEARTHFEATURES_EXPORT FeatureModelSource : public ModelSource
00166     {
00167     public:      
00171         FeatureModelSource( const FeatureModelSourceOptions& options =FeatureModelSourceOptions() );
00172 
00173     public:
00174 
00175         //override 
00176         virtual void initialize( const std::string& referenceURI, const osgEarth::Map* map );
00177 
00178         // override
00179         virtual osg::Node* createNode( ProgressCallback* progress );
00180     
00181         virtual FeatureNodeFactory* createFeatureNodeFactory() =0;
00182 
00183 
00184     public: // properties:
00185 
00187         void setFeatureSource( FeatureSource* source );
00188 
00190         FeatureSource* getFeatureSource() { return _features.get(); }
00191 
00192         virtual const FeatureModelSourceOptions& getFeatureModelOptions() const { return _options; }
00193 
00194         const osgEarth::Map* getMap() const { return _map.get(); }
00195 
00197         virtual osg::Referenced* createBuildData() { return NULL; }     
00198 
00199     public: 
00200 
00201         // META_Object specialization:
00202         virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate
00203         virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate
00204         virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const FeatureModelSource*>(obj)!=NULL; }
00205         virtual const char* className() const { return "FeatureModelSource"; }
00206         virtual const char* libraryName() const { return "osgEarthFeatures"; }
00207 
00208     protected:
00209 
00211         virtual ~FeatureModelSource() { }
00212 
00213         osg::ref_ptr<FeatureSource>       _features;
00214         osg::ref_ptr<const Map>           _map;
00215         const FeatureModelSourceOptions   _options;
00216         osg::ref_ptr<FeatureNodeFactory>  _factory;
00217 
00218     };
00219 
00220 } } // namespace osgEarth::Features
00221 
00222 #endif // OSGEARTHFEATURES_FEATURE_SOURCE_H
00223 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines