osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthFeatures/Feature

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_H
00021 #define OSGEARTHFEATURES_FEATURE_H 1
00022 
00023 #include <osgEarthFeatures/Common>
00024 #include <osgEarthSymbology/Geometry>
00025 #include <osgEarthSymbology/Style>
00026 #include <osgEarth/SpatialReference>
00027 #include <osg/Array>
00028 #include <map>
00029 #include <list>
00030 
00031 namespace osgEarth { namespace Features
00032 {
00033     using namespace osgEarth;
00034     using namespace osgEarth::Symbology;
00035 
00039     class OSGEARTHFEATURES_EXPORT FeatureProfile : public osg::Referenced
00040     {
00041     public:        
00042         FeatureProfile( const GeoExtent& extent );
00043 
00045         const GeoExtent& getExtent() const {
00046             return _extent; }
00047 
00049         const SpatialReference* getSRS() const {
00050             return _extent.getSRS(); }
00051 
00052         bool getTiled() const;
00053         void setTiled(bool tiled);
00054 
00055         int getFirstLevel() const;
00056         void setFirstLevel(int firstLevel );
00057 
00058         int getMaxLevel() const;
00059         void setMaxLevel(int maxLevel);
00060 
00061         const osgEarth::Profile* getProfile() const;
00062         void setProfile( const osgEarth::Profile* profile );
00063 
00064     protected:
00065         osg::ref_ptr< const osgEarth::Profile > _profile;
00066         GeoExtent _extent;
00067         bool _tiled;
00068         int _firstLevel;
00069         int _maxLevel;
00070     };
00071 
00072     struct AttributeValueUnion
00073     {
00074         std::string stringValue;
00075         double      doubleValue;
00076         int         intValue;
00077         bool        boolValue;
00078     };
00079 
00080     enum AttributeType
00081     {
00082         ATTRTYPE_UNSPECIFIED,
00083         ATTRTYPE_STRING,
00084         ATTRTYPE_INT,
00085         ATTRTYPE_DOUBLE,
00086         ATTRTYPE_BOOL
00087     };
00088 
00089     struct OSGEARTHFEATURES_EXPORT AttributeValue : public std::pair<AttributeType,AttributeValueUnion>
00090     {
00091         std::string getString() const;
00092         double getDouble( double defaultValue =0.0 ) const;
00093         int getInt( int defaultValue =0 ) const;
00094         bool getBool( bool defaultValue =false ) const;
00095     };
00096 
00097     typedef std::map<std::string, AttributeValue> AttributeTable;
00098 
00099     typedef unsigned long FeatureID;
00100 
00101     typedef std::map< std::string, AttributeType > FeatureSchema;
00102 
00106     class OSGEARTHFEATURES_EXPORT Feature : public osg::Object
00107     {
00108     public:
00109         Feature( FeatureID fid =0L );
00110 
00111         Feature( Geometry* geom, const Style& style =Style(), FeatureID fid =0L );
00112 
00114         Feature( const Feature& rhs, const osg::CopyOp& copyop =osg::CopyOp::DEEP_COPY_ALL );
00115 
00116         META_Object( osgEarthFeatures, Feature );
00117 
00118     public:
00119 
00120         FeatureID getFID() const;
00121 
00122         void setGeometry( Symbology::Geometry* geom ) { _geom = geom; }
00123 
00124         Symbology::Geometry* getGeometry() { return _geom.get(); }
00125 
00126         const Symbology::Geometry* getGeometry() const { return _geom.get(); }
00127 
00128         const AttributeTable& getAttrs() const { return _attrs; }
00129 
00130         void set( const std::string& name, const std::string& value );
00131         void set( const std::string& name, double value );
00132         void set( const std::string& name, int value );
00133         void set( const std::string& name, bool value );
00134 
00135         bool hasAttr( const std::string& name ) const;
00136 
00137         std::string getString( const std::string& name ) const;
00138         double getDouble( const std::string& name, double defaultValue =0.0 ) const;
00139         int getInt( const std::string& name, int defaultValue =0 ) const;
00140         bool getBool( const std::string& name, bool defaultValue =false ) const;
00141 
00143         optional<Style>& style() { return _style; }
00144         const optional<Style>& style() const { return _style; }
00145 
00147         optional<GeoInterpolation>& geoInterp() { return _geoInterp; }
00148         const optional<GeoInterpolation>& geomInterp() const { return _geoInterp; }
00149 
00151         double eval( NumericExpression& expr ) const;
00152         
00154         const std::string& eval( StringExpression& expr ) const;
00155 
00156     protected:
00157         FeatureID                         _fid;
00158         osg::ref_ptr<Symbology::Geometry> _geom;
00159         AttributeTable                    _attrs;
00160         optional<Style>                   _style;
00161         optional<GeoInterpolation>        _geoInterp;
00162     };
00163 
00164     typedef std::list< osg::ref_ptr<Feature> > FeatureList;
00165 
00166 } } // namespace osgEarth::Features
00167 
00168 #endif // OSGEARTHFEATURES_FEATURE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines