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_TILE_KEY_H 00021 #define OSGEARTH_TILE_KEY_H 1 00022 00023 #include <osgEarth/Common> 00024 #include <osgEarth/Profile> 00025 #include <osg/Referenced> 00026 #include <osg/Image> 00027 #include <osg/Shape> 00028 #include <osg/Version> 00029 #include <osgDB/ReaderWriter> 00030 #include <osgTerrain/TerrainTile> 00031 #include <string> 00032 00033 namespace osgEarth 00034 { 00038 class OSGEARTH_EXPORT TileKey 00039 { 00040 public: 00044 TileKey() { } 00045 00058 TileKey( 00059 unsigned int lod, 00060 unsigned int tile_x, 00061 unsigned int tile_y, 00062 const Profile* profile ); 00063 00064 TileKey( const TileKey& rhs ); 00065 00066 bool operator == (const TileKey& rhs) const { 00067 return valid() && rhs.valid() && _lod==rhs._lod && _x==rhs._x && _y==rhs._y; 00068 } 00069 bool operator != (const TileKey& rhs) const { 00070 return !(*this == rhs); 00071 } 00072 bool operator < (const TileKey& rhs) const { 00073 if (_lod < rhs._lod) return true; 00074 if (_lod > rhs._lod) return false; 00075 if (_x < rhs._x) return true; 00076 if (_x > rhs._x) return false; 00077 return _y < rhs._y; 00078 } 00079 00083 static TileKey INVALID; 00084 00089 std::string str() const { return _key; } 00090 00094 osgTerrain::TileID getTileId() const; 00095 00099 const osgEarth::Profile* getProfile() const; 00100 00104 const bool valid() const { return _profile.valid(); } 00105 00106 public: 00111 TileKey createChildKey( unsigned int quadrant ) const; 00112 00116 TileKey createParentKey() const; 00117 00122 TileKey createAncestorKey( int ancestorLod ) const; 00123 00124 00129 enum Direction { NORTH, SOUTH, EAST, WEST }; 00130 TileKey createNeighborKey( Direction dir ) const; 00131 00135 unsigned int getLevelOfDetail() const; 00136 00140 const GeoExtent& getExtent() const { 00141 return _extent; } 00142 00146 void getPixelExtents( 00147 unsigned int& out_minx, 00148 unsigned int& out_miny, 00149 unsigned int& out_maxx, 00150 unsigned int& out_maxy, 00151 const unsigned int& tile_size) const; 00152 00156 void getTileXY( 00157 unsigned int& out_tile_x, 00158 unsigned int& out_tile_y) const; 00159 00160 unsigned int getTileX() const { return _x; } 00161 unsigned int getTileY() const { return _y; } 00162 00163 static inline int getLOD(const osgTerrain::TileID& id) 00164 { 00165 //The name of the lod changed after OSG 2.6 from layer to level 00166 #if (OPENSCENEGRAPH_MAJOR_VERSION == 2 && OPENSCENEGRAPH_MINOR_VERSION < 7) 00167 return id.layer; 00168 #else 00169 return id.level; 00170 #endif 00171 } 00172 00173 protected: 00174 std::string _key; 00175 unsigned int _lod; 00176 unsigned int _x; 00177 unsigned int _y; 00178 osg::ref_ptr<const Profile> _profile; 00179 GeoExtent _extent; 00180 }; 00181 } 00182 00183 #endif // OSGEARTH_TILE_KEY_H