osgEarth 2.1.1
|
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 OSGEARTH_CUBE_H 00021 #define OSGEARTH_CUBE_H 1 00022 00023 #include <osgEarth/Common> 00024 #include <osgEarth/Profile> 00025 #include <osgEarth/TileKey> 00026 #include <osgEarth/Locators> 00027 00028 namespace osgEarth 00029 { 00033 class OSGEARTH_EXPORT CubeUtils 00034 { 00035 public: 00041 static bool latLonToFaceCoords( 00042 double lat_deg, double lon_deg, 00043 double& out_x, double& out_y, int& out_face, 00044 int faceHint = -1 ); 00045 00049 static bool faceCoordsToLatLon( 00050 double x, double y, int face, 00051 double& out_lat_deg, double& out_lon_deg ); 00052 00056 static int getFace( const TileKey& key ); 00057 00064 static bool cubeToFace( 00065 double& in_out_x, 00066 double& in_out_y, 00067 int& out_face ); 00068 00074 static bool cubeToFace( 00075 double& in_out_xmin, double& in_out_ymin, 00076 double& in_out_xmax, double& in_out_ymax, 00077 int& out_face ); 00078 00082 static bool faceToCube( 00083 double& in_out_x, double& in_out_y, 00084 int face ); 00085 }; 00086 00091 class CubeFaceLocator : public GeoLocator 00092 { 00093 public: 00094 CubeFaceLocator(unsigned int face); 00095 00096 // This method will generate geocentric vertex coordinates, given local tile 00097 // coordinates (0=>1). 00098 bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const; 00099 00100 // This method will generate the texture coordinates for a given location on 00101 // the globe. 00102 bool convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const; 00103 00104 private: 00105 unsigned int _face; 00106 }; 00107 00113 class CubeSpatialReference : public SpatialReference 00114 { 00115 public: 00116 CubeSpatialReference(void* handle); 00117 00118 virtual GeoLocator* createLocator( 00119 double xmin, double ymin, double xmax, double ymax, 00120 bool plate_carre =false) const; 00121 00122 // CUBE is a projected coordinate system. 00123 virtual bool isGeographic() const { return false; } 00124 virtual bool isProjected() const { return true; } 00125 00126 // This SRS uses a WGS84 lat/long SRS under the hood for reprojection. So we need the 00127 // pre/post transforms to move from cube to latlong and back. 00128 virtual bool preTransform(double& x, double& y, double& z, void* context) const; 00129 virtual bool postTransform(double& x, double& y, double& z, void* context) const; 00130 00131 virtual bool transformExtent( 00132 const SpatialReference* to_srs, 00133 double& in_out_xmin, 00134 double& in_out_ymin, 00135 double& in_out_xmax, 00136 double& in_out_ymax, 00137 void* context) const; 00138 00139 protected: // SpatialReference overrides 00140 00141 void _init(); 00142 00143 }; 00144 00168 class OSGEARTH_EXPORT UnifiedCubeProfile : public Profile 00169 { 00170 public: 00171 UnifiedCubeProfile(); 00172 00173 public: // utilities 00174 00178 static int getFace( const TileKey& key ); 00179 00180 public: // Profile 00181 00182 virtual void getIntersectingTiles( 00183 const GeoExtent& extent, 00184 std::vector< TileKey >& out_intersectingKeys ) const; 00185 00186 private: 00187 00188 GeoExtent _faceExtent_gcs[6]; 00189 00190 GeoExtent transformGcsExtentOnFace( const GeoExtent& gcsExtent, int face ) const; 00191 }; 00192 } 00193 00194 #endif // OSGEARTH_CUBE_H