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

Terrain Class Reference

Inheritance diagram for Terrain:
Collaboration diagram for Terrain:

List of all members.

Public Member Functions

 Terrain (const MapFrame &update_mapf, const MapFrame &cull_mapf, OSGTileFactory *factory, bool quickReleaseGLObjects)
virtual const char * libraryName () const
virtual const char * className () const
OSGTileFactorygetTileFactory ()
bool getQuickReleaseGLObjects () const
const MapFramegetUpdateThreadMapFrame ()
const MapFramegetCullThreadMapFrame ()
virtual TilecreateTile (const TileKey &key, GeoLocator *locator) const
void setTechniquePrototype (TerrainTechnique *tech)
TerrainTechniquecloneTechnique () const
void setSampleRatio (float value)
float getSampleRatio () const
void setVerticalScale (float value)
float getVerticalScale () const
virtual void traverse (osg::NodeVisitor &nv)
void releaseGLObjectsForTiles (osg::State *state)
void registerTile (Tile *newTile)
void getTiles (TileVector &out_tiles)
template<typename T >
void getTile (const osgTerrain::TileID &id, osg::ref_ptr< T > &out_tile, bool lock=true) const

Protected Types

typedef std::map
< osgTerrain::TileID,
osg::ref_ptr< Tile > > 
TileTable
typedef std::queue
< osg::ref_ptr< Tile > > 
TileQueue
typedef std::list
< osg::ref_ptr< Tile > > 
TileList
typedef std::vector
< osg::ref_ptr< Tile > > 
TileVector
typedef std::queue
< osgTerrain::TileID > 
TileIDQueue

Protected Member Functions

virtual ~Terrain ()
virtual unsigned getNumActiveTasks () const
virtual void updateTraversal (osg::NodeVisitor &nv)
void setDelay (unsigned frames)
void decDelay ()

Protected Attributes

Threading::ReadWriteMutex _tilesMutex
TileTable _tiles
TileList _tilesToShutDown
TileVector _tilesToRelease
Threading::Mutex _tilesToReleaseMutex
float _sampleRatio
float _verticalScale
osg::ref_ptr< OSGTileFactory_tileFactory
osg::ref_ptr< const Profile_profile
bool _alwaysUpdate
int _onDemandDelay
bool _registeredWithReleaseGLCallback
const MapFrame_update_mapf
const MapFrame_cull_mapf
bool _quickReleaseGLObjects
bool _quickReleaseCallbackInstalled
osg::ref_ptr< TerrainTechnique_techPrototype

Detailed Description

Definition at line 41 of file Terrain.


Member Typedef Documentation

typedef std::queue< osgTerrain::TileID > Terrain::TileIDQueue [protected]

Definition at line 95 of file Terrain.

typedef std::list< osg::ref_ptr<Tile> > Terrain::TileList [protected]

Definition at line 93 of file Terrain.

typedef std::queue< osg::ref_ptr<Tile> > Terrain::TileQueue [protected]

Definition at line 92 of file Terrain.

typedef std::map< osgTerrain::TileID, osg::ref_ptr<Tile> > Terrain::TileTable [protected]

Definition at line 90 of file Terrain.

typedef std::vector< osg::ref_ptr<Tile> > Terrain::TileVector [protected]

Definition at line 94 of file Terrain.


Constructor & Destructor Documentation

Terrain::Terrain ( const MapFrame update_mapf,
const MapFrame cull_mapf,
OSGTileFactory factory,
bool  quickReleaseGLObjects 
)

Definition at line 89 of file Terrain.cpp.

                                                         :

_tileFactory( tileFactory ),
_registeredWithReleaseGLCallback( false ),
_update_mapf( update_mapf ),
_cull_mapf( cull_mapf ),
_onDemandDelay( 2 ),
_quickReleaseGLObjects( quickReleaseGLObjects ),
_quickReleaseCallbackInstalled( false ),
_alwaysUpdate( false ),
_sampleRatio( 1.0f ),
_verticalScale( 1.0f )
{
    this->setThreadSafeRefUnref( true );

    // the EVENT_VISITOR will reset this to 0 once the "delay" is expired.
    _alwaysUpdate = false;
    setNumChildrenRequiringUpdateTraversal( 1 );

    // register for events in order to support ON_DEMAND frame scheme
    setNumChildrenRequiringEventTraversal( 1 );

    getOrCreateStateSet()->setMode(GL_BLEND , osg::StateAttribute::ON);    
}
Terrain::~Terrain ( ) [protected, virtual]

Definition at line 117 of file Terrain.cpp.

{
    // detach all the tiles from the terrain first. Otherwise osgTerrain::Terrain
    // will crap out.
    for( TileTable::iterator i = _tiles.begin(); i != _tiles.end(); ++i )
    {
        i->second->attachToTerrain( 0L );
    }
    _tiles.clear();
}

Member Function Documentation

virtual const char* Terrain::className ( ) const [inline, virtual]

Reimplemented in StreamingTerrain.

Definition at line 52 of file Terrain.

{ return "Terrain"; }
TerrainTechnique * Terrain::cloneTechnique ( ) const

Definition at line 135 of file Terrain.cpp.

{
    return osg::clone( _techPrototype.get(), osg::CopyOp::DEEP_COPY_ALL );
}

Here is the caller graph for this function:

Tile * Terrain::createTile ( const TileKey key,
GeoLocator locator 
) const [virtual]

Reimplemented in StreamingTerrain.

Definition at line 141 of file Terrain.cpp.

{
    return new Tile( key, keyLocator, this->getQuickReleaseGLObjects() );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Terrain::decDelay ( ) [protected]

Definition at line 321 of file Terrain.cpp.

Here is the caller graph for this function:

const MapFrame& Terrain::getCullThreadMapFrame ( ) [inline]

Definition at line 62 of file Terrain.

{ return _cull_mapf;   }
virtual unsigned Terrain::getNumActiveTasks ( ) const [inline, protected, virtual]

Reimplemented in StreamingTerrain.

Definition at line 85 of file Terrain.

{ return 0; }

Here is the caller graph for this function:

bool Terrain::getQuickReleaseGLObjects ( ) const [inline]

Definition at line 58 of file Terrain.

Here is the caller graph for this function:

float Terrain::getSampleRatio ( ) const [inline]

Definition at line 72 of file Terrain.

{ return _sampleRatio; }

Here is the caller graph for this function:

template<typename T >
void Terrain::getTile ( const osgTerrain::TileID &  id,
osg::ref_ptr< T > &  out_tile,
bool  lock = true 
) const [inline]

Fetches a tile from the repo

Definition at line 117 of file Terrain.

                                                                                              {
        if ( lock ) {
            Threading::ScopedReadLock lock( const_cast<Terrain*>(this)->_tilesMutex );
            TileTable::const_iterator i = _tiles.find( id );
            out_tile = i != _tiles.end()? static_cast<T*>(i->second.get()) : 0L;
        }
        else {
            TileTable::const_iterator i = _tiles.find( id );
            out_tile = i != _tiles.end()? static_cast<T*>(i->second.get()) : 0L;
        }
    }

Here is the caller graph for this function:

OSGTileFactory* Terrain::getTileFactory ( ) [inline]

Definition at line 56 of file Terrain.

{ return _tileFactory.get(); }

Here is the caller graph for this function:

void Terrain::getTiles ( TileVector out_tiles)

Gets a thread-safe copy of the entire tile list

Definition at line 165 of file Terrain.cpp.

{
    Threading::ScopedReadLock lock( _tilesMutex );
    out.clear();
    out.reserve( _tiles.size() );
    for( TileTable::const_iterator i = _tiles.begin(); i != _tiles.end(); ++i )
        out.push_back( i->second.get() );
}

Here is the caller graph for this function:

const MapFrame& Terrain::getUpdateThreadMapFrame ( ) [inline]

Definition at line 60 of file Terrain.

{ return _update_mapf; }
float Terrain::getVerticalScale ( ) const [inline]

Definition at line 76 of file Terrain.

{ return _verticalScale; }

Here is the caller graph for this function:

virtual const char* Terrain::libraryName ( ) const [inline, virtual]

Reimplemented in StreamingTerrain.

Definition at line 50 of file Terrain.

{ return "osgEarth"; }
void Terrain::registerTile ( Tile newTile)

Definition at line 175 of file Terrain.cpp.

{
    Threading::ScopedWriteLock exclusiveTileTableLock( _tilesMutex );
    _tiles[ newTile->getTileId() ] = newTile;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Terrain::releaseGLObjectsForTiles ( osg::State *  state)

Definition at line 184 of file Terrain.cpp.

{
    OpenThreads::ScopedLock<Mutex> lock( _tilesToReleaseMutex );

    for( TileVector::iterator i = _tilesToRelease.begin(); i != _tilesToRelease.end(); ++i )
    {
        i->get()->releaseGLObjects( state );
    }

    _tilesToRelease.clear();

    //while( _tilesToRelease.size() > 0 )
    //{
    //    _tilesToRelease.front()->releaseGLObjects( state );
    //    _tilesToRelease.pop();
    //}
}
void Terrain::setDelay ( unsigned  frames) [protected]

Definition at line 311 of file Terrain.cpp.

{
    if ( _onDemandDelay == 0 && !_alwaysUpdate )
    {
        ADJUST_UPDATE_TRAV_COUNT( this, 1 );
    }
    _onDemandDelay = frames;
}

Here is the caller graph for this function:

void Terrain::setSampleRatio ( float  value)

Definition at line 156 of file Terrain.cpp.

{
    if ( value != _sampleRatio )
    {
        _sampleRatio = value;
    }
}

Here is the caller graph for this function:

void Terrain::setTechniquePrototype ( TerrainTechnique tech)

Definition at line 129 of file Terrain.cpp.

{
    _techPrototype = value;
}

Here is the caller graph for this function:

void Terrain::setVerticalScale ( float  value)

Definition at line 147 of file Terrain.cpp.

{
    if ( value != _verticalScale )
    {
        _verticalScale = value;
    }
}

Here is the caller graph for this function:

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

Definition at line 203 of file Terrain.cpp.

{
    // UPDATE runs whenever a Tile runs its update traversal on the first pass.
    // i.e., only runs then a new Tile is born.
    if ( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
    {
        // if the terrain engine requested "quick release", install the quick release
        // draw callback now.
        if ( _quickReleaseGLObjects && !_quickReleaseCallbackInstalled )
        {
            osg::Camera* cam = findFirstParentOfType<osg::Camera>( this );
            if ( cam )
            {
                cam->setPostDrawCallback( new QuickReleaseGLCallback( this, cam->getPostDrawCallback() ) );
                _quickReleaseCallbackInstalled = true;
                OE_INFO << LC << "Quick release enabled" << std::endl;
            }
        }

        // Collect any "dead" tiles and queue them for shutdown. Since UPDATE only runs
        // when new tiles arrive, this clears out old tiles from the queue at that time.
        // Another approach might be to use an observer_ptr instead...but then we may
        // not be able to use the quick-release.
        {
            Threading::ScopedWriteLock tileTableExclusiveLock( _tilesMutex );

            for( TileTable::iterator i = _tiles.begin(); i != _tiles.end(); )
            {
                Tile* tile = i->second.get();
                if ( tile->getNumParents() == 0 && tile->getHasBeenTraversed() )
                {
                    _tilesToShutDown.push_back( tile );
                    
                    // i is incremented prior to calling erase, but i's previous value goes to erase,
                    // maintaining validity
                    _tiles.erase( i++ );
                }
                else
                    ++i;
            }
        }

        // Remove any dead tiles from the main tile table, while at the same time queuing 
        // any tiles that require quick-release. This criticial section requires an exclusive
        // lock on the main tile table.
        if ( _tilesToShutDown.size() > 0 ) // quick no-lock check..
        {
            Threading::ScopedMutexLock tilesToReleaseExclusiveLock( _tilesToReleaseMutex );

            // Shut down any dead tiles once there tasks are complete.
            for( TileList::iterator i = _tilesToShutDown.begin(); i != _tilesToShutDown.end(); )
            {
                Tile* tile = i->get();
                if ( tile && tile->cancelActiveTasks() )
                {
                    if ( _quickReleaseGLObjects && _quickReleaseCallbackInstalled )
                    {
                        _tilesToRelease.push_back( tile );
                    }

                    i = _tilesToShutDown.erase( i );
                }
                else
                    ++i;
            }
        }

        // call subclass to continue update..
        updateTraversal( nv );
    }
    
    else if ( nv.getVisitorType() == osg::NodeVisitor::EVENT_VISITOR )
    {
        // in OSG's "ON_DEMAND" frame scheme, OSG runs the event visitor as part of the
        // test to see if a frame is needed. In sequential/preemptive mode, we need to 
        // check whether there are any pending tasks running. 

        // In addition, once the tasks run out, we continue to delay on-demand rendering
        // for another full frame so that the event dispatchers can catch up.

        if ( _tilesToShutDown.size() > 0 )
        {
            setDelay( 2 );
        }

        else if ( _onDemandDelay <= 0 )
        {
            unsigned numActiveTasks = getNumActiveTasks();
            if ( numActiveTasks > 0 )
            {
                setDelay( 2 );
            }
        }

        //OE_INFO << "Tasks = " << numTasks << std::endl;

        if ( _onDemandDelay > 0 )
        {
            osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>( &nv );
            ev->getActionAdapter()->requestRedraw();
            decDelay();
        }
    }

    osg::Group::traverse( nv );
}

Here is the call graph for this function:

virtual void Terrain::updateTraversal ( osg::NodeVisitor &  nv) [inline, protected, virtual]

Reimplemented in StreamingTerrain.

Definition at line 88 of file Terrain.

{ }

Here is the caller graph for this function:


Member Data Documentation

bool Terrain::_alwaysUpdate [protected]

Definition at line 134 of file Terrain.

const MapFrame& Terrain::_cull_mapf [protected]

Definition at line 144 of file Terrain.

int Terrain::_onDemandDelay [protected]

Definition at line 135 of file Terrain.

osg::ref_ptr<const Profile> Terrain::_profile [protected]

Definition at line 132 of file Terrain.

Definition at line 147 of file Terrain.

Definition at line 146 of file Terrain.

Definition at line 140 of file Terrain.

float Terrain::_sampleRatio [protected]

Definition at line 103 of file Terrain.

osg::ref_ptr<TerrainTechnique> Terrain::_techPrototype [protected]

Definition at line 149 of file Terrain.

osg::ref_ptr<OSGTileFactory> Terrain::_tileFactory [protected]

Definition at line 131 of file Terrain.

Definition at line 98 of file Terrain.

Definition at line 97 of file Terrain.

Definition at line 100 of file Terrain.

Definition at line 101 of file Terrain.

Definition at line 99 of file Terrain.

const MapFrame& Terrain::_update_mapf [protected]

Definition at line 143 of file Terrain.

float Terrain::_verticalScale [protected]

Definition at line 104 of file Terrain.


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