Beispiel #1
0
void
MapNode::traverse( osg::NodeVisitor& nv )
{
    if ( nv.getVisitorType() == nv.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;
            _terrainEngine->accept( v );
        }

        // traverse:
        std::for_each( _children.begin(), _children.end(), osg::NodeAcceptOp(nv) );
    }

    else if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
    {
        osg::ref_ptr<osg::Referenced> oldUserData = nv.getUserData();
        nv.setUserData( this );
        std::for_each( _children.begin(), _children.end(), osg::NodeAcceptOp(nv) );
        nv.setUserData( oldUserData.get() );
    }

    else
    {
        osg::Group::traverse( nv );
    }
}
void
RexTerrainEngineNode::traverse(osg::NodeVisitor& nv)
{
    if ( nv.getVisitorType() == nv.UPDATE_VISITOR && _quickReleaseInstalled == false )
    {
        osg::Camera* cam = findFirstParentOfType<osg::Camera>( this );
        if ( cam )
        {
            // get the installed PDC so we can nest them:
            osg::Camera::DrawCallback* cbToNest = cam->getPostDrawCallback();

            // if it's another QR callback, we'll just replace it.
            QuickReleaseGLObjects* previousQR = dynamic_cast<QuickReleaseGLObjects*>(cbToNest);
            if ( previousQR )
                cbToNest = previousQR->_next.get();

            cam->setPostDrawCallback( new QuickReleaseGLObjects(_deadTiles.get(), cbToNest) );

            _quickReleaseInstalled = true;
            OE_INFO << LC << "Quick release enabled" << std::endl;

            // knock down the trav count set in the constructor.
            ADJUST_UPDATE_TRAV_COUNT( this, -1 );
        }
    }

    if ( nv.getVisitorType() == nv.CULL_VISITOR )
    {
        // Inform the registry of the current frame so that Tiles have access
        // to the information.
        if ( _liveTiles.valid() && nv.getFrameStamp() )
        {
            _liveTiles->setTraversalFrame( nv.getFrameStamp()->getFrameNumber() );
        }
    }

#if 0
    static int c = 0;
    if ( ++c % 60 == 0 )
    {
        OE_NOTICE << LC << "Live = " << _liveTiles->size() << ", Dead = " << _deadTiles->size() << std::endl;
        _liveTiles->run( CheckForOrphans() );
    }
#endif
    
    if ( _loader.valid() ) // ensures that postInitialize has run
    {
        TraversalData* tdata = TraversalData::get(nv);
        if ( tdata )
        {
            RefUID& uid = tdata->getOrCreate<RefUID>("landcover.zone");
            getEngineContext()->_landCoverData->_currentZoneIndex = uid;
        }

        // Pass the tile creation context to the traversal.
        osg::ref_ptr<osg::Referenced> data = nv.getUserData();
        nv.setUserData( this->getEngineContext() );

        osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(&nv);

        this->getEngineContext()->startCull( cv );
        TerrainEngineNode::traverse( nv );
        this->getEngineContext()->endCull( cv );

        if ( data.valid() )
            nv.setUserData( data.get() );
    }

    else
    {
        TerrainEngineNode::traverse( nv );
    }
}
Beispiel #3
0
void
MapNode::traverse( osg::NodeVisitor& nv )
{
    if ( nv.getVisitorType() == nv.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;
            _terrainEngine->accept( v );
        }

        // traverse:
        std::for_each( _children.begin(), _children.end(), osg::NodeAcceptOp(nv) );
    }

    else if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
    {
        osg::ref_ptr<osg::Referenced> oldUserData = nv.getUserData();
        nv.setUserData( this );
        std::for_each( _children.begin(), _children.end(), osg::NodeAcceptOp(nv) );
        nv.setUserData( oldUserData.get() );
    }

    else if ( nv.getVisitorType() == nv.CULL_VISITOR )
    {
        osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(&nv);
        if ( cv )
        {
#if 1
            osg::ref_ptr<osg::Referenced> oldUserData = cv->getUserData();
            
            TraversalData* data = new TraversalData();
            cv->setUserData( data );
            
            std::for_each( _children.begin(), _children.end(), osg::NodeAcceptOp(nv) );

            cv->setUserData( oldUserData.get() );
#else

            // insert traversal data for this camera:
            osg::ref_ptr<osg::Referenced> oldUserData = cv->getUserData();
            MapNodeCullData* cullData = getCullData( cv->getCurrentCamera() );
            cv->setUserData( cullData );

            cullData->_mapNode = this;

            osg::Vec3d eye = cv->getViewPoint();

            // horizon:
            if ( !cullData->_horizonInitialized )
            {
                cullData->_horizonInitialized = true;
                cullData->_horizon.setEllipsoid( *getMapSRS()->getEllipsoid() );
            }
            cullData->_horizon.setEye( eye );

            // calculate altitude:
            const SpatialReference* srs = getMapSRS();
            if ( srs && !srs->isProjected() )
            {
                GeoPoint lla;
                lla.fromWorld( srs, eye );
                cullData->_cameraAltitude = lla.alt();
                cullData->_cameraAltitudeUniform->set( (float)lla.alt() );
            }
            else
            {
                cullData->_cameraAltitude = eye.z();
                cullData->_cameraAltitudeUniform->set( (float)eye.z() );
            }

            // window matrix:
            cullData->_windowMatrixUniform->set( cv->getWindowMatrix() );

            // traverse:
            cv->pushStateSet( cullData->_stateSet.get() );
            std::for_each( _children.begin(), _children.end(), osg::NodeAcceptOp(nv) );
            cv->popStateSet();

            // restore:
            cv->setUserData( oldUserData.get() );
#endif
        }
    }

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