本文整理汇总了C++中osg::NodeVisitor::getUserData方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeVisitor::getUserData方法的具体用法?C++ NodeVisitor::getUserData怎么用?C++ NodeVisitor::getUserData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::NodeVisitor
的用法示例。
在下文中一共展示了NodeVisitor::getUserData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
TileNode::cull_stealth(osg::NodeVisitor& nv)
{
if ( !isDormant(nv.getFrameStamp()) )
{
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( &nv );
EngineContext* context = static_cast<EngineContext*>( nv.getUserData() );
if ( getNumChildren() == 4 )
{
unsigned before = RenderBinUtils::getTotalNumRenderLeaves( cv->getRenderStage() );
for(int i=0; i<4; ++i)
{
_children[i]->accept( nv );
}
unsigned after = RenderBinUtils::getTotalNumRenderLeaves( cv->getRenderStage() );
if ( after == before )
{
acceptSurface( cv, context );
}
}
else if ( _surface.valid() )
{
acceptSurface( cv, context );
}
}
}
示例2: if
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 );
}
}
示例3: lock
void
TileNode::load(osg::NodeVisitor& nv)
{
// Access the context:
EngineContext* context = static_cast<EngineContext*>( nv.getUserData() );
// Create a new load request on demand:
if ( !_loadRequest.valid() )
{
Threading::ScopedMutexLock lock(_mutex);
if ( !_loadRequest.valid() )
{
_loadRequest = new LoadTileData( this, context );
_loadRequest->setName( _key.str() );
_loadRequest->setTileKey( _key );
}
}
// Prioritize by LOD. (negated because lower order gets priority)
float priority = - (float)getTileKey().getLOD();
if ( context->getOptions().highResolutionFirst() == true )
priority = -priority;
// then sort by distance within each LOD.
float distance = nv.getDistanceToViewPoint( getBound().center(), true );
priority = 10.0f*priority - log10(distance);
// testing intermediate loading idea...
//if ( getTileKey().getLOD() == 5 )
// priority += 100.0f;
// Submit to the loader.
context->getLoader()->load( _loadRequest.get(), priority, nv );
}
示例4: lock
void
TileNode::expireChildren(osg::NodeVisitor& nv)
{
OE_DEBUG << LC << "Expiring children of " << getTileKey().str() << "\n";
EngineContext* context = static_cast<EngineContext*>( nv.getUserData() );
if ( !_expireRequest.valid() )
{
Threading::ScopedMutexLock lock(_mutex);
if ( !_expireRequest.valid() )
{
_expireRequest = new ExpireTiles(this, context);
_expireRequest->setName( getTileKey().str() + " expire" );
_expireRequest->setTileKey( _key );
}
}
// Low priority for expiry requests.
const float lowPriority = -100.0f;
context->getLoader()->load( _expireRequest.get(), lowPriority, nv );
}
示例5: cull
void TileNode::cull(osg::NodeVisitor& nv)
{
if ( nv.getFrameStamp() )
{
_lastTraversalFrame.exchange( nv.getFrameStamp()->getFrameNumber() );
}
unsigned currLOD = getTileKey().getLOD();
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( &nv );
EngineContext* context = static_cast<EngineContext*>( nv.getUserData() );
const SelectionInfo& selectionInfo = context->getSelectionInfo();
if ( context->progress() )
context->progress()->stats()["TileNode::cull"]++;
// determine whether we can and should subdivide to a higher resolution:
bool subdivide =
shouldSubDivide(nv, selectionInfo, cv->getLODScale());
// whether it is OK to create child TileNodes is necessary.
bool canCreateChildren = subdivide;
// whether it is OK to load data if necessary.
bool canLoadData = true;
if ( _dirty && context->getOptions().progressive() == true )
{
// Don't create children in progressive mode until content is in place
canCreateChildren = false;
}
else
{
// If this is an inherit-viewpoint camera, we don't need it to invoke subdivision
// because we want only the tiles loaded by the true viewpoint.
const osg::Camera* cam = cv->getCurrentCamera();
if ( cam && cam->getReferenceFrame() == osg::Camera::ABSOLUTE_RF_INHERIT_VIEWPOINT )
{
canCreateChildren = false;
canLoadData = false;
}
}
optional<bool> surfaceVisible;
// If *any* of the children are visible, subdivide.
if (subdivide)
{
// We are in range of the child nodes. Either draw them or load them.
// If the children don't exist, create them and inherit the parent's data.
if ( getNumChildren() == 0 && canCreateChildren )
{
Threading::ScopedMutexLock exclusive(_mutex);
if ( getNumChildren() == 0 )
{
createChildren( context );
}
}
// If all are ready, traverse them now.
if ( getNumChildren() == 4 )
{
for(int i=0; i<4; ++i)
{
_children[i]->accept( nv );
}
}
// If we don't traverse the children, traverse this node's payload.
else if ( _surface.valid() )
{
surfaceVisible = acceptSurface( cv, context );
}
}
// If children are outside camera range, draw the payload and expire the children.
else if ( _surface.valid() )
{
surfaceVisible = acceptSurface( cv, context );
if ( getNumChildren() >= 4 && context->maxLiveTilesExceeded() )
{
if (getSubTile(0)->isDormant( nv ) &&
getSubTile(1)->isDormant( nv ) &&
getSubTile(2)->isDormant( nv ) &&
getSubTile(3)->isDormant( nv ))
{
expireChildren( nv );
}
}
}
// Traverse land cover data at this LOD.
int zoneIndex = context->_landCoverData->_currentZoneIndex;
if ( zoneIndex < (int)context->_landCoverData->_zones.size() )
//.........这里部分代码省略.........
示例6: QuickReleaseGLObjects
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 );
}
}
示例7: cull
void TileNode::cull(osg::NodeVisitor& nv)
{
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( &nv );
EngineContext* context = static_cast<EngineContext*>( nv.getUserData() );
const SelectionInfo& selectionInfo = context->getSelectionInfo();
// record the number of drawables before culling this node:
unsigned before = RenderBinUtils::getTotalNumRenderLeaves( cv->getRenderStage() );
if ( context->progress() )
context->progress()->stats()["TileNode::cull"]++;
// determine whether we can and should subdivide to a higher resolution:
bool subdivide = shouldSubDivide(nv, selectionInfo, cv->getLODScale());
// whether it is OK to create child TileNodes is necessary.
bool canCreateChildren = subdivide;
// whether it is OK to load data if necessary.
bool canLoadData = true;
if ( _dirty && context->getOptions().progressive() == true )
{
// Don't create children in progressive mode until content is in place
canCreateChildren = false;
}
// If this is an inherit-viewpoint camera, we don't need it to invoke subdivision
// because we want only the tiles loaded by the true viewpoint.
const osg::Camera* cam = cv->getCurrentCamera();
if ( cam && cam->getReferenceFrame() == osg::Camera::ABSOLUTE_RF_INHERIT_VIEWPOINT )
{
canCreateChildren = false;
canLoadData = false;
}
optional<bool> surfaceVisible( false );
if (subdivide)
{
// We are in range of the child nodes. Either draw them or load them.
// If the children don't exist, create them and inherit the parent's data.
if ( getNumChildren() == 0 && canCreateChildren )
{
Threading::ScopedMutexLock exclusive(_mutex);
if ( getNumChildren() == 0 )
{
createChildren( context );
}
}
// If all are ready, traverse them now.
if ( getNumChildren() == 4 )
{
for(int i=0; i<4; ++i)
{
// pre-check each child for simple bounding sphere culling, and if the check
// fails, unload it's children if them exist. This lets us unload dormant
// tiles from memory as we go. If those children are visible from another
// camera, no worries, the unload attempt will fail gracefully.
if (!cv->isCulled(*_children[i].get()))
{
_children[i]->accept( nv );
}
else
{
context->getUnloader()->unloadChildren(getSubTile(i)->getTileKey());
}
}
}
// If we don't traverse the children, traverse this node's payload.
else if ( _surface.valid() )
{
surfaceVisible = acceptSurface( cv, context );
}
}
// If children are outside camera range, draw the payload and expire the children.
else if ( _surface.valid() )
{
surfaceVisible = acceptSurface( cv, context );
// if children exists, and are not in the process of loading, unload them now.
if ( !_dirty && _children.size() > 0 )
{
context->getUnloader()->unloadChildren( this->getTileKey() );
}
}
// See whether we actually added any drawables.
unsigned after = RenderBinUtils::getTotalNumRenderLeaves( cv->getRenderStage() );
bool addedDrawables = (after > before);
// Only continue if we accepted at least one surface drawable.
if ( addedDrawables )
{
//.........这里部分代码省略.........
示例8: cull
void TileNode::cull(osg::NodeVisitor& nv)
{
if ( nv.getFrameStamp() )
{
_lastTraversalFrame.exchange( nv.getFrameStamp()->getFrameNumber() );
}
unsigned currLOD = getTileKey().getLOD();
#if OSGEARTH_REX_TILE_NODE_DEBUG_TRAVERSAL
if (currLOD==0)
{
OE_INFO << LC <<"Traversing: "<<"\n";
}
#endif
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( &nv );
EngineContext* context = static_cast<EngineContext*>( nv.getUserData() );
const SelectionInfo& selectionInfo = context->getSelectionInfo();
// determine whether we can and should subdivide to a higher resolution:
bool subdivide = shouldSubDivide(nv, selectionInfo, cv->getLODScale());
// If this is an inherit-viewpoint camera, we don't need it to invoke subdivision
// because we want only the tiles loaded by the true viewpoint.
bool canCreateChildren = subdivide;
const osg::Camera* cam = cv->getCurrentCamera();
if ( cam && cam->getReferenceFrame() == osg::Camera::ABSOLUTE_RF_INHERIT_VIEWPOINT )
{
canCreateChildren = false;
}
// If *any* of the children are visible, subdivide.
if (subdivide)
{
// We are in range of the child nodes. Either draw them or load them.
// If the children don't exist, create them and inherit the parent's data.
if ( getNumChildren() == 0 && canCreateChildren )
{
Threading::ScopedMutexLock exclusive(_mutex);
if ( getNumChildren() == 0 )
{
createChildren( context );
}
}
// All 4 children must be ready before we can traverse any of them:
unsigned numChildrenReady = 0;
if ( getNumChildren() == 4 )
{
for(unsigned i = 0; i < 4; ++i)
{
if ( getSubTile(i)->isReadyToTraverse() )
{
++numChildrenReady;
}
}
}
// If all are ready, traverse them now.
if ( numChildrenReady == 4 )
{
// TODO:
// When we do this, we need to quite sure that all 4 children will be accepted into
// the draw set. Perhaps isReadyToTraverse() needs to check that.
_children[0]->accept( nv );
_children[1]->accept( nv );
_children[2]->accept( nv );
_children[3]->accept( nv );
}
// If we don't traverse the children, traverse this node's payload.
else if ( _surface.valid() )
{
cullSurface( cv );
}
}
// If children are outside camera range, draw the payload and expire the children.
else if ( _surface.valid() )
{
cullSurface( cv );
if ( getNumChildren() >= 4 && context->maxLiveTilesExceeded() )
{
if (getSubTile(0)->isDormant( nv ) &&
getSubTile(1)->isDormant( nv ) &&
getSubTile(2)->isDormant( nv ) &&
getSubTile(3)->isDormant( nv ))
{
expireChildren( nv );
}
}
}
// Traverse land cover bins at this LOD.
for(int i=0; i<context->landCoverBins()->size(); ++i)
{
bool first = true;
//.........这里部分代码省略.........
示例9: if
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 );
}
}