osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/engine_seamless/Euler

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2010 Pelican Ventures, Inc.
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 SEAMLESS_EULER
00021 #define SEAMLESS_EULER 1
00022 
00023 #include <osgEarth/Common>
00024 #include <osgEarth/Profile>
00025 #include <osgEarth/TileKey>
00026 #include <osgEarth/Locators>
00027 
00028 namespace seamless
00029 {
00051 namespace euler
00052 {
00053 extern bool latLonToFaceCoords(
00054     double lat_deg, double lon_deg, double& out_x, double& out_y,
00055     int& out_face, int faceHint = -1);
00056 
00060 extern bool faceCoordsToLatLon(
00061     double x, double y, int face, double& out_lat_deg, double& out_lon_deg);
00062 
00069 extern bool cubeToFace(
00070     double& in_out_x, double& in_out_y,int& out_face);
00071 
00077 extern bool cubeToFace(
00078     double& in_out_xmin, double& in_out_ymin,
00079     double& in_out_xmax, double& in_out_ymax,
00080     int& out_face);
00081 
00085 extern bool faceToCube(
00086     double& in_out_x, double& in_out_y, int face);
00087 
00092 extern osg::Vec3d face2dc(int face, const osg::Vec2d& faceCoord);
00093 
00099 extern double arcLength(
00100     const osg::Vec2d& coord1, const osg::Vec2d& coord2, int face);
00101 
00110 extern double distanceToSegment(
00111     const osg::Vec3d& p, const osg::Vec2d& coord1, const osg::Vec2d& coord2,
00112     int face);
00113 
00121 extern double distanceToSegment(
00122     const osg::Vec3d& p, const osg::Vec3d& coord1, const osg::Vec3d& coord2);
00123 }
00124 
00129 class EulerFaceLocator : public osgEarth::GeoLocator
00130 {
00131 public:
00132     EulerFaceLocator(unsigned int face)
00133         : _face(face)
00134     {
00135     }
00136 
00137     // This method will generate geocentric vertex coordinates, given local tile
00138     // coordinates (0=>1).
00139     bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const;
00140 
00141     // This method will generate the texture coordinates for a given location on
00142     // the globe.
00143     bool convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const;
00144 
00145 private:
00146     unsigned int _face;
00147 };
00148 
00162 class EulerSpatialReference : public osgEarth::SpatialReference
00163 {
00164 public:
00165     EulerSpatialReference(void* handle);
00166 
00167     virtual osgEarth::GeoLocator* createLocator(
00168         double xmin, double ymin, double xmax, double ymax,
00169         bool plate_carre =false) const;
00170 
00171     // Euler is a projected coordinate system.
00172     virtual bool isGeographic() const { return false; }
00173     virtual bool isProjected() const { return true; }
00174 
00175     // This SRS uses a WGS84 lat/long SRS under the hood for reprojection. So we need the
00176     // pre/post transforms to move from cube to latlong and back.
00177     virtual bool preTransform(double& x, double& y, void* context) const;
00178     virtual bool postTransform(double& x, double& y, void* context) const;
00179     // Optimized versions that avoid going through GDAL.
00180     virtual bool transform(
00181         double x, double y,
00182         const SpatialReference* to_srs,
00183         double& out_x, double& out_y,
00184         void* context =0L) const;
00185 
00186     virtual bool transformPoints(
00187         const SpatialReference* to_srs, 
00188         double* x, double *y,
00189         unsigned int numPoints,
00190         void* context =0L,
00191         bool ignore_errors =false) const;
00192     
00193     virtual bool transformExtent(
00194         const SpatialReference* to_srs,
00195         double& in_out_xmin,
00196         double& in_out_ymin,
00197         double& in_out_xmax,
00198         double& in_out_ymax,
00199         void* context) const;
00200 
00201     virtual bool transformExtentPoints(
00202         const SpatialReference* to_srs,
00203         double in_xmin, double in_ymin,
00204         double in_xmax, double in_ymax,
00205         double* x, double *y,
00206         unsigned int numx, unsigned int numy,
00207         void* context = 0L, bool ignore_errors = false ) const;
00208 
00209 protected: // SpatialReference overrides
00210 
00211     void _init();
00212     friend class CacheInitializer;
00213 };
00214 
00215 class EulerProfile : public osgEarth::Profile
00216 {
00217 public:
00218     EulerProfile();
00219 
00220 public: // utilities
00221 
00225     static int getFace( const osgEarth::TileKey& key );
00226 
00227 public: // Profile
00228 
00229     virtual void getIntersectingTiles(
00230         const osgEarth::GeoExtent& extent,
00231         std::vector<osgEarth::TileKey>& out_intersectingKeys ) const;
00232 
00233 private:
00234 
00235 };
00236 }
00237 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines