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

osgEarth::MapNode Class Reference

Collaboration diagram for osgEarth::MapNode:

List of all members.

Classes

class  TileRangeData

Public Member Functions

 MapNode ()
 MapNode (const MapNodeOptions &options)
 MapNode (Map *map)
 MapNode (Map *map, const MapNodeOptions &options)
virtual const char * libraryName () const
virtual const char * className () const
MapgetMap ()
bool isGeocentric () const
osg::Group * getModelLayerGroup () const
void addTerrainDecorator (osg::Group *decorator)
void removeTerrainDecorator (osg::Group *decorator)
osg::Group * getOverlayGroup ()
void updateOverlayGraph ()
const MapNodeOptionsgetMapNodeOptions () const
TerrainEngineNodegetTerrainEngine () const
ConfigexternalConfig ()
const ConfigexternalConfig () const
virtual osg::BoundingSphere computeBound () const
virtual void traverse (class osg::NodeVisitor &nv)
void onModelLayerAdded (ModelLayer *, unsigned int)
void onModelLayerRemoved (ModelLayer *)
void onModelLayerMoved (ModelLayer *layer, unsigned int oldIndex, unsigned int newIndex)
void onModelLayerOverlayChanged (ModelLayer *layer)

Static Public Member Functions

static MapNodeload (class osg::ArgumentParser &arguments)
static MapNodefindMapNode (osg::Node *graph)

Protected Member Functions

virtual ~MapNode ()

Private Types

typedef std::map< ModelLayer
*, osg::Node * > 
ModelLayerNodeMap

Private Member Functions

void init ()
void adjustEventTraversalCount (int delta)

Private Attributes

unsigned int _id
osg::ref_ptr< Map_map
osg::ref_ptr< osg::Group > _models
osg::ref_ptr< osg::Group > _overlayModels
osg::ref_ptr< OverlayDecorator_overlayDecorator
MapNodeOptions _mapNodeOptions
Config _externalConf
ModelLayerNodeMap _modelLayerNodes
osg::Group * _maskLayerNode
osg::ref_ptr< osgSim::OverlayNode > _pendingOverlayNode
bool _pendingOverlayAutoSetTextureUnit
unsigned _lastNumBlacklistedFilenames
osg::ref_ptr< TerrainEngineNode_terrainEngine
bool _terrainEngineInitialized
osg::ref_ptr< osg::Group > _terrainEngineContainer
osg::ref_ptr< ModelLayerCallback_modelLayerCallback
osg::ref_ptr< MapCallback_mapCallback

Detailed Description

OSG Node that forms the root of an osgEarth map. This node is a "view" component that renders data from a "Map" data model.

Definition at line 37 of file MapNode.


Member Typedef Documentation

typedef std::map<ModelLayer*,osg::Node*> osgEarth::MapNode::ModelLayerNodeMap [private]

Definition at line 182 of file MapNode.


Constructor & Destructor Documentation

MapNode::MapNode ( )

Creates an empty map node.

Definition at line 144 of file MapNode.cpp.

                 :
_map( new Map() )
{
    init();
}

Here is the call graph for this function:

MapNode::MapNode ( const MapNodeOptions options)

Creates an empty map node.

Parameters:
optionsTile creation and rendering properties

Definition at line 156 of file MapNode.cpp.

                                                :
_map( new Map() ),
_mapNodeOptions( options )
{
    init();
}

Here is the call graph for this function:

MapNode::MapNode ( Map map)

Creates a new map node.

Parameters:
mapMap data that this map node will render.

Definition at line 150 of file MapNode.cpp.

                           :
_map( map )
{
    init();
}

Here is the call graph for this function:

MapNode::MapNode ( Map map,
const MapNodeOptions options 
)

Creates a new map node.

Parameters:
mapMap data that this map node will render.
optionsTile creation and rendering properties

Definition at line 163 of file MapNode.cpp.

                                                          :
_map( map? map : new Map() ),
_mapNodeOptions( options )
{
    init();
}

Here is the call graph for this function:

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

Definition at line 307 of file MapNode.cpp.

{
    _map->removeMapCallback( _mapCallback.get() );

    ModelLayerVector modelLayers;
    _map->getModelLayers( modelLayers );
    //Remove our model callback from any of the model layers in the map    
    for (osgEarth::ModelLayerVector::iterator itr = modelLayers.begin(); itr != modelLayers.end(); ++itr)
    {
        this->onModelLayerRemoved( itr->get() );        
    }
}

Here is the call graph for this function:


Member Function Documentation

void MapNode::addTerrainDecorator ( osg::Group *  decorator)

Adds a node that decorates the terrain groups

Definition at line 501 of file MapNode.cpp.

{    
    if ( _terrainEngine.valid() )
    {
        decorator->addChild( _terrainEngine.get() );
        _terrainEngine->getParent(0)->replaceChild( _terrainEngine.get(), decorator );
        dirtyBound();

        TerrainDecorator* td = dynamic_cast<TerrainDecorator*>( decorator );
        if ( td )
            td->onInstall( _terrainEngine.get() );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MapNode::adjustEventTraversalCount ( int  delta) [private]

Definition at line 541 of file MapNode.cpp.

{
    int oldCount = this->getNumChildrenRequiringEventTraversal();
    if ( oldCount + delta >= 0 )
        this->setNumChildrenRequiringEventTraversal( (unsigned int)(oldCount + delta) );
}

Here is the caller graph for this function:

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

Definition at line 93 of file MapNode.

{ return "MapNode"; }
osg::BoundingSphere MapNode::computeBound ( ) const [virtual]

Definition at line 321 of file MapNode.cpp.

{
    osg::BoundingSphere bs;
    if ( getTerrainEngine() )
    {
        bs.expandBy(  getTerrainEngine()->getBound() );
    }
    if ( _models.valid() )
        bs.expandBy( _models->getBound() );
    return bs;
}

Here is the call graph for this function:

Config& osgEarth::MapNode::externalConfig ( ) [inline]

Gets the Config object serializing external data. External data is information that osgEarth itself does not control, but that an app can include in the MapNode for the purposes of including it in a .earth file.

Definition at line 158 of file MapNode.

{ return _externalConf; }

Here is the caller graph for this function:

const Config& osgEarth::MapNode::externalConfig ( ) const [inline]

Definition at line 159 of file MapNode.

{ return _externalConf; }
MapNode * MapNode::findMapNode ( osg::Node *  graph) [static]

Finds the topmost Map node in the specified scene graph, or returns NULL if no Map node exists in the graph.

Parameters:
graphNode graph in which to search for a MapNode

Definition at line 365 of file MapNode.cpp.

{
    return findTopMostNodeOfType<MapNode>( graph );
}

Here is the caller graph for this function:

Map * MapNode::getMap ( )

Gets the Map that this MapNode is rendering.

Definition at line 334 of file MapNode.cpp.

{
    return _map.get();
}

Here is the caller graph for this function:

const MapNodeOptions & MapNode::getMapNodeOptions ( ) const

Gets the engine properties associated with this node. The engine properties dictate how the map engine will create scene graph elements.

Definition at line 359 of file MapNode.cpp.

{
    return _mapNodeOptions;
}

Here is the caller graph for this function:

osg::Group * MapNode::getModelLayerGroup ( ) const

Accesses the group node that contains all the ModelLayers.

Definition at line 353 of file MapNode.cpp.

{
    return _models.get();
}
osg::Group* osgEarth::MapNode::getOverlayGroup ( ) [inline]

Accesses the group containing anything that will be "draped" on the terrain via the OverlayDecorator.

Definition at line 134 of file MapNode.

{ return _overlayModels.get(); }
TerrainEngineNode * MapNode::getTerrainEngine ( ) const

Gets the underlying terrain engine that renders the terrain surface of the map.

Definition at line 340 of file MapNode.cpp.

{
    if ( !_terrainEngineInitialized && _terrainEngine.valid() )
    {
        _terrainEngine->postInitialize( _map.get(), getMapNodeOptions().getTerrainOptions() );
        MapNode* me = const_cast< MapNode* >(this);
        me->_terrainEngineInitialized = true;
        me->dirtyBound();
    }
    return _terrainEngine.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MapNode::init ( ) [private]

Definition at line 171 of file MapNode.cpp.

{
        // Protect the MapNode from the Optimizer
        setDataVariance(osg::Object::DYNAMIC);

    setName( "osgEarth::MapNode" );

    // Since we have global uniforms in the stateset, mark it dynamic so it is immune to
    // multi-threaded overlap
    // TODO: do we need this anymore? there are no more global uniforms in here.. gw
    getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);

    _modelLayerCallback = new MapModelLayerCallback(this);

    _maskLayerNode = 0L;
    _lastNumBlacklistedFilenames = 0;

    // Set the global proxy settings
    // TODO: this should probably happen elsewhere, like in the registry?
    if ( _mapNodeOptions.proxySettings().isSet() )
    {
                HTTPClient::setProxySettings( _mapNodeOptions.proxySettings().get() );
    }

    // establish global driver options. These are OSG reader-writer options that
    // will make their way to any read* calls down the pipe
    const osgDB::ReaderWriter::Options* global_options = _map->getGlobalOptions();
    osg::ref_ptr<osgDB::ReaderWriter::Options> local_options = global_options ? 
        new osgDB::ReaderWriter::Options( *global_options ) :
        NULL;

    if ( local_options.valid() )
    {
        OE_INFO << LC
            << "Options string = " 
            << (local_options.valid()? local_options->getOptionString() : "<empty>")
            << std::endl;
    }

    // TODO: not sure why we call this here
    _map->setGlobalOptions( local_options.get() );

    // overlays:
    _pendingOverlayAutoSetTextureUnit = true;

    // load and attach the terrain engine, but don't initialize it until we need it
    const TerrainOptions& terrainOptions = _mapNodeOptions.getTerrainOptions();

    _terrainEngine = TerrainEngineNodeFactory::create( _map.get(), terrainOptions );
    _terrainEngineInitialized = false;

    // the engine needs a container so we can set lighting state on the container and
    // not on the terrain engine itself. Setting the dynamic variance will prevent
    // an optimizer from collapsing the empty group node.
    _terrainEngineContainer = new osg::Group();
    _terrainEngineContainer->setDataVariance( osg::Object::DYNAMIC );
    this->addChild( _terrainEngineContainer.get() );

    // initialize terrain-level lighting:
    if ( terrainOptions.enableLighting().isSet() )
    {
        _terrainEngineContainer->getOrCreateStateSet()->setMode( GL_LIGHTING, terrainOptions.enableLighting().value() ? 
            osg::StateAttribute::ON | osg::StateAttribute::PROTECTED :
            osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
    }

    if ( _terrainEngine.valid() )
    {
        // inform the terrain engine of the map information now so that it can properly
        // initialize it's CoordinateSystemNode. This is necessary in order to support
        // manipulators and to set up the texture compositor prior to frame-loop 
        // initialization.
        _terrainEngine->preInitialize( _map.get(), terrainOptions );

        _terrainEngineContainer->addChild( _terrainEngine.get() );
    }
    else
        OE_WARN << "FAILED to create a terrain engine for this map" << std::endl;

    // make a group for the model layers:
    _models = new osg::Group();
    _models->setName( "osgEarth::MapNode.modelsGroup" );
    addChild( _models.get() );

    // make a group for overlay model layers:
    _overlayModels = new osg::Group();
    _overlayModels->setName( "osgEarth::MapNode.overlayModelsGroup" );

    // a decorator for overlay models:
    _overlayDecorator = new OverlayDecorator();
    if ( _mapNodeOptions.overlayVertexWarping().isSet() )
        _overlayDecorator->setVertexWarping( *_mapNodeOptions.overlayVertexWarping() );
    if ( _mapNodeOptions.overlayBlending().isSet() )
        _overlayDecorator->setOverlayBlending( *_mapNodeOptions.overlayBlending() );
    if ( _mapNodeOptions.overlayTextureSize().isSet() )
        _overlayDecorator->setTextureSize( *_mapNodeOptions.overlayTextureSize() );
    addTerrainDecorator( _overlayDecorator.get() );

    // install any pre-existing model layers:
    ModelLayerVector modelLayers;
    _map->getModelLayers( modelLayers );
    int modelLayerIndex = 0;
    for( ModelLayerVector::const_iterator k = modelLayers.begin(); k != modelLayers.end(); k++, modelLayerIndex++ )
    {
        onModelLayerAdded( k->get(), modelLayerIndex );
    }

#if 0
    // install any pre-existing mask layer:
    if ( _map->getTerrainMaskLayer() )
    {
        onMaskLayerAdded( _map->getTerrainMaskLayer() );
    }
#endif

    _mapCallback = new MapNodeMapCallbackProxy(this);
    // install a layer callback for processing further map actions:
    _map->addMapCallback( _mapCallback.get()  );

    osg::StateSet* ss = getOrCreateStateSet();
        //ss->setAttributeAndModes( new osg::CullFace() ); //, osg::StateAttribute::ON);
    //ss->setAttributeAndModes( new osg::PolygonOffset( -1, -1 ) );

    if ( _mapNodeOptions.enableLighting().isSet() )
    {
        ss->setMode( GL_LIGHTING, _mapNodeOptions.enableLighting().value() ? 
            osg::StateAttribute::ON | osg::StateAttribute::PROTECTED :
            osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
    }

    dirtyBound();

    // register for event traversals so we can deal with blacklisted filenames
    adjustEventTraversalCount( 1 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool MapNode::isGeocentric ( ) const

Returns true if the realized terrain model is geocentric, false if it is flat/projected.

Definition at line 371 of file MapNode.cpp.

{
    return _map->isGeocentric();
}

Here is the caller graph for this function:

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

Definition at line 92 of file MapNode.

{ return "osgEarth"; }
MapNode * MapNode::load ( class osg::ArgumentParser &  arguments) [static]

Attempts to load a MapNOde from a ".earth" file in the arguments list

Definition at line 126 of file MapNode.cpp.

{
    for( unsigned i=1; i<args.argc(); ++i )
    {
        if ( args[i] && endsWith(args[i], ".earth") )
        {
            osg::ref_ptr<osg::Node> output;
            if ( HTTPClient::readNodeFile( args[i], output ) == HTTPClient::RESULT_OK )
            {
                return dynamic_cast<MapNode*>( output.release() );
            }
        }
    }    
    return 0L;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MapNode::onModelLayerAdded ( ModelLayer layer,
unsigned int  index 
)

Definition at line 377 of file MapNode.cpp.

{
    osg::Node* node = layer->getOrCreateNode();

    layer->addCallback(_modelLayerCallback.get() );

    if ( node )
    {
        if ( _modelLayerNodes.find( layer ) != _modelLayerNodes.end() )
        {
            OE_WARN
                << "Illegal: tried to add the name model layer more than once: " 
                << layer->getName()
                << std::endl;
        }
        else
        {
            if ( dynamic_cast<TerrainDecorator*>(node) || dynamic_cast<osgSim::OverlayNode*>(node) )
            {
                OE_INFO << LC << "Installing overlay node" << std::endl;
                addTerrainDecorator( node->asGroup() );
            }
            else
            {
                if ( layer->getOverlay() )
                {
                    _overlayModels->addChild( node ); // todo: index?
                    updateOverlayGraph();
                }
                else
                {
                    _models->insertChild( index, node );
                }
            }

            ModelSource* ms = layer->getModelSource();
            if ( ms && ms->getOptions().renderOrder().isSet() )
            {
                node->getOrCreateStateSet()->setRenderBinDetails(
                    ms->getOptions().renderOrder().value(), "RenderBin" );
            }

            _modelLayerNodes[ layer ] = node;
        }

        dirtyBound();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MapNode::onModelLayerMoved ( ModelLayer layer,
unsigned int  oldIndex,
unsigned int  newIndex 
)

Definition at line 464 of file MapNode.cpp.

{
                if ( layer )
    {
        // look up the node associated with this model layer.
        ModelLayerNodeMap::iterator i = _modelLayerNodes.find( layer );
        if ( i != _modelLayerNodes.end() )
        {
            osg::Node* node = i->second;
            
            if ( dynamic_cast<osgSim::OverlayNode*>( node ) )
            {
                // treat overlay node as a special case
            }
            else
            {
                _models->removeChild( node );
                _models->insertChild( newIndex, node );
            }
        }
        
        dirtyBound();
    }
}
void MapNode::onModelLayerOverlayChanged ( ModelLayer layer)

Definition at line 568 of file MapNode.cpp.

{
    OE_NOTICE << "Overlay changed to "  << layer->getOverlay() << std::endl;
    osg::ref_ptr< osg::Group > origParent = layer->getOverlay() ? _models.get() : _overlayModels.get();
    osg::ref_ptr< osg::Group > newParent  = layer->getOverlay() ? _overlayModels.get() : _models.get();

    osg::ref_ptr< osg::Node > node = layer->getOrCreateNode();
    if (node.valid())
    {
        //Remove it from the original parent and add it to the new parent
        origParent->removeChild( node.get() );
        newParent->addChild( node.get() );
    }

    updateOverlayGraph();
}

Here is the call graph for this function:

void MapNode::onModelLayerRemoved ( ModelLayer layer)

Definition at line 427 of file MapNode.cpp.

{
    if ( layer )
    {
        layer->removeCallback( _modelLayerCallback.get() );

        // look up the node associated with this model layer.
        ModelLayerNodeMap::iterator i = _modelLayerNodes.find( layer );
        if ( i != _modelLayerNodes.end() )
        {
            osg::Node* node = i->second;

            if ( dynamic_cast<TerrainDecorator*>( node ) || dynamic_cast<osgSim::OverlayNode*>( node ) )
            {
                removeTerrainDecorator( node->asGroup() );
            }
            else
            {
                if ( layer->getModelLayerOptions().overlay() == true )
                {
                    _overlayModels->removeChild( node );
                    updateOverlayGraph();
                }
                else
                {
                    _models->removeChild( node );
                }
            }
            
            _modelLayerNodes.erase( i );
        }
        
        dirtyBound();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MapNode::removeTerrainDecorator ( osg::Group *  decorator)

Removes a node previously added via addTerrainDecorator.

Definition at line 516 of file MapNode.cpp.

{
    if ( _terrainEngine.valid() )
    {
        TerrainDecorator* td = dynamic_cast<TerrainDecorator*>( decorator );
        if ( td )
            td->onUninstall( _terrainEngine.get() );

        osg::Node* child = _terrainEngine.get();
        for( osg::Group* g = child->getParent(0); g != _terrainEngineContainer.get(); )
        {
            if ( g == decorator )
            {
                g->getParent(0)->replaceChild( g, child );
                g->removeChild( child );
                break;
            }
            child = g;
            g = g->getParent(0);
        }
        dirtyBound();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 549 of file MapNode.cpp.

{
    if ( nv.getVisitorType() == osg::NodeVisitor::EVENT_VISITOR )
    {
        unsigned int numBlacklist = Registry::instance()->getNumBlacklistedFilenames();
        if (numBlacklist != _lastNumBlacklistedFilenames)
        {
            //Only remove the blacklisted filenames if new filenames have been added since last time.
            _lastNumBlacklistedFilenames = numBlacklist;
            RemoveBlacklistedFilenamesVisitor v;
            //accept( v );
            _terrainEngine->accept( v );
        }
    }

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

Here is the call graph for this function:

void MapNode::updateOverlayGraph ( )

If you add or remove children to/fro the overlay group above, call this method to refresh the overlay graph.

Definition at line 586 of file MapNode.cpp.

{
    if ( _overlayModels->getNumChildren() > 0 && _overlayDecorator->getOverlayGraph() != _overlayModels.get() )
    {
        _overlayDecorator->setOverlayGraph( _overlayModels.get() );
    }
    else if ( _overlayModels->getNumChildren() == 0 && _overlayDecorator->getOverlayGraph() == _overlayModels.get() )
    {
        _overlayDecorator->setOverlayGraph( 0L );
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 179 of file MapNode.

unsigned int osgEarth::MapNode::_id [private]

Definition at line 173 of file MapNode.

Definition at line 189 of file MapNode.

osg::ref_ptr<Map> osgEarth::MapNode::_map [private]

Definition at line 174 of file MapNode.

osg::ref_ptr< MapCallback > osgEarth::MapNode::_mapCallback [private]

Definition at line 212 of file MapNode.

Definition at line 178 of file MapNode.

osg::Group* osgEarth::MapNode::_maskLayerNode [private]

Definition at line 184 of file MapNode.

Definition at line 211 of file MapNode.

Definition at line 183 of file MapNode.

osg::ref_ptr< osg::Group > osgEarth::MapNode::_models [private]

Definition at line 175 of file MapNode.

Definition at line 177 of file MapNode.

osg::ref_ptr< osg::Group > osgEarth::MapNode::_overlayModels [private]

Definition at line 176 of file MapNode.

Definition at line 187 of file MapNode.

osg::ref_ptr< osgSim::OverlayNode > osgEarth::MapNode::_pendingOverlayNode [private]

Definition at line 186 of file MapNode.

Definition at line 191 of file MapNode.

osg::ref_ptr<osg::Group> osgEarth::MapNode::_terrainEngineContainer [private]

Definition at line 194 of file MapNode.

Definition at line 192 of file MapNode.


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