osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/GeoData

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 #ifndef OSGEARTH_GEODATA_H
00020 #define OSGEARTH_GEODATA_H 1
00021 
00022 #include <osg/Referenced>
00023 #include <osg/Image>
00024 #include <osg/Shape>
00025 #include <osgTerrain/Locator>
00026 #include <osgEarth/Common>
00027 #include <osgEarth/SpatialReference>
00028 #include <osgEarth/VerticalSpatialReference>
00029 #include <osgEarth/HeightFieldUtils>
00030 #include <osgEarth/Units>
00031 
00032 namespace osgEarth
00033 {
00037     class OSGEARTH_EXPORT Bounds : public osg::BoundingBoxImpl<osg::Vec3d>
00038     {
00039     public:
00040         Bounds();
00041         Bounds(double xmin, double ymin, double xmax, double ymax );
00042 
00043         double width() const;
00044         double height() const;
00045         double depth() const;
00046         bool contains(double x, double y ) const;
00047         bool contains(const Bounds& rhs) const;
00048         Bounds unionWith(const Bounds& rhs) const; 
00049         Bounds intersectionWith(const Bounds& rhs) const;
00050         void expandBy( double x, double y );
00051         void expandBy( double x, double y, double z );
00052         void expandBy( const Bounds& rhs );
00053         osg::Vec2d center2d() const;
00054         double radius2d() const;
00055         std::string toString() const;
00056         bool isValid() const;
00057         bool isEmpty() const { return !isValid(); }
00058         void transform( const SpatialReference* fromSRS, const SpatialReference* toSRS );
00059     };
00060 
00068     class OSGEARTH_EXPORT GeoExtent
00069     {
00070     public:
00072         GeoExtent(); 
00073 
00075         GeoExtent(
00076             const SpatialReference* srs,
00077             double xmin = FLT_MAX, double ymin = FLT_MAX,
00078             double xmax = -FLT_MAX, double ymax = -FLT_MAX );
00079 
00081         GeoExtent( const GeoExtent& rhs );
00082 
00084         GeoExtent( const SpatialReference* srs, const Bounds& bounds );
00085 
00086         bool operator == ( const GeoExtent& rhs ) const;
00087         bool operator != ( const GeoExtent& rhs ) const;
00088 
00090         const SpatialReference* getSRS() const;
00091 
00092         double xMin() const { return _xmin; }
00093         double& xMin() { return _xmin; }
00094         double yMin() const { return _ymin; }
00095         double& yMin() { return _ymin; }
00096         double xMax() const { return _xmax; }
00097         double& xMax() { return _xmax; }
00098         double yMax() const { return _ymax; }
00099         double& yMax() { return _ymax; }
00100 
00101         double width() const;
00102         double height() const;
00103 
00104         void getCentroid( double& out_x, double& out_y ) const;
00105 
00110         bool crossesDateLine() const;
00111 
00115         void getBounds(double &xmin, double &ymin, double &xmax, double &ymax) const;
00116 
00118         bool isValid() const;
00119         bool defined() const { return isValid(); }
00120 
00126         bool splitAcrossDateLine( GeoExtent& first, GeoExtent& second ) const;
00127 
00137         GeoExtent transform( const SpatialReference* to_srs ) const;
00138 
00148         bool contains(double x, double y, const SpatialReference* xy_srs =0L) const;
00149 
00153         bool contains( const Bounds& rhs ) const;
00154 
00158         bool intersects( const GeoExtent& rhs ) const;
00159 
00161         Bounds bounds() const;
00162 
00167         void expandToInclude( double x, double y );
00168 
00173         void expandToInclude( const Bounds& rhs );
00174         
00179         GeoExtent intersectionSameSRS( const Bounds& rhs ) const;
00180 
00184         std::string toString() const;
00185 
00189         void scale(double x_scale, double y_scale);
00190 
00194                 void expand( double x, double y );
00195 
00199         double area() const;
00200 
00201     public:
00202         static GeoExtent INVALID;
00203 
00204     private:
00205         osg::ref_ptr<const SpatialReference> _srs;
00206         double _xmin, _ymin, _xmax, _ymax;
00207     };
00208 
00212     class OSGEARTH_EXPORT DataExtent : public GeoExtent
00213     {
00214     public:
00215         DataExtent(const GeoExtent& extent, unsigned int minLevel, unsigned int maxLevel);
00216 
00218         unsigned int getMinLevel() const;
00219 
00221         unsigned int getMaxLevel() const;
00222 
00223     private:
00224         unsigned int _minLevel;
00225         unsigned int _maxLevel;
00226     };
00227 
00228     typedef std::vector< DataExtent > DataExtentList;
00229 
00230 
00234     class OSGEARTH_EXPORT GeoImage
00235     {
00236     public:
00238         GeoImage();
00239 
00243         GeoImage( osg::Image* image, const GeoExtent& extent );
00244 
00245         static GeoImage INVALID;
00246 
00247     public:
00251         bool valid() const { return _image.valid(); }
00252 
00256         osg::Image* getImage() const;
00257 
00261         const GeoExtent& getExtent() const;
00262 
00267         const SpatialReference* getSRS() const;
00268 
00284         GeoImage crop( 
00285             const GeoExtent& extent,
00286             bool exact = false,
00287             unsigned int width = 0,
00288             unsigned int height = 0) const;
00289 
00302         GeoImage reproject(
00303             const SpatialReference* to_srs,
00304             const GeoExtent* to_extent = 0,
00305             unsigned int width = 0,
00306             unsigned int height = 0) const;
00307 
00311         GeoImage addTransparentBorder(
00312             bool leftBorder=true, 
00313             bool rightBorder=true, 
00314             bool bottomBorder=true, 
00315             bool topBorder=true);
00316 
00320         osg::Image* takeImage();
00321 
00325                 double getUnitsPerPixel() const;
00326 
00327     private:
00328         osg::ref_ptr<osg::Image> _image;
00329         GeoExtent _extent;
00330     };
00331 
00332     typedef std::vector<GeoImage> GeoImageVector;
00333 
00337     class OSGEARTH_EXPORT GeoHeightField
00338     {
00339     public:
00341         GeoHeightField();
00342 
00346         GeoHeightField(
00347             osg::HeightField* heightField,
00348             const GeoExtent& extent,
00349             const VerticalSpatialReference* vsrs);
00350 
00351         static GeoHeightField INVALID;
00352 
00356         bool valid() const { return _heightField.valid(); }
00357 
00377         bool getElevation(
00378             const SpatialReference* inputSRS, 
00379             double x, double y,
00380             ElevationInterpolation interp,
00381             const VerticalSpatialReference* outputVSRS,
00382             float& out_elevation ) const;
00383         
00388         GeoHeightField createSubSample( const GeoExtent& destEx, ElevationInterpolation interpolation) const;
00389 
00393         const GeoExtent& getExtent() const;
00394 
00398         const osg::HeightField* getHeightField() const;
00399         osg::HeightField* getHeightField();
00400 
00404         osg::HeightField* takeHeightField();
00405 
00406     protected:
00407         osg::ref_ptr<osg::HeightField> _heightField;
00408         GeoExtent _extent;
00409         osg::ref_ptr<const VerticalSpatialReference> _vsrs;
00410     };
00411 
00412         typedef std::vector<GeoHeightField> GeoHeightFieldVector;
00413 
00414     
00419     class OSGEARTH_EXPORT Geoid : public osg::Referenced
00420     {
00421     public:
00422         Geoid();
00423 
00425         void setName( const std::string& value );
00426         const std::string& getName() const { return _name; }
00427 
00429         void setHeightField( const GeoHeightField& hf );
00430 
00432         float getOffset(
00433             double lat_deg, double lon_deg, 
00434             const ElevationInterpolation& interp =INTERP_BILINEAR) const;
00435 
00437         const Units& getUnits() const { return _units; }
00438         void setUnits( const Units& value );
00439 
00441         bool isValid() const { return _valid; }
00442 
00444         bool isEquivalentTo( const Geoid& rhs ) const;
00445 
00446     private:
00447         std::string _name;
00448         GeoHeightField _hf;
00449         Units _units;
00450         bool _valid;
00451         void validate();
00452     };
00453 
00454 }
00455 
00456 #endif // OSGEARTH_GEODATA_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines