osgEarth 2.1.1
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

OSGTerrainEngineNode Class Reference

Inheritance diagram for OSGTerrainEngineNode:
Collaboration diagram for OSGTerrainEngineNode:

List of all members.

Public Member Functions

 OSGTerrainEngineNode ()
 OSGTerrainEngineNode (const OSGTerrainEngineNode &rhs, const osg::CopyOp &op=osg::CopyOp::DEEP_COPY_ALL)
 META_Node (osgEarth, OSGTerrainEngineNode)
 ~OSGTerrainEngineNode ()
osg::Node * createNode (const TileKey &key)
virtual void preInitialize (const Map *map, const TerrainOptions &options)
virtual void postInitialize (const Map *map, const TerrainOptions &options)
virtual void validateTerrainOptions (TerrainOptions &options)
virtual const TerrainOptionsgetTerrainOptions () const
virtual void traverse (osg::NodeVisitor &)
virtual osg::BoundingSphere computeBound () const
void onMapInfoEstablished (const MapInfo &mapInfo)
void onMapModelChanged (const MapModelChange &change)
UID getUID () const
OSGTileFactorygetTileFactory () const
class TerraingetTerrain () const

Static Public Member Functions

static void registerEngine (OSGTerrainEngineNode *engineNode)
static void unregisterEngine (UID uid)
static void getEngineByUID (UID uid, osg::ref_ptr< OSGTerrainEngineNode > &output)

Private Member Functions

void init ()
void syncMapModel ()
void addImageLayer (ImageLayer *layer)
void addElevationLayer (ElevationLayer *layer)
void removeImageLayer (ImageLayer *layerRemoved)
void removeElevationLayer (ElevationLayer *layerRemoved)
void moveImageLayer (unsigned int oldIndex, unsigned int newIndex)
void moveElevationLayer (unsigned int oldIndex, unsigned int newIndex)
void updateElevation (Tile *tile)
void installShaders ()
void updateTextureCombining ()

Private Attributes

osg::ref_ptr< OSGTileFactory_tileFactory
class Terrain_terrain
UID _uid
osgEarth::Drivers::OSGTerrainOptions _terrainOptions
Revision _shaderLibRev
osg::ref_ptr< TaskServiceManager_taskServiceMgr
MapFrame_update_mapf
MapFrame_cull_mapf
osg::ref_ptr< TaskService_tileService
osg::ref_ptr< KeyNodeFactory_keyNodeFactory
osg::ref_ptr< TileBuilder_tileBuilder
osg::Timer _timer
unsigned _tileCount
double _tileCreationTime
bool _isStreaming

Detailed Description

Definition at line 38 of file OSGTerrainEngineNode.


Constructor & Destructor Documentation

OSGTerrainEngineNode::OSGTerrainEngineNode ( )

Definition at line 113 of file OSGTerrainEngineNode.cpp.

                                           :
TerrainEngineNode(),
_terrain( 0L ),
_update_mapf( 0L ),
_cull_mapf( 0L ),
_tileCount( 0 ),
_tileCreationTime( 0.0 )
{
    _uid = Registry::instance()->createUID();
    _taskServiceMgr = Registry::instance()->getTaskServiceManager();
}
OSGTerrainEngineNode::OSGTerrainEngineNode ( const OSGTerrainEngineNode rhs,
const osg::CopyOp &  op = osg::CopyOp::DEEP_COPY_ALL 
)

Definition at line 125 of file OSGTerrainEngineNode.cpp.

                                                                                                 :
TerrainEngineNode( rhs, op )
{
    //nop - this copy ctor will never get called since this is a plugin instance.
    OE_WARN << LC << "ILLEGAL STATE in OSGTerrainEngineNode Copy CTOR" << std::endl;
}
OSGTerrainEngineNode::~OSGTerrainEngineNode ( )

Definition at line 132 of file OSGTerrainEngineNode.cpp.

{
    unregisterEngine( _uid );

    if ( _update_mapf )
    {
        delete _update_mapf;
    }

    if ( _cull_mapf )
    {
        delete _cull_mapf;
    }
}

Here is the call graph for this function:


Member Function Documentation

void OSGTerrainEngineNode::addElevationLayer ( ElevationLayer layer) [private]

Definition at line 627 of file OSGTerrainEngineNode.cpp.

{
    if ( !layer || !layer->getTileSource() )
        return;
    
    TileVector tiles;
    _terrain->getTiles( tiles );

    OE_DEBUG << LC << "Found " << tiles.size() << std::endl;

    for (TileVector::iterator itr = tiles.begin(); itr != tiles.end(); ++itr)
    {
        updateElevation( itr->get() );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::addImageLayer ( ImageLayer layer) [private]

Definition at line 443 of file OSGTerrainEngineNode.cpp.

{
    if ( !layerAdded || !layerAdded->getTileSource() )
        return;

    // visit all existing terrain tiles and inform each one of the new image layer:
    TileVector tiles;
    _terrain->getTiles( tiles );

    for( TileVector::iterator itr = tiles.begin(); itr != tiles.end(); ++itr )
    {
        Tile* tile = itr->get();

        StreamingTile* streamingTile = 0L;

        GeoImage geoImage;
        bool needToUpdateImagery = false;
        int imageLOD = -1;

        if ( !_isStreaming || tile->getKey().getLevelOfDetail() == 1 )
        {
            // in standard mode, or at the first LOD in seq/pre mode, fetch the image immediately.
            TileKey geoImageKey = tile->getKey();
            _tileFactory->createValidGeoImage( layerAdded, tile->getKey(), geoImage, geoImageKey );
            imageLOD = tile->getKey().getLevelOfDetail();
        }
        else
        {
            // in seq/pre mode, set up a placeholder and mark the tile as dirty.
            geoImage = GeoImage(ImageUtils::createEmptyImage(), tile->getKey().getExtent() );
            needToUpdateImagery = true;
            streamingTile = static_cast<StreamingTile*>(tile);
        }

        if (geoImage.valid())
        {
            const MapInfo& mapInfo = _update_mapf->getMapInfo();

            double img_min_lon, img_min_lat, img_max_lon, img_max_lat;
            geoImage.getExtent().getBounds(img_min_lon, img_min_lat, img_max_lon, img_max_lat);

            //Specify a new locator for the color with the coordinates of the TileKey that was actually used to create the image
            osg::ref_ptr<GeoLocator> img_locator = tile->getKey().getProfile()->getSRS()->createLocator( 
                img_min_lon, img_min_lat, img_max_lon, img_max_lat, 
                !mapInfo.isGeocentric() );
            
            //Set the CS to geocentric if we are dealing with a geocentric map
            if ( mapInfo.isGeocentric() )
            {
                img_locator->setCoordinateSystemType( osgTerrain::Locator::GEOCENTRIC );
            }

            tile->setCustomColorLayer( CustomColorLayer(
                layerAdded,
                geoImage.getImage(),
                img_locator.get(), imageLOD,  tile->getKey() ) );

            // if necessary, tell the tile to queue up a new imagery request (since we
            // just installed a placeholder)
            if ( needToUpdateImagery )
            {
                streamingTile->updateImagery( layerAdded, *_update_mapf, _tileFactory.get() );
            }
        }
        else
        {
            // this can happen if there's no data in the new layer for the given tile.
            // we will rely on the driver to dump out a warning if this is an error.
        }

        tile->applyImmediateTileUpdate( TileUpdate::ADD_IMAGE_LAYER, layerAdded->getUID() );
    }

    updateTextureCombining();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 225 of file OSGTerrainEngineNode.cpp.

{
    if ( _terrain && _terrain->getNumChildren() > 0 )
    {
        return _terrain->getBound();
    }
    else
    {
        return TerrainEngineNode::computeBound();
    }
}
osg::Node * OSGTerrainEngineNode::createNode ( const TileKey key)

Definition at line 356 of file OSGTerrainEngineNode.cpp.

{
    // if the engine has been disconnected from the scene graph, bail out and don't
    // create any more tiles
    if ( getNumParents() == 0 )
        return 0L;

#ifdef PROFILING
    osg::Timer_t start = _timer.tick();
#endif

    osg::Node* result = 0L;

    if ( _isStreaming )
    {
        // sequential or preemptive mode only.
        // create a map frame so we can safely create tiles from this dbpager thread
        MapFrame mapf( getMap(), Map::TERRAIN_LAYERS, "dbpager::earth plugin" );
        result = getTileFactory()->createSubTiles( mapf, _terrain, key, false );
    }
    else
    {
        result = _keyNodeFactory->createNode( key );
    }

#ifdef PROFILING
    osg::Timer_t end = osg::Timer::instance()->tick();
    if ( result )
    {
        _tileCount++;
        _tileCreationTime += _timer.delta_s(start,_timer.tick());
        if ( _tileCount % 60 == 0 )
        {
            OE_INFO << LC << "Avg tile = " << 1000.0*(_tileCreationTime/(double)_tileCount)
                << " ms, tiles per sec = " << (double)_tileCount/_timer.time_s() << std::endl;
        }
    }
#endif

    return result;
}

Here is the call graph for this function:

void OSGTerrainEngineNode::getEngineByUID ( UID  uid,
osg::ref_ptr< OSGTerrainEngineNode > &  output 
) [static]

Definition at line 97 of file OSGTerrainEngineNode.cpp.

{
    Threading::ScopedReadLock sharedLock( s_engineNodeCacheMutex );
    EngineNodeCache::const_iterator k = getEngineNodeCache().find( uid );
    if (k != getEngineNodeCache().end())
        output = k->second.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 63 of file OSGTerrainEngineNode.

{ return _terrain; }
virtual const TerrainOptions& OSGTerrainEngineNode::getTerrainOptions ( ) const [inline, virtual]

Gets the property set in use by this map engine.

Implements osgEarth::TerrainEngineNode.

Definition at line 53 of file OSGTerrainEngineNode.

{ return _terrainOptions; }
OSGTileFactory* OSGTerrainEngineNode::getTileFactory ( ) const [inline]

Definition at line 62 of file OSGTerrainEngineNode.

{ return _tileFactory.get(); }

Here is the caller graph for this function:

UID OSGTerrainEngineNode::getUID ( ) const

Definition at line 106 of file OSGTerrainEngineNode.cpp.

{
    return _uid;
}
void OSGTerrainEngineNode::init ( ) [private]
void OSGTerrainEngineNode::installShaders ( ) [private]

Definition at line 697 of file OSGTerrainEngineNode.cpp.

{
    // This method installs a default shader setup on the engine node itself. The texture compositor
    // can then override parts of the program by using a VirtualProgram on the _terrain node. We do
    // it this way so that the developer has the option of removing this top-level shader program,
    // replacing it, or migrating it higher up the scene graph if necessary.

    if ( _texCompositor.valid() && _texCompositor->usesShaderComposition() )
    {
        const ShaderFactory* sf = Registry::instance()->getShaderFactory();

        int numLayers = osg::maximum( 1, (int)_update_mapf->imageLayers().size() );

        VirtualProgram* vp = new VirtualProgram();

        // note. this stuff should probably happen automatically in VirtualProgram. gw

        //vp->setShader( "osgearth_vert_main",     sf->createVertexShaderMain() ); // happens in VirtualProgram now
        vp->setShader( "osgearth_vert_setupLighting", sf->createDefaultLightingVertexShader() );
        vp->setShader( "osgearth_vert_setupTexturing",  sf->createDefaultTextureVertexShader( numLayers ) );

        //vp->setShader( "osgearth_frag_main",     sf->createFragmentShaderMain() ); // happend in VirtualProgram now
        vp->setShader( "osgearth_frag_applyLighting", sf->createDefaultLightingFragmentShader() );
        vp->setShader( "osgearth_frag_applyTexturing",  sf->createDefaultTextureFragmentShader( numLayers ) );

        getOrCreateStateSet()->setAttributeAndModes( vp, osg::StateAttribute::ON );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSGTerrainEngineNode::META_Node ( osgEarth  ,
OSGTerrainEngineNode   
)
void OSGTerrainEngineNode::moveElevationLayer ( unsigned int  oldIndex,
unsigned int  newIndex 
) [private]

Definition at line 656 of file OSGTerrainEngineNode.cpp.

{
    TileVector tiles;
    _terrain->getTiles( tiles );

    OE_DEBUG << "Found " << tiles.size() << std::endl;

    for (TileVector::iterator itr = tiles.begin(); itr != tiles.end(); ++itr)
    {
        updateElevation( itr->get() );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::moveImageLayer ( unsigned int  oldIndex,
unsigned int  newIndex 
) [private]

Definition at line 538 of file OSGTerrainEngineNode.cpp.

{
    // take a thread-safe copy of the tile table
    TileVector tiles;
    _terrain->getTiles( tiles );

    for (TileVector::iterator itr = tiles.begin(); itr != tiles.end(); ++itr)
    {
        Tile* tile = itr->get();
        tile->applyImmediateTileUpdate( TileUpdate::MOVE_IMAGE_LAYER );
    }     

    updateTextureCombining();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::onMapInfoEstablished ( const MapInfo mapInfo)

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 238 of file OSGTerrainEngineNode.cpp.

{
    OE_INFO << LC << "Map profile established" << std::endl;
    
    LoadingPolicy::Mode mode = *_terrainOptions.loadingPolicy()->mode();
    OE_INFO << LC << "Loading policy mode = " <<
        ( mode == LoadingPolicy::MODE_PREEMPTIVE ? "PREEMPTIVE" :
          mode == LoadingPolicy::MODE_SEQUENTIAL ? "SEQUENTIAL" :
          mode == LoadingPolicy::MODE_PARALLEL   ? "PARALLEL" :
          "SERIAL/STANDARD" )
        << std::endl;

    // create a factory for creating actual tile data
    _tileFactory = new OSGTileFactory( _uid, *_cull_mapf, _terrainOptions );

    // go through and build the root nodesets.
    if ( !_isStreaming )
    {
        _terrain = new Terrain(
            *_update_mapf, *_cull_mapf, _tileFactory.get(), *_terrainOptions.quickReleaseGLObjects() );
    }
    else
    {
        _terrain = new StreamingTerrain(
            *_update_mapf, *_cull_mapf, _tileFactory.get(), *_terrainOptions.quickReleaseGLObjects() );
    }

    this->addChild( _terrain );

    // set the initial properties from the options structure:
    _terrain->setVerticalScale( _terrainOptions.verticalScale().value() );
    _terrain->setSampleRatio  ( _terrainOptions.heightFieldSampleRatio().value() );

    OE_INFO << LC << "Sample ratio = " << _terrainOptions.heightFieldSampleRatio().value() << std::endl;

    // install the proper layer composition technique:

    if ( _texCompositor->getTechnique() == TerrainOptions::COMPOSITING_MULTIPASS )
    {
        _terrain->setTechniquePrototype( new MultiPassTerrainTechnique( _texCompositor.get() ) );
        OE_INFO << LC << "Compositing technique = MULTIPASS" << std::endl;
    }

    else 
    {
        CustomTerrainTechnique* tech = new SinglePassTerrainTechnique( _texCompositor.get() );

        // prepare the interpolation technique for generating triangles:
        if ( _terrainOptions.elevationInterpolation() == INTERP_TRIANGULATE )
            tech->setOptimizeTriangleOrientation( false );

        _terrain->setTechniquePrototype( tech );
    }

    // install the shader program, if applicable:
    installShaders();

    // calculate a good thread pool size for non-streaming parallel processing
    if ( !_isStreaming )
    {
        unsigned num = 2 * OpenThreads::GetNumberOfProcessors();
        if ( _terrainOptions.loadingPolicy().isSet() )
        {
            if ( _terrainOptions.loadingPolicy()->numLoadingThreads().isSet() )
            {
                num = *_terrainOptions.loadingPolicy()->numLoadingThreads();
            }
            else if ( _terrainOptions.loadingPolicy()->numLoadingThreadsPerCore().isSet() )
            {
                num = (unsigned)(*_terrainOptions.loadingPolicy()->numLoadingThreadsPerCore() * OpenThreads::GetNumberOfProcessors());
            }
        }
        _tileService = new TaskService( "TileBuilder", num );

        // initialize the tile builder
        _tileBuilder = new TileBuilder( getMap(), _terrainOptions, _tileService.get() );


        // initialize a key node factory.
        switch( mode )
        {
        case LoadingPolicy::MODE_SERIAL:
            _keyNodeFactory = new SerialKeyNodeFactory( _tileBuilder.get(), _terrainOptions, mapInfo, _terrain, _uid );
            break;

        case LoadingPolicy::MODE_PARALLEL:
            _keyNodeFactory = new ParallelKeyNodeFactory( _tileBuilder.get(), _terrainOptions, mapInfo, _terrain, _uid );
            break;

        default:
            break;
        }
    }

    // Build the first level of the terrain.
    // Collect the tile keys comprising the root tiles of the terrain.
    std::vector< TileKey > keys;
    _update_mapf->getProfile()->getRootKeys( keys );

    for( unsigned i=0; i<keys.size(); ++i )
    {
        osg::Node* node;
        if ( _keyNodeFactory.valid() )
            node = _keyNodeFactory->createNode( keys[i] );
        else
            node = _tileFactory->createSubTiles( *_update_mapf, _terrain, keys[i], true );

        if ( node )
            _terrain->addChild( node );
        else
            OE_WARN << LC << "Couldn't make tile for root key: " << keys[i].str() << std::endl;
    }

    // we just added the root tiles, so mark the bound in need of recomputation.
    dirtyBound();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::onMapModelChanged ( const MapModelChange change)

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 399 of file OSGTerrainEngineNode.cpp.

{
    _update_mapf->sync();

    // dispatch the change handler
    if ( change.getLayer() )
    {
        // first inform the texture compositor with the new model changes:
        if ( _texCompositor.valid() )
            _texCompositor->applyMapModelChange( change );

        // then apply the actual change:
        switch( change.getAction() )
        {
        case MapModelChange::ADD_IMAGE_LAYER:
            addImageLayer( change.getImageLayer() );
            break;
        case MapModelChange::REMOVE_IMAGE_LAYER:
            removeImageLayer( change.getImageLayer() );
            break;
        case MapModelChange::ADD_ELEVATION_LAYER:
            addElevationLayer( change.getElevationLayer() );
            break;
        case MapModelChange::REMOVE_ELEVATION_LAYER:
            removeElevationLayer( change.getElevationLayer() );
            break;
        case MapModelChange::MOVE_IMAGE_LAYER:
            moveImageLayer( change.getFirstIndex(), change.getSecondIndex() );
            break;
        case MapModelChange::MOVE_ELEVATION_LAYER:
            moveElevationLayer( change.getFirstIndex(), change.getSecondIndex() );
            break;
        }
    }

    // update the terrain revision in threaded mode
    if ( _isStreaming )
    {
        //getTerrain()->incrementRevision();
        static_cast<StreamingTerrain*>(_terrain)->updateTaskServiceThreads( *_update_mapf );
    }
}

Here is the call graph for this function:

void OSGTerrainEngineNode::postInitialize ( const Map map,
const TerrainOptions options 
) [virtual]

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 182 of file OSGTerrainEngineNode.cpp.

{
    TerrainEngineNode::postInitialize( map, options );

    // Initialize the map frames. We need one for the update thread and one for the
    // cull thread. Someday we can detect whether these are actually the same thread
    // (depends on the viewer's threading mode).
    _update_mapf = new MapFrame( map, Map::MASKED_TERRAIN_LAYERS, "osgterrain-update" );
    _cull_mapf   = new MapFrame( map, Map::TERRAIN_LAYERS, "osgterrain-cull" );

    // merge in the custom options:
    _terrainOptions.merge( options );

    // handle an already-established map profile:
    if ( _update_mapf->getProfile() )
    {
        // NOTE: this will initialize the map with the startup layers
        onMapInfoEstablished( MapInfo(map) );
    }

    // populate the terrain with whatever data is in the map to begin with:
    if ( _terrain )
    {
        // update the terrain revision in threaded mode
        if ( _isStreaming )
        {
            static_cast<StreamingTerrain*>(_terrain)->updateTaskServiceThreads( *_update_mapf );
        }

        updateTextureCombining();
    }

    // install a layer callback for processing further map actions:
    map->addMapCallback( new OSGTerrainEngineNodeMapCallbackProxy(this) );

    // register me.
    registerEngine( this );

    // now that we have a map, set up to recompute the bounds
    dirtyBound();
}

Here is the call graph for this function:

void OSGTerrainEngineNode::preInitialize ( const Map map,
const TerrainOptions options 
) [virtual]

Attaches a map to the terrain engine and initialized it.

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 148 of file OSGTerrainEngineNode.cpp.

{
    TerrainEngineNode::preInitialize( map, options );

    _isStreaming =
        options.loadingPolicy()->mode() == LoadingPolicy::MODE_PREEMPTIVE ||
        options.loadingPolicy()->mode() == LoadingPolicy::MODE_SEQUENTIAL;

    // in standard mode, try to set the number of OSG DatabasePager threads to use.
    if ( options.loadingPolicy().isSet() && !_isStreaming )
    {
        int numThreads = -1;

        if ( options.loadingPolicy()->numLoadingThreads().isSet() )
        {
            numThreads = osg::maximum( 1, *options.loadingPolicy()->numLoadingThreads() );
        }
        else if ( options.loadingPolicy()->numLoadingThreadsPerCore().isSet() )
        {
            float numThreadsPerCore = *options.loadingPolicy()->numLoadingThreadsPerCore();
            numThreads = osg::maximum( (int)1, (int)osg::round( 
                numThreadsPerCore * (float)OpenThreads::GetNumberOfProcessors() ) );
        }

        if ( numThreads > 0 )
        {
            OE_INFO << LC << "Requesting " << numThreads << " database pager threads in STANDARD mode" << std::endl;
            osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( numThreads );
            //osg::DisplaySettings::instance()->setNumOfHttpDatabaseThreadsHint( numThreads );
        }
    }
}

Here is the call graph for this function:

void OSGTerrainEngineNode::registerEngine ( OSGTerrainEngineNode engineNode) [static]

Definition at line 73 of file OSGTerrainEngineNode.cpp.

{
    Threading::ScopedWriteLock exclusiveLock( s_engineNodeCacheMutex );
    getEngineNodeCache()[engineNode->_uid] = engineNode;
    OE_DEBUG << LC << "Registered engine " << engineNode->_uid << std::endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::removeElevationLayer ( ElevationLayer layerRemoved) [private]

Definition at line 644 of file OSGTerrainEngineNode.cpp.

{
    TileVector tiles;
    _terrain->getTiles( tiles );

    for (TileVector::iterator itr = tiles.begin(); itr != tiles.end(); ++itr)
    {
        updateElevation( itr->get() );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::removeImageLayer ( ImageLayer layerRemoved) [private]

Definition at line 520 of file OSGTerrainEngineNode.cpp.

{
    // make a thread-safe copy of the tile table
    TileVector tiles;
    _terrain->getTiles( tiles );

    for (TileVector::iterator itr = tiles.begin(); itr != tiles.end(); ++itr)
    {
        Tile* tile = itr->get();

        // critical section
        tile->removeCustomColorLayer( layerRemoved->getUID() );
    }
    
    updateTextureCombining();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::syncMapModel ( ) [private]
void OSGTerrainEngineNode::traverse ( osg::NodeVisitor &  nv) [virtual]

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 681 of file OSGTerrainEngineNode.cpp.

{
    if ( _cull_mapf ) // ensures initialize() has been called
    {
        if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
        {
            // update the cull-thread map frame if necessary. (We don't need to sync the
            // update_mapf becuase that happens in response to a map callback.)
            _cull_mapf->sync();
        }
    }

    TerrainEngineNode::traverse( nv );
}

Here is the call graph for this function:

void OSGTerrainEngineNode::unregisterEngine ( UID  uid) [static]

Definition at line 81 of file OSGTerrainEngineNode.cpp.

{
    Threading::ScopedWriteLock exclusiveLock( s_engineNodeCacheMutex );
    EngineNodeCache::iterator k = getEngineNodeCache().find( uid );
    if (k != getEngineNodeCache().end())
    {
        getEngineNodeCache().erase(k);
        OE_DEBUG << LC << "Unregistered engine " << uid << std::endl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::updateElevation ( Tile tile) [private]

Definition at line 554 of file OSGTerrainEngineNode.cpp.

{
    Threading::ScopedWriteLock exclusiveLock( tile->getTileLayersMutex() );

    const TileKey& key = tile->getKey();

    bool hasElevation = _update_mapf->elevationLayers().size() > 0;

    osgTerrain::HeightFieldLayer* heightFieldLayer = dynamic_cast<osgTerrain::HeightFieldLayer*>(tile->getElevationLayer());
    if (heightFieldLayer)
    {
        // In standard mode, just load the elevation data and dirty the tile.
        if ( !_isStreaming )
        {
            osg::ref_ptr<osg::HeightField> hf;

            if (hasElevation)
                _update_mapf->getHeightField( key, true, hf, 0L, _terrainOptions.elevationInterpolation().value());

            if (!hf.valid()) 
                hf = OSGTileFactory::createEmptyHeightField( key );

            heightFieldLayer->setHeightField( hf.get() );
            hf->setSkirtHeight( tile->getBound().radius() * _terrainOptions.heightFieldSkirtRatio().value() );

            //TODO: review this in favor of a tile update...
            tile->setDirty( true );
        }

        else // if ( isStreaming )
        {
            StreamingTile* stile = static_cast<StreamingTile*>(tile);

            //Update the elevation hint
            stile->setHasElevationHint( hasElevation );

            //In seq/pre mode, if there is no elevation, just clear out all the elevation on the tiles
            if ( !hasElevation )
            {
                osg::ref_ptr<osg::HeightField> hf = OSGTileFactory::createEmptyHeightField( key );
                heightFieldLayer->setHeightField( hf.get() );
                hf->setSkirtHeight( stile->getBound().radius() * _terrainOptions.heightFieldSkirtRatio().value() );
                stile->setElevationLOD( key.getLevelOfDetail() );
                stile->resetElevationRequests( *_update_mapf );
                stile->queueTileUpdate( TileUpdate::UPDATE_ELEVATION );
            }
            else
            {
                //Always load the first LOD so the children tiles can have something to use for placeholders
                if (stile->getKey().getLevelOfDetail() == 1)
                {
                    osg::ref_ptr<osg::HeightField> hf;
                    _update_mapf->getHeightField( key, true, hf, 0L, _terrainOptions.elevationInterpolation().value());
                    if (!hf.valid()) 
                        hf = OSGTileFactory::createEmptyHeightField( key );
                    heightFieldLayer->setHeightField( hf.get() );
                    hf->setSkirtHeight( stile->getBound().radius() * _terrainOptions.heightFieldSkirtRatio().value() );
                    stile->setElevationLOD(tile->getKey().getLevelOfDetail());
                    stile->queueTileUpdate( TileUpdate::UPDATE_ELEVATION );
                }
                else
                {
                    //Set the elevation LOD to -1
                    stile->setElevationLOD(-1);
                    stile->resetElevationRequests( *_update_mapf );
                }
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::updateTextureCombining ( ) [private]

Definition at line 727 of file OSGTerrainEngineNode.cpp.

{
    if ( _texCompositor.valid() )
    {
        int numImageLayers = _update_mapf->imageLayers().size();
        osg::StateSet* terrainStateSet = _terrain->getOrCreateStateSet();

        if ( _texCompositor->usesShaderComposition() )
        {
            // Creates or updates the shader components that are generated by the texture compositor.
            // These components reside in the CustomTerrain's stateset, and override the components
            // installed in the VP on the engine-node's stateset in installShaders().

            VirtualProgram* vp = dynamic_cast<VirtualProgram*>( terrainStateSet->getAttribute(osg::StateAttribute::PROGRAM) );
            if ( !vp )
            {
                // create and add it the first time around..
                vp = new VirtualProgram();
                terrainStateSet->setAttributeAndModes( vp, osg::StateAttribute::ON );
            }

            // first, update the default shader components based on the new layer count:
            const ShaderFactory* sf = Registry::instance()->getShaderFactory();
            vp->setShader( "osgearth_vert_setupTexturing",  sf->createDefaultTextureVertexShader( numImageLayers ) );

            // not this one, because the compositor always generates a new one.
            //vp->setShader( "osgearth_frag_applyTexturing",  lib.createDefaultTextureFragmentShader( numImageLayers ) );
        }

        // next, inform the compositor that it needs to update based on a new layer count:
        _texCompositor->updateMasterStateSet( terrainStateSet ); //, numImageLayers );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OSGTerrainEngineNode::validateTerrainOptions ( TerrainOptions options) [virtual]

Reimplemented from osgEarth::TerrainEngineNode.

Definition at line 670 of file OSGTerrainEngineNode.cpp.

{
    TerrainEngineNode::validateTerrainOptions( options );
    
    //nop for now.
    //note: to validate plugin-specific features, we would create an OSGTerrainOptions
    // and do the validation on that. You would then re-integrate it by calling
    // options.mergeConfig( osgTerrainOptions ).
}

Member Data Documentation

Definition at line 98 of file OSGTerrainEngineNode.

Definition at line 107 of file OSGTerrainEngineNode.

Definition at line 101 of file OSGTerrainEngineNode.

Definition at line 93 of file OSGTerrainEngineNode.

Definition at line 94 of file OSGTerrainEngineNode.

Definition at line 90 of file OSGTerrainEngineNode.

Definition at line 92 of file OSGTerrainEngineNode.

Definition at line 102 of file OSGTerrainEngineNode.

Definition at line 105 of file OSGTerrainEngineNode.

Definition at line 106 of file OSGTerrainEngineNode.

Definition at line 88 of file OSGTerrainEngineNode.

Definition at line 100 of file OSGTerrainEngineNode.

osg::Timer OSGTerrainEngineNode::_timer [private]

Definition at line 104 of file OSGTerrainEngineNode.

Definition at line 91 of file OSGTerrainEngineNode.

Definition at line 97 of file OSGTerrainEngineNode.


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