osgEarth 2.1.1
Public Member Functions | Protected Member Functions | Protected Attributes | Friends

Tile Class Reference

Inheritance diagram for Tile:
Collaboration diagram for Tile:

List of all members.

Public Member Functions

 Tile (const TileKey &key, GeoLocator *keyLocator, bool quickReleaseGLObjects)
const TileKeygetKey () const
class TerraingetTerrain ()
class TerraingetTerrain () const
void attachToTerrain (Terrain *terrain)
void init ()
const MaskLayerVectorgetTerrainMasks ()
void setTerrainMasks (const MaskLayerVector &terrainMask)
bool getHasBeenTraversed () const
Threading::ReadWriteMutexgetTileLayersMutex ()
virtual void queueTileUpdate (TileUpdate::Action action, int index=-1)
void applyImmediateTileUpdate (TileUpdate::Action action, int index=-1)
virtual bool cancelActiveTasks ()
float getVerticalScale () const
void setVerticalScale (float verticalScale)
osgTerrain::Locator * getLocator () const
const osgTerrain::TileID & getTileId () const
bool getDirty () const
void setDirty (bool value)
void setTerrainTechnique (TerrainTechnique *value)
TerrainTechniquegetTerrainTechnique () const
void removeCustomColorLayer (UID layerUID, bool writeLock=true)
bool getCustomColorLayer (UID layerUID, CustomColorLayer &output, bool readLock=true) const
void getCustomColorLayers (ColorLayersByUID &out, bool readLock=true) const
void setCustomColorLayers (const ColorLayersByUID &in, bool writeLock=true)
void setCustomColorLayer (const CustomColorLayer &colorLayer, bool writeLock=true)
osgTerrain::HeightFieldLayer * getElevationLayer () const
void setElevationLayer (osgTerrain::HeightFieldLayer *value)
virtual void traverse (class osg::NodeVisitor &nv)
virtual void releaseGLObjects (osg::State *=0) const
virtual osg::BoundingSphere computeBound () const

Protected Member Functions

virtual ~Tile ()

Protected Attributes

bool _hasBeenTraversed
bool _quickReleaseGLObjects
bool _parentTileSet
bool _dirty
TileKey _key
osgTerrain::TileID _tileId
osg::ref_ptr< GeoLocator_locator
osg::observer_ptr< Terrain_terrain
MaskLayerVector _masks
Threading::ReadWriteMutex _tileLayersMutex
ColorLayersByUID _colorLayers
float _verticalScale
osg::ref_ptr
< osgTerrain::HeightFieldLayer > 
_elevationLayer
osg::ref_ptr< TerrainTechnique_tech

Friends

class TileFrame

Detailed Description

Definition at line 74 of file Tile.


Constructor & Destructor Documentation

Tile::Tile ( const TileKey key,
GeoLocator keyLocator,
bool  quickReleaseGLObjects 
)

Definition at line 45 of file Tile.cpp.

                                                                                   :
_key( key ),
_locator( keyLocator ),
_quickReleaseGLObjects( quickReleaseGLObjects ),
_hasBeenTraversed( false ),
_verticalScale( 1.0f ),
_parentTileSet( false ),
_tileId( key.getTileId() ),
_dirty( true )
{
    this->setThreadSafeRefUnref( true );
    this->setName( key.str() );

    // initially bump the update requirement so that this tile will receive an update
    // traversal the first time through. It is on the first update traversal that we
    // know the tile is in the scene graph and that it can be registered with the terrain.
    ADJUST_UPDATE_TRAV_COUNT( this, 1 );
}

Here is the call graph for this function:

Tile::~Tile ( ) [protected, virtual]

Definition at line 64 of file Tile.cpp.

{
    //nop
}

Member Function Documentation

void Tile::applyImmediateTileUpdate ( TileUpdate::Action  action,
int  index = -1 
)

Reimplemented in StreamingTile.

Definition at line 267 of file Tile.cpp.

{
    CustomTerrainTechnique* tech = dynamic_cast<CustomTerrainTechnique*>( _tech.get() );
    if ( tech )
    {
        tech->compile( TileUpdate(action, value), 0L );
        tech->applyTileUpdates();
    }
    else
    {
        queueTileUpdate( action, value );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Tile::attachToTerrain ( Terrain terrain)

Definition at line 88 of file Tile.cpp.

{
    _terrain = terrain;
    if ( terrain )
        terrain->registerTile( this );
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool Tile::cancelActiveTasks ( ) [inline, virtual]

Reimplemented in StreamingTile.

Definition at line 107 of file Tile.

{ return true; }

Here is the caller graph for this function:

osg::BoundingSphere Tile::computeBound ( ) const [virtual]

Definition at line 210 of file Tile.cpp.

{
    //Overriden computeBound that takes into account the vertical scale.
    //OE_NOTICE << "Tile::computeBound verticalScale = " << _verticalScale << std::endl;

    osg::BoundingSphere bs;

    if (_elevationLayer.valid())
    {        
        if (!_elevationLayer->getLocator()) return bs;

        osg::BoundingBox bb;
        unsigned int numColumns = _elevationLayer->getNumColumns();
        unsigned int numRows = _elevationLayer->getNumRows();
        for(unsigned int r=0;r<numRows;++r)
        {
            for(unsigned int c=0;c<numColumns;++c)
            {
                float value = 0.0f;
                bool validValue = _elevationLayer->getValidValue(c,r, value);
                if (validValue) 
                {
                    //Multiply by the vertical scale.
                    value *= _verticalScale;
                    osg::Vec3d ndc, v;
                    ndc.x() = ((double)c)/(double)(numColumns-1), 
                        ndc.y() = ((double)r)/(double)(numRows-1);
                    ndc.z() = value;

                    if (_elevationLayer->getLocator()->convertLocalToModel(ndc, v))
                    {
                        bb.expandBy(v);
                    }
                }
            }
        }
        bs.expandBy(bb);

    }
    else
    {
        for(ColorLayersByUID::const_iterator i = _colorLayers.begin(); i != _colorLayers.end(); ++i )
        {
            bs.expandBy( i->second.computeBound() ); 
        }
    }

    return bs;    
}
bool Tile::getCustomColorLayer ( UID  layerUID,
CustomColorLayer output,
bool  readLock = true 
) const

Definition at line 152 of file Tile.cpp.

{
    if ( readLock )
    {
        Threading::ScopedReadLock sharedTileLock( const_cast<Tile*>(this)->_tileLayersMutex );
        return getCustomColorLayer( layerUID, out, false );
    }
    else
    {
        ColorLayersByUID::const_iterator i = _colorLayers.find( layerUID );
        if ( i != _colorLayers.end() )
        {
            out = i->second;
            return true;
        }
    }
    return false;
}

Here is the caller graph for this function:

void Tile::getCustomColorLayers ( ColorLayersByUID out,
bool  readLock = true 
) const

Definition at line 172 of file Tile.cpp.

{
    if ( readLock )
    {
        Threading::ScopedReadLock sharedTileLock( const_cast<Tile*>(this)->_tileLayersMutex );
        return getCustomColorLayers( out, false );
    }
    else
        out = _colorLayers;
}

Here is the caller graph for this function:

bool Tile::getDirty ( ) const [inline]

Definition at line 117 of file Tile.

{ return _dirty; }

Here is the caller graph for this function:

osgTerrain::HeightFieldLayer* Tile::getElevationLayer ( ) const [inline]

Definition at line 130 of file Tile.

{ return _elevationLayer.get(); }

Here is the caller graph for this function:

bool Tile::getHasBeenTraversed ( ) const [inline]

Whether OSG has traversed the tile at least once.

Definition at line 97 of file Tile.

{ return _hasBeenTraversed; }

Here is the caller graph for this function:

const TileKey& Tile::getKey ( ) const [inline]

Gets the tilekey associated with this tile.

Definition at line 80 of file Tile.

{ return _key; }

Here is the caller graph for this function:

osgTerrain::Locator* Tile::getLocator ( ) const [inline]

Definition at line 113 of file Tile.

{ return _locator.get(); }

Here is the caller graph for this function:

class Terrain* Tile::getTerrain ( ) [inline]

Gets the terrain object to which this tile belongs.

Definition at line 83 of file Tile.

{ return _terrain.get(); }

Here is the caller graph for this function:

class Terrain* Tile::getTerrain ( ) const [inline]

Definition at line 84 of file Tile.

{ return _terrain.get(); }
const MaskLayerVector& Tile::getTerrainMasks ( ) [inline]

Gets or sets the terrain mask geometry.

Definition at line 93 of file Tile.

{ return _masks; }

Here is the caller graph for this function:

TerrainTechnique* Tile::getTerrainTechnique ( ) const [inline]

Definition at line 121 of file Tile.

{ return _tech.get(); }

Here is the caller graph for this function:

const osgTerrain::TileID& Tile::getTileId ( ) const [inline]

Definition at line 115 of file Tile.

{ return _tileId; }

Here is the caller graph for this function:

Threading::ReadWriteMutex& Tile::getTileLayersMutex ( ) [inline]

Mutex that protects access to the tile contents.

Definition at line 100 of file Tile.

{ return _tileLayersMutex; }

Here is the caller graph for this function:

float Tile::getVerticalScale ( ) const [inline]

The scale factor for elevation heights

Definition at line 110 of file Tile.

{ return _verticalScale; }

Here is the caller graph for this function:

void Tile::init ( )

intializes the tile and clears its dirty flag

Definition at line 70 of file Tile.cpp.

{
    if ( _tech.valid() )
    {
        _tech->init();
        _dirty = false;
    }
}

Here is the caller graph for this function:

void Tile::queueTileUpdate ( TileUpdate::Action  action,
int  index = -1 
) [virtual]

Reimplemented in StreamingTile.

Definition at line 261 of file Tile.cpp.

{
    _dirty = true;
}

Here is the caller graph for this function:

void Tile::releaseGLObjects ( osg::State *  state = 0) const [virtual]

If State is non-zero, this function releases any associated OpenGL objects for the specified graphics context. Otherwise, releases OpenGL objects for all graphics contexts.

Definition at line 342 of file Tile.cpp.

{
    osg::Node::releaseGLObjects( state );
    
    if ( _tech.valid() )
    {
        //NOTE: crashes sometimes if OSG_RELEASE_DELAY is set -gw
        _tech->releaseGLObjects( state );
    }
}
void Tile::removeCustomColorLayer ( UID  layerUID,
bool  writeLock = true 
)

Tile contents. We don't use the TerrainTile color layer list, we use our own

Definition at line 131 of file Tile.cpp.

{
    if ( writeLock )
    {
        Threading::ScopedWriteLock exclusiveTileLock( _tileLayersMutex );
        removeCustomColorLayer( layerUID, false );
    }
    else
    {
        ColorLayersByUID::iterator i = _colorLayers.find(layerUID);
        if ( i != _colorLayers.end() )
        {
            if ( i->second.getMapLayer()->isDynamic() )
                ADJUST_UPDATE_TRAV_COUNT( this, -1 );

            _colorLayers.erase( i );
        }
    }
}

Here is the caller graph for this function:

void Tile::setCustomColorLayer ( const CustomColorLayer colorLayer,
bool  writeLock = true 
)

Definition at line 106 of file Tile.cpp.

{
    if ( writeLock )
    {
        Threading::ScopedWriteLock exclusiveTileLock( _tileLayersMutex );
        setCustomColorLayer( layer, false );
    }
    else
    {
        int delta = 0;
        ColorLayersByUID::const_iterator i = _colorLayers.find( layer.getUID() );
        if ( i != _colorLayers.end() && i->second.getMapLayer()->isDynamic() )
            --delta;
        
       _colorLayers[layer.getUID()] = layer;
       
        if ( layer.getMapLayer()->isDynamic() )
            ++delta;

        if ( delta != 0 )
            ADJUST_UPDATE_TRAV_COUNT( this, delta );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Tile::setCustomColorLayers ( const ColorLayersByUID in,
bool  writeLock = true 
)

Definition at line 184 of file Tile.cpp.

{
    if ( writeLock )
    {
        Threading::ScopedWriteLock exclusiveLock( _tileLayersMutex );
        setCustomColorLayers( in, false );
    }
    else
    {
        int delta = 0;
        for( ColorLayersByUID::const_iterator i = _colorLayers.begin(); i != _colorLayers.end(); ++i )
            if ( i->second.getMapLayer()->isDynamic() )
                --delta;

        _colorLayers = in;

        for( ColorLayersByUID::const_iterator i = _colorLayers.begin(); i != _colorLayers.end(); ++i )
            if ( i->second.getMapLayer()->isDynamic() )
                ++delta;

        if ( delta != 0 )
            ADJUST_UPDATE_TRAV_COUNT( this, delta );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Tile::setDirty ( bool  value) [inline]

Definition at line 118 of file Tile.

{ _dirty = value; }

Here is the caller graph for this function:

void Tile::setElevationLayer ( osgTerrain::HeightFieldLayer *  value) [inline]

Definition at line 131 of file Tile.

{ _elevationLayer = value; }

Here is the caller graph for this function:

void Tile::setTerrainMasks ( const MaskLayerVector terrainMask) [inline]

Definition at line 94 of file Tile.

{ _masks.clear(); std::copy( terrainMask.begin(), terrainMask.end(), std::back_inserter(_masks) ); }

Here is the call graph for this function:

void Tile::setTerrainTechnique ( TerrainTechnique value)

Definition at line 80 of file Tile.cpp.

{
    tech->_tile = this;
    _tech = tech;
    _dirty = true;
}

Here is the caller graph for this function:

void Tile::setVerticalScale ( float  verticalScale)

Definition at line 96 of file Tile.cpp.

{
    if (_verticalScale != verticalScale)
    {
        _verticalScale = verticalScale;
        dirtyBound();
    }
}

Here is the caller graph for this function:

void Tile::traverse ( class osg::NodeVisitor &  nv) [virtual]

Definition at line 282 of file Tile.cpp.

{    
    // set the parent tile in the technique:
    if ( !_parentTileSet && _terrain.valid() )
    {
        osg::ref_ptr<Tile> parentTile;
        //Take a reference
        osg::ref_ptr< Terrain > terrain = _terrain.get();
        if (terrain.valid())
        {
            terrain->getTile( _key.createParentKey().getTileId(), parentTile );
            CustomTerrainTechnique* tech = dynamic_cast<CustomTerrainTechnique*>( _tech.get() );
            if ( tech )
                tech->setParentTile( parentTile.get() );
            _parentTileSet = true;
        }
    }

    // this block runs the first time the tile is traversed while in the scene graph.
    if ( !_hasBeenTraversed )
    {
        if ( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
        {
            Threading::ScopedWriteLock lock( this->_tileLayersMutex );
            {
                if ( !_hasBeenTraversed && _terrain.valid() )
                {
                    _hasBeenTraversed = true;

                    // we constructed this tile with an update traversal count of 1 so it would get
                    // here and we could register the tile. Now we can decrement it back to normal.
                    // this MUST be called from the UPDATE traversal.
                    ADJUST_UPDATE_TRAV_COUNT( this, -1 );
                }
            }
        }
    }

    // code copied from osgTerrain::TerrainTile... TODO: evaluate this... -gw
    if ( nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR )
    {
        osg::ClusterCullingCallback* ccc = dynamic_cast<osg::ClusterCullingCallback*>(getCullCallback());
        if (ccc)
        {
            if (ccc->cull(&nv,0,static_cast<osg::State *>(0))) return;
        }
    }

    if ( _dirty )
    {
        init();
    }

    if ( _tech.valid() )
    {
        _tech->traverse( nv );
    }
}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class TileFrame [friend]

Definition at line 168 of file Tile.


Member Data Documentation

Definition at line 160 of file Tile.

bool Tile::_dirty [protected]

Definition at line 151 of file Tile.

osg::ref_ptr<osgTerrain::HeightFieldLayer> Tile::_elevationLayer [protected]

Definition at line 163 of file Tile.

bool Tile::_hasBeenTraversed [protected]

Definition at line 148 of file Tile.

TileKey Tile::_key [protected]

Definition at line 153 of file Tile.

osg::ref_ptr<GeoLocator> Tile::_locator [protected]

Definition at line 155 of file Tile.

Definition at line 157 of file Tile.

bool Tile::_parentTileSet [protected]

Definition at line 150 of file Tile.

bool Tile::_quickReleaseGLObjects [protected]

Definition at line 149 of file Tile.

osg::ref_ptr<TerrainTechnique> Tile::_tech [protected]

Definition at line 164 of file Tile.

osg::observer_ptr<Terrain> Tile::_terrain [protected]

Definition at line 156 of file Tile.

osgTerrain::TileID Tile::_tileId [protected]

Definition at line 154 of file Tile.

Definition at line 159 of file Tile.

float Tile::_verticalScale [protected]

Definition at line 161 of file Tile.


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