本文整理汇总了C++中osg::NodeVisitor类的典型用法代码示例。如果您正苦于以下问题:C++ NodeVisitor类的具体用法?C++ NodeVisitor怎么用?C++ NodeVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
void
TerrainEngineNode::traverse( osg::NodeVisitor& nv )
{
if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
{
// see if we need to set up the Terrain object with an update ops queue.
if ( !_terrainInterface->_updateOperationQueue.valid() )
{
static Threading::Mutex s_opqlock;
Threading::ScopedMutexLock lock(s_opqlock);
if ( !_terrainInterface->_updateOperationQueue.valid() ) // double check pattern
{
//TODO: think, will this work with >1 view?
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( &nv );
if ( cv->getCurrentCamera() )
{
osgViewer::View* view = dynamic_cast<osgViewer::View*>(cv->getCurrentCamera()->getView());
if ( view && view->getViewerBase() )
{
osg::OperationQueue* q = view->getViewerBase()->getUpdateOperations();
if ( !q ) {
q = new osg::OperationQueue();
view->getViewerBase()->setUpdateOperations( q );
}
_terrainInterface->_updateOperationQueue = q;
}
}
}
}
if ( Registry::instance()->getCapabilities().supportsGLSL() )
{
_updateLightingUniformsHelper.cullTraverse( this, &nv );
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( &nv );
if ( cv )
{
osg::Vec3d eye = cv->getEyePoint();
float elevation;
if ( _map->isGeocentric() )
elevation = eye.length() - osg::WGS_84_RADIUS_EQUATOR;
else
elevation = eye.z();
_cameraElevationUniform->set( elevation );
}
}
}
else if ( nv.getVisitorType() == osg::NodeVisitor::EVENT_VISITOR )
{
_dirtyCount = 0;
}
osg::CoordinateSystemNode::traverse( nv );
}
示例2: traverse
void ElevationLOD::traverse( osg::NodeVisitor& nv)
{
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR &&
nv.getTraversalMode() == osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN )
{
bool rangeOK = true;
bool altitudeOK = true;
// first test the range:
if ( _minRange.isSet() || _maxRange.isSet() )
{
float range = nv.getDistanceToViewPoint( getBound().center(), true );
rangeOK =
(!_minRange.isSet() || (range >= *_minRange)) &&
(!_maxRange.isSet() || (range <= *_maxRange));
}
if ( rangeOK )
{
if ( _minElevation.isSet() || _maxElevation.isSet() )
{
double alt;
// first see if we have a precalculated elevation:
osgUtil::CullVisitor* cv = Culling::asCullVisitor(nv);
osg::Vec3d eye = cv->getViewPoint();
if ( _srs && !_srs->isProjected() )
{
GeoPoint mapPoint;
mapPoint.fromWorld( _srs.get(), eye );
alt = mapPoint.z();
}
else
{
alt = eye.z();
}
// account for the LOD scale
alt *= cv->getLODScale();
altitudeOK =
(!_minElevation.isSet() || (alt >= *_minElevation)) &&
(!_maxElevation.isSet() || (alt <= *_maxElevation));
}
if ( altitudeOK )
{
std::for_each(_children.begin(),_children.end(),osg::NodeAcceptOp(nv));
}
}
}
else
{
osg::Group::traverse( nv );
}
}
示例3: if
void
HTMNode::traverse(osg::NodeVisitor& nv)
{
if ( nv.getVisitorType() == nv.CULL_VISITOR )
{
//OE_INFO << getName() << std::endl;
#if 0
if ( _isLeaf )
{
if (_settings._debugFrame != nv.getFrameStamp()->getFrameNumber())
{
OE_NOTICE << "Frame " << _settings._debugFrame << ": " << _settings._debugCount << std::endl;
_settings._debugCount = 0;
_settings._debugFrame = nv.getFrameStamp()->getFrameNumber();
}
_settings._debugCount += getNumChildren();
}
#endif
const osg::BoundingSphere& bs = getBound();
float range = nv.getDistanceToViewPoint(bs.center(), true);
bool inRange = false;
if (_settings._maxRange.isSet() == false)
{
inRange = range < (bs.radius() * _settings._rangeFactor.get());
}
else
{
inRange = range < (bs.radius() + _settings._maxRange.get());
}
if ( inRange )
{
osg::Group::traverse( nv );
if (_debug.valid() && _isLeaf)
{
_debug->accept(nv);
}
}
else if (_debug.valid())
{
_debug->accept(nv);
}
}
else
{
if (_debug.valid())
{
_debug->accept(nv);
}
osg::Group::traverse( nv );
}
}
示例4: if
void
OrthoNode::traverse( osg::NodeVisitor& nv )
{
osgUtil::CullVisitor* cv = 0L;
if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
{
cv = Culling::asCullVisitor(nv);
// make sure that we're NOT using the AutoTransform if this node is in the decluttering bin;
// the decluttering bin automatically manages screen space transformation.
bool declutter = cv->getCurrentRenderBin()->getName() == OSGEARTH_DECLUTTER_BIN;
if ( declutter && _switch->getValue(0) == 1 )
{
_switch->setSingleChildOn( 1 );
}
else if ( !declutter && _switch->getValue(0) == 0 )
{
_switch->setSingleChildOn( 0 );
}
// If decluttering is enabled, update the auto-transform but not its children.
// This is necessary to support picking/selection. An optimization would be to
// disable this pass when picking is not in use
if ( declutter )
{
static_cast<AnnotationUtils::OrthoNodeAutoTransform*>(_autoxform)->acceptCullNoTraverse( cv );
}
// turn off small feature culling
cv->setSmallFeatureCullingPixelSize(0.0f);
AnnotationNode::traverse( nv );
if ( this->getCullingActive() == false )
this->setCullingActive( true );
}
// For an intersection visitor, ALWAYS traverse the autoxform instead of the
// matrix transform. The matrix transform is only used in combination with the
// decluttering engine, so it cannot properly support picking of decluttered
// objects
else if (
nv.getVisitorType() == osg::NodeVisitor::NODE_VISITOR &&
dynamic_cast<osgUtil::IntersectionVisitor*>( &nv ) )
{
if ( static_cast<AnnotationUtils::OrthoNodeAutoTransform*>(_autoxform)->okToIntersect() )
{
_autoxform->accept( nv );
}
}
else
{
AnnotationNode::traverse( nv );
}
}
示例5: getPerViewData
void
OverlayDecorator::traverse( osg::NodeVisitor& nv )
{
if ( _overlayGraph.valid() && _textureUnit.isSet() )
{
// in the CULL traversal, find the per-view data associated with the
// cull visitor's current camera view and work with that:
if ( nv.getVisitorType() == nv.CULL_VISITOR )
{
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( &nv );
osg::Camera* camera = cv->getCurrentCamera();
if ( camera != 0L && (_rttTraversalMask & nv.getTraversalMask()) != 0 )
{
PerViewData& pvd = getPerViewData( camera );
if (checkNeedsUpdate(pvd))
{
updateRTTCamera(pvd);
}
if ( pvd._texGen.valid() )
{
// FFP path only
cv->getCurrentRenderBin()->getStage()->addPositionedTextureAttribute(
*_textureUnit, cv->getModelViewMatrix(), pvd._texGen.get() );
}
cull( cv, pvd );
pvd._rttCamera->accept( nv );
}
else
{
osg::Group::traverse(nv);
}
// debug-- (draws the overlay at its native location as well)
//_overlayGraph->accept(nv);
}
else
{
// Some other type of visitor (like update or intersection). Skip the RTT camera
// and traverse the overlay graph directly.
if ( _overlayGraph.valid() )
{
_overlayGraph->accept( nv );
}
osg::Group::traverse( nv );
}
}
else
{
osg::Group::traverse( nv );
}
}
示例6: if
void
SilverLiningContextNode::traverse(osg::NodeVisitor& nv)
{
if ( _SL && _SL->ready() )
{
if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
{
int frameNumber = nv.getFrameStamp()->getFrameNumber();
_skyDrawable->dirtyBound();
if( _cloudsDrawable )
{
if ( _lastAltitude <= *_options.cloudsMaxAltitude() )
{
if ( _cloudsDrawable->getNumParents() == 0 )
_geode->addDrawable( _cloudsDrawable.get() );
_cloudsDrawable->dirtyBound();
}
else
{
if ( _cloudsDrawable->getNumParents() > 0 )
_geode->removeDrawable( _cloudsDrawable.get() );
}
}
}
else if ( nv.getVisitorType() == nv.CULL_VISITOR )
{
osgUtil::CullVisitor* cv = Culling::asCullVisitor(nv);
osg::Camera* camera = cv->getCurrentCamera();
if ( camera )
{
#ifndef SL_USE_CULL_MASK
//Check if this is the target camera for this context
if(getTargetCamera() == camera)
#endif
{
// TODO: make this multi-camera safe
_SL->setCameraPosition( nv.getEyePoint() );
_lastAltitude = _SL->getSRS()->isGeographic() ?
cv->getEyePoint().length() - _SL->getSRS()->getEllipsoid()->getRadiusEquator() :
cv->getEyePoint().z();
_SL->updateLocation();
_SL->updateLight();
}
}
}
}
if ( _geode.valid() )
{
_geode->accept(nv);
}
}
示例7:
void
TritonNode::traverse(osg::NodeVisitor& nv)
{
if ( nv.getVisitorType() == nv.UPDATE_VISITOR && _TRITON->ready() )
{
_TRITON->update(nv.getFrameStamp()->getSimulationTime());
}
osgEarth::Util::OceanNode::traverse(nv);
}
示例8:
void
GeoCell::traverse( osg::NodeVisitor& nv )
{
bool isCull = nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR;
if ( _depth > 0 )
{
if ( isCull )
{
// process boundary geometry, if present.
if ( _boundaryGeode.valid() )
{
if ( _count > 0 )
(*_boundaryColor)[0].set(1,0,0,0.35);
else
(*_boundaryColor)[0].set(1,1,1,0.25);
_boundaryColor->dirty();
_boundaryGeode->accept( nv );
}
// custom BSP culling function. this checks that the set of boundary points
// for this cell intersects the viewing frustum.
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( &nv );
if ( cv && !intersects( cv->getCurrentCullingSet().getFrustum() ) )
{
return;
}
// passed cull, so record the framestamp.
_frameStamp = cv->getFrameStamp()->getFrameNumber();
}
if ( _objects.size() > 0 )
{
for( GeoObjectCollection::iterator i = _objects.begin(); i != _objects.end(); ++i )
{
osg::Node* node = i->second->getNode();
if ( node )
node->accept( nv );
}
}
if ( _clusterGeode.valid() )
_clusterGeode->accept( nv );
}
else
{
if ( isCull )
_frameStamp = nv.getFrameStamp()->getFrameNumber();
}
osg::LOD::traverse( nv );
}
示例9:
void
TilePagedLOD::traverse(osg::NodeVisitor& nv)
{
if (_progress.valid() &&
nv.getVisitorType() == nv.CULL_VISITOR &&
nv.getFrameStamp() )
{
_progress->update( nv.getFrameStamp()->getFrameNumber() );
}
osg::PagedLOD::traverse(nv);
}
示例10:
void
GeoCell::traverse( osg::NodeVisitor& nv )
{
bool isCull = nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR;
if ( _depth > 0 )
{
if ( isCull )
{
// process boundary geometry, if present.
if ( _boundaryGeode.valid() )
{
if ( _count > 0 )
(*_boundaryColor)[0].set(1,0,0,0.35);
else
(*_boundaryColor)[0].set(1,1,1,0.25);
_boundaryColor->dirty();
_boundaryGeode->accept( nv );
}
osgUtil::CullVisitor* cv = Culling::asCullVisitor(nv);
if ( cv )
{
// passed cull, so record the framestamp.
_frameStamp = cv->getFrameStamp()->getFrameNumber();
}
}
if ( _objects.size() > 0 )
{
for( GeoObjectCollection::iterator i = _objects.begin(); i != _objects.end(); ++i )
{
osg::Node* node = i->second->getNode();
if ( node )
node->accept( nv );
}
}
if ( _clusterGeode.valid() )
_clusterGeode->accept( nv );
}
else
{
if ( isCull )
_frameStamp = nv.getFrameStamp()->getFrameNumber();
}
osg::LOD::traverse( nv );
}
示例11: updateFocus
void Widget::traverseImplementation(osg::NodeVisitor& nv)
{
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
if (ev)
{
if (_visible && _enabled)
{
updateFocus(nv);
// OSG_NOTICE<<"EventTraversal getHasEventFocus()="<<getHasEventFocus()<<std::endl;
// signify that event has been taken by widget with focus
osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
if (handle(ev, itr->get()))
{
(*itr)->setHandled(true);
ev->setEventHandled(true);
}
}
osg::Group::traverse(nv);
}
}
else if (_visible ||
(nv.getVisitorType()!=osg::NodeVisitor::UPDATE_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::INTERSECTION_VISITOR) )
{
GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
while(itr!= _graphicsSubgraphMap.end() && itr->first<=0)
{
itr->second->accept(nv);
++itr;
}
Group::traverse(nv);
while(itr!= _graphicsSubgraphMap.end())
{
itr->second->accept(nv);
++itr;
}
}
}
示例12: 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 );
}
}
#if 0
double range0, range1;
int lod = getTileKey().getLOD();
if ( lod > context->getOptions().firstLOD().get() )
range0 = context->getSelectionInfo().visParameters(lod-1)._visibilityRange;
else
range0 = 0.0;
double range1 = context->getSelectionInfo().visParameters(lod)._visibilityRange;
priority =
#endif
// Prioritize by LOD. (negated because lower order gets priority)
float priority = - (float)getTileKey().getLOD();
if ( context->getOptions().highResolutionFirst() == true )
{
priority = context->getSelectionInfo().numLods() - priority;
//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 );
}
示例13: if
void
DrapeableNode::traverse( osg::NodeVisitor& nv )
{
if ( !_overlayProxyContainer.valid() )
{
osg::Group::traverse( nv );
}
else
{
if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
{
if ( _draped )
{
// for a draped node, inform the proxy that we are visible. But do NOT traverse the
// child graph (since it will be traversed by the OverlayDecorator).
CullNodeByFrameNumber* cb = static_cast<CullNodeByFrameNumber*>(_overlayProxyContainer->getCullCallback());
if (cb)
{
cb->_frame = nv.getFrameStamp()->getFrameNumber();
}
}
else
{
// for a non-draped node, just traverse children as usual.
osg::Group::traverse( nv );
}
}
else if ( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
{
if ( _dirty )
{
applyChanges();
_dirty = false;
ADJUST_UPDATE_TRAV_COUNT( this, -1 );
}
// traverse children directly, regardles of draped status
osg::Group::traverse( nv );
}
// handle other visitor types (like intersections, etc) by simply
// traversing the child graph.
else // if ( nv.getNodeVisitor() == osg::NodeVisitor::NODE_VISITOR )
{
osg::Group::traverse( nv );
}
}
}
示例14: OSG_MIN_VERSION_REQUIRED
void MultiPassTerrainTechnique::traverse(osg::NodeVisitor& nv)
{
if (!_tile) return;
// initialize the terrain tile on startup
if (_tile->getDirty() && !_terrainTileInitialized)
{
_tile->init();
_terrainTileInitialized = true;
#if 0
#if OSG_MIN_VERSION_REQUIRED(2,9,8)
_terrainTile->init(~0x0, true);
#else
_terrainTile->init();
#endif
_terrainTileInitialized = true;
#endif
}
if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
{
updateTransparency();
}
// traverse the dynamically-generated geometry.
if (_transform.valid())
_transform->accept(nv);
}
示例15: QuickReleaseGLObjects
void
TerrainNode::traverse( osg::NodeVisitor &nv )
{
if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
{
// if the terrain engine requested "quick release", install the quick release
// draw callback now.
if ( !_quickReleaseCallbackInstalled && _tilesToQuickRelease.valid() )
{
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(
_tilesToQuickRelease.get(),
cbToNest ) );
_quickReleaseCallbackInstalled = true;
OE_INFO << LC << "Quick release enabled" << std::endl;
// knock down the trav count set in the constructor.
ADJUST_UPDATE_TRAV_COUNT( this, -1 );
}
}
}
osg::Group::traverse( nv );
}