osgEarth 2.1.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes

osgEarth::TileKey Class Reference

Collaboration diagram for osgEarth::TileKey:

List of all members.

Public Types

enum  Direction { NORTH, SOUTH, EAST, WEST }

Public Member Functions

 TileKey ()
 TileKey (unsigned int lod, unsigned int tile_x, unsigned int tile_y, const Profile *profile)
 TileKey (const TileKey &rhs)
bool operator== (const TileKey &rhs) const
bool operator!= (const TileKey &rhs) const
bool operator< (const TileKey &rhs) const
std::string str () const
osgTerrain::TileID getTileId () const
const osgEarth::ProfilegetProfile () const
const bool valid () const
TileKey createChildKey (unsigned int quadrant) const
TileKey createParentKey () const
TileKey createAncestorKey (int ancestorLod) const
TileKey createNeighborKey (Direction dir) const
unsigned int getLevelOfDetail () const
const GeoExtentgetExtent () const
void getPixelExtents (unsigned int &out_minx, unsigned int &out_miny, unsigned int &out_maxx, unsigned int &out_maxy, const unsigned int &tile_size) const
void getTileXY (unsigned int &out_tile_x, unsigned int &out_tile_y) const
unsigned int getTileX () const
unsigned int getTileY () const

Static Public Member Functions

static int getLOD (const osgTerrain::TileID &id)

Static Public Attributes

static TileKey INVALID

Protected Attributes

std::string _key
unsigned int _lod
unsigned int _x
unsigned int _y
osg::ref_ptr< const Profile_profile
GeoExtent _extent

Detailed Description

Uniquely identifies a single tile on the map, relative to a Profile.

Definition at line 38 of file TileKey.


Member Enumeration Documentation

Creates a key that represents this tile's neighbor at the same LOD. Wraps around in X and Y automatically.

Enumerator:
NORTH 
SOUTH 
EAST 
WEST 

Definition at line 129 of file TileKey.

{ NORTH, SOUTH, EAST, WEST };

Constructor & Destructor Documentation

osgEarth::TileKey::TileKey ( ) [inline]

Constructs an invalid TileKey.

Definition at line 44 of file TileKey.

{ }

Here is the caller graph for this function:

TileKey::TileKey ( unsigned int  lod,
unsigned int  tile_x,
unsigned int  tile_y,
const Profile profile 
)

Creates a new TileKey with the given tile xy at the specified level of detail

Parameters:
lodThe level of detail (subdivision recursion level) of the tile
tile_xThe x index of the tile
tile_yThe y index of the tile
profileThe profile for the tile

Definition at line 30 of file TileKey.cpp.

{
    _x = tile_x;
    _y = tile_y;
    _lod = lod;
    _profile = profile;

    double width, height;
    if ( _profile.valid() )
    {
        _profile->getTileDimensions(lod, width, height);

        double xmin = _profile->getExtent().xMin() + (width * (double)_x);
        double ymax = _profile->getExtent().yMax() - (height * (double)_y);
        double xmax = xmin + width;
        double ymin = ymax - height;

        _extent = GeoExtent( _profile->getSRS(), xmin, ymin, xmax, ymax );

        std::stringstream buf;
        buf << _lod << "_" << _x << "_" << _y;
        _key = buf.str();
    }
    else
    {
        _extent = GeoExtent::INVALID;
        _key = "invalid";
    }
}
TileKey::TileKey ( const TileKey rhs)

Definition at line 60 of file TileKey.cpp.

                                     :
_key( rhs._key ),
_lod(rhs._lod),
_x(rhs._x),
_y(rhs._y),
_profile( rhs._profile.get() ),
_extent( rhs._extent )
{
    //NOP
}

Member Function Documentation

TileKey TileKey::createAncestorKey ( int  ancestorLod) const

Creates and returns a key that represents an ancestor tile corresponding to the specified LOD.

Definition at line 148 of file TileKey.cpp.

{
    if ( ancestorLod > (int)_lod ) return TileKey::INVALID;

    unsigned int x = _x, y = _y;
    for( int i=_lod; i > ancestorLod; i-- )
    {
        x /= 2;
        y /= 2;
    }
    return TileKey( ancestorLod, x, y, _profile.get() );
}

Here is the call graph for this function:

Here is the caller graph for this function:

TileKey TileKey::createChildKey ( unsigned int  quadrant) const

Gets a reference to the child key of this key in the specified quadrant (0, 1, 2, or 3).

Definition at line 113 of file TileKey.cpp.

{
    unsigned int lod = _lod + 1;
    unsigned int x = _x * 2;
    unsigned int y = _y * 2;

    if (quadrant == 1)
    {
        x+=1;
    }
    else if (quadrant == 2)
    {
        y+=1;
    }
    else if (quadrant == 3)
    {
        x+=1;
        y+=1;
    }
    return TileKey( lod, x, y, _profile.get());
}

Here is the call graph for this function:

Here is the caller graph for this function:

TileKey TileKey::createNeighborKey ( TileKey::Direction  dir) const

Definition at line 162 of file TileKey.cpp.

{
    unsigned int tx, ty;
    getProfile()->getNumTiles( _lod, tx, ty );

    unsigned int x =
        dir == WEST ? _x > 0 ? _x-1 : tx-1 :
        dir == EAST ? _x+1 < tx ? _x+1 : 0 :
        _x;

    unsigned int y = 
        dir == SOUTH ? _y > 0 ? _y-1 : ty-1 :
        dir == NORTH ? _y+1 < ty ? _y+1 : 0 :
        _y;        

    return TileKey( _lod, x, y, _profile.get() );
}

Here is the call graph for this function:

TileKey TileKey::createParentKey ( ) const

Creates and returns a key that represents the parent tile of this key.

Definition at line 137 of file TileKey.cpp.

{
    if (_lod == 0) return TileKey::INVALID;

    unsigned int lod = _lod - 1;
    unsigned int x = _x / 2;
    unsigned int y = _y / 2;
    return TileKey( lod, x, y, _profile.get());
}

Here is the call graph for this function:

Here is the caller graph for this function:

const GeoExtent& osgEarth::TileKey::getExtent ( ) const [inline]

Gets the geospatial extents of the tile represented by this key.

Definition at line 140 of file TileKey.

                                           {
            return _extent; }

Here is the caller graph for this function:

unsigned int TileKey::getLevelOfDetail ( ) const

Gets the level of detail of the tile represented by this key.

Definition at line 94 of file TileKey.cpp.

{
    return _lod;
}
static int osgEarth::TileKey::getLOD ( const osgTerrain::TileID &  id) [inline, static]

Definition at line 163 of file TileKey.

                {
                        //The name of the lod changed after OSG 2.6 from layer to level
#if (OPENSCENEGRAPH_MAJOR_VERSION == 2 && OPENSCENEGRAPH_MINOR_VERSION < 7)
                        return id.layer;
#else
                        return id.level;
#endif
                }

Here is the caller graph for this function:

void TileKey::getPixelExtents ( unsigned int &  out_minx,
unsigned int &  out_miny,
unsigned int &  out_maxx,
unsigned int &  out_maxy,
const unsigned int &  tile_size 
) const

Gets the extents of this key's tile, in pixels

Definition at line 100 of file TileKey.cpp.

{
    xmin = _x * tile_size;
    ymin = _y * tile_size;
    xmax = xmin + tile_size;
    ymax = ymin + tile_size; 
}
const Profile * TileKey::getProfile ( ) const

Gets the profile within which this key is interpreted.

Definition at line 72 of file TileKey.cpp.

{
    return _profile.get();
}

Here is the caller graph for this function:

osgTerrain::TileID TileKey::getTileId ( ) const

Gets a TileID corresponding to this key.

Definition at line 86 of file TileKey.cpp.

{
    //TODO: will this be an issue with multi-face? perhaps not since each face will
    // exist within its own scene graph.. ?
    return osgTerrain::TileID(_lod, _x, _y);
}

Here is the caller graph for this function:

unsigned int osgEarth::TileKey::getTileX ( ) const [inline]

Definition at line 160 of file TileKey.

{ return _x; }

Here is the caller graph for this function:

void TileKey::getTileXY ( unsigned int &  out_tile_x,
unsigned int &  out_tile_y 
) const

Gets the X and Y indexes of this tile at its level of detail.

Definition at line 78 of file TileKey.cpp.

{
    out_tile_x = _x;
    out_tile_y = _y;
}

Here is the caller graph for this function:

unsigned int osgEarth::TileKey::getTileY ( ) const [inline]

Definition at line 161 of file TileKey.

{ return _y; }

Here is the caller graph for this function:

bool osgEarth::TileKey::operator!= ( const TileKey rhs) const [inline]

Definition at line 69 of file TileKey.

                                                    {
            return !(*this == rhs);
        }
bool osgEarth::TileKey::operator< ( const TileKey rhs) const [inline]

Definition at line 72 of file TileKey.

                                                   {
            if (_lod < rhs._lod) return true;
            if (_lod > rhs._lod) return false;
            if (_x < rhs._x) return true;
            if (_x > rhs._x) return false;
            return _y < rhs._y;
        }
bool osgEarth::TileKey::operator== ( const TileKey rhs) const [inline]

Definition at line 66 of file TileKey.

                                                    {
            return valid() && rhs.valid() && _lod==rhs._lod && _x==rhs._x && _y==rhs._y;
        }

Here is the call graph for this function:

std::string osgEarth::TileKey::str ( ) const [inline]

Gets the string representation of the key, formatted like: "lod_x_y"

Definition at line 89 of file TileKey.

{ return _key; }

Here is the caller graph for this function:

const bool osgEarth::TileKey::valid ( ) const [inline]

Whether this is a valid key.

Definition at line 104 of file TileKey.

{ return _profile.valid(); }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 179 of file TileKey.

std::string osgEarth::TileKey::_key [protected]

Definition at line 174 of file TileKey.

unsigned int osgEarth::TileKey::_lod [protected]

Definition at line 175 of file TileKey.

osg::ref_ptr<const Profile> osgEarth::TileKey::_profile [protected]

Definition at line 178 of file TileKey.

unsigned int osgEarth::TileKey::_x [protected]

Definition at line 176 of file TileKey.

unsigned int osgEarth::TileKey::_y [protected]

Definition at line 177 of file TileKey.

Canonical invalid tile key.

Definition at line 83 of file TileKey.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines