Added more osg::Object::as*() methods and usage of these through the code base to avoid use of dynamic_cast<> when using UpdateVisitor/CullVisitor/EventVIisitor etc.

This commit is contained in:
Robert Osfield 2016-01-20 15:13:19 +00:00
parent 2e7cfe7efa
commit 1219a6d3bf
38 changed files with 148 additions and 60 deletions

View File

@ -102,7 +102,12 @@ class OSG_EXPORT Drawable : public Node
META_Node(osg, Drawable); META_Node(osg, Drawable);
/** Convert 'this' into a Drawable pointer if Object is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<Drawable*>(this).*/
virtual Drawable* asDrawable() { return this; } virtual Drawable* asDrawable() { return this; }
/** convert 'const this' into a const Drawable pointer if Object is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<const Drawable*>(this).*/
virtual const Drawable* asDrawable() const { return this; } virtual const Drawable* asDrawable() const { return this; }
/** Compute the DataVariance based on an assessment of callback etc.*/ /** Compute the DataVariance based on an assessment of callback etc.*/

View File

@ -103,6 +103,13 @@ class OSG_EXPORT Node : public Object
* Equivalent to dynamic_cast<const Node*>(this).*/ * Equivalent to dynamic_cast<const Node*>(this).*/
virtual const Node* asNode() const { return this; } virtual const Node* asNode() const { return this; }
/** convert 'this' into a Drawable pointer if Node is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Drawable* asDrawable() { return 0; }
/** convert 'const this' into a const Drawable pointer if Node is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<const Group*>(this).*/
virtual const Drawable* asDrawable() const { return 0; }
/** convert 'this' into a Geometry pointer if Node is a Geometry, otherwise return 0. /** convert 'this' into a Geometry pointer if Node is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/ * Equivalent to dynamic_cast<Group*>(this).*/
virtual Geometry* asGeometry() { return 0; } virtual Geometry* asGeometry() { return 0; }
@ -126,13 +133,6 @@ class OSG_EXPORT Node : public Object
virtual const Transform* asTransform() const { return 0; } virtual const Transform* asTransform() const { return 0; }
/** Convert 'this' into a Camera pointer if Node is a Camera, otherwise return 0.
* Equivalent to dynamic_cast<Camera*>(this).*/
virtual Camera* asCamera() { return 0; }
/** convert 'const this' into a const Camera pointer if Node is a Camera, otherwise return 0.
* Equivalent to dynamic_cast<const Camera*>(this).*/
virtual const Camera* asCamera() const { return 0; }
/** Convert 'this' into a Switch pointer if Node is a Switch, otherwise return 0. /** Convert 'this' into a Switch pointer if Node is a Switch, otherwise return 0.
* Equivalent to dynamic_cast<Switch*>(this).*/ * Equivalent to dynamic_cast<Switch*>(this).*/

View File

@ -18,6 +18,10 @@
#include <osg/Matrix> #include <osg/Matrix>
#include <osg/FrameStamp> #include <osg/FrameStamp>
namespace osgUtil { class UpdateVisitor; class CullVisitor; class IntersectionVisitor; }
namespace osgGA { class EventVisitor; }
namespace osg { namespace osg {
class Billboard; class Billboard;
@ -44,6 +48,10 @@ class CameraView;
class Drawable; class Drawable;
class Geometry; class Geometry;
const unsigned int UNINITIALIZED_FRAME_NUMBER=0xffffffff; const unsigned int UNINITIALIZED_FRAME_NUMBER=0xffffffff;
#define META_NodeVisitor(library, name) \ #define META_NodeVisitor(library, name) \
@ -104,6 +112,40 @@ class OSG_EXPORT NodeVisitor : public virtual Object
* Equivalent to dynamic_cast<const NodeVisitor*>(this).*/ * Equivalent to dynamic_cast<const NodeVisitor*>(this).*/
virtual const NodeVisitor* asNodeVisitor() const { return this; } virtual const NodeVisitor* asNodeVisitor() const { return this; }
/** Convert 'this' into a osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgUtil::UpdateVisitor*>(this).*/
virtual osgUtil::UpdateVisitor* asUpdateVisitor() { return 0; }
/** convert 'const this' into a const osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgUtil::UpdateVisitor*>(this).*/
virtual const osgUtil::UpdateVisitor* asUpdateVisitor() const { return 0; }
/** Convert 'this' into a osgUtil::CullVisitor pointer if Object is a osgUtil::CullVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgUtil::CullVisitor*>(this).*/
virtual osgUtil::CullVisitor* asCullVisitor() { return 0; }
/** convert 'const this' into a const osgUtil::CullVisitor pointer if Object is a osgUtil::CullVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgUtil::CullVisitor*>(this).*/
virtual const osgUtil::CullVisitor* asCullVisitor() const { return 0; }
/** Convert 'this' into a osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgGA::EventVisitor*>(this).*/
virtual osgGA::EventVisitor* asEventVisitor() { return 0; }
/** convert 'const this' into a const osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgGA::EventVisitor*>(this).*/
virtual const osgGA::EventVisitor* asEventVisitor() const { return 0; }
/** Convert 'this' into a osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgUtil::IntersectionVisitor*>(this).*/
virtual osgUtil::IntersectionVisitor* asIntersectionVisitor() { return 0; }
/** convert 'const this' into a const osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgUtil::IntersectionVisitor*>(this).*/
virtual const osgUtil::IntersectionVisitor* asIntersectionVisitor() const { return 0; }
/** Method to call to reset visitor. Useful if your visitor accumulates /** Method to call to reset visitor. Useful if your visitor accumulates
state during a traversal, and you plan to reuse the visitor. state during a traversal, and you plan to reuse the visitor.

View File

@ -31,6 +31,8 @@ class Node;
class NodeVisitor; class NodeVisitor;
class StateAttribute; class StateAttribute;
class Uniform; class Uniform;
class Drawable;
class Camera;
class Callback; class Callback;
class CallbackObject; class CallbackObject;
@ -136,6 +138,14 @@ class OSG_EXPORT Object : public Referenced
* Equivalent to dynamic_cast<const Uniform*>(this).*/ * Equivalent to dynamic_cast<const Uniform*>(this).*/
virtual const Uniform* asUniform() const { return 0; } virtual const Uniform* asUniform() const { return 0; }
/** Convert 'this' into a Camera pointer if Node is a Camera, otherwise return 0.
* Equivalent to dynamic_cast<Camera*>(this).*/
virtual Camera* asCamera() { return 0; }
/** convert 'const this' into a const Camera pointer if Node is a Camera, otherwise return 0.
* Equivalent to dynamic_cast<const Camera*>(this).*/
virtual const Camera* asCamera() const { return 0; }
/** Convert 'this' into a Drawable pointer if Object is a Drawable, otherwise return 0. /** Convert 'this' into a Drawable pointer if Object is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<Drawable*>(this).*/ * Equivalent to dynamic_cast<Drawable*>(this).*/
virtual Drawable* asDrawable() { return 0; } virtual Drawable* asDrawable() { return 0; }

View File

@ -46,6 +46,14 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
META_NodeVisitor(osgGA, EventVisitor) META_NodeVisitor(osgGA, EventVisitor)
/** Convert 'this' into a osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgGA::EventVisitor*>(this).*/
virtual osgGA::EventVisitor* asEventVisitor() { return this; }
/** convert 'const this' into a const osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgGA::EventVisitor*>(this).*/
virtual const osgGA::EventVisitor* asEventVisitor() const { return this; }
void setActionAdapter(osgGA::GUIActionAdapter* actionAdapter) { _actionAdapter=actionAdapter; } void setActionAdapter(osgGA::GUIActionAdapter* actionAdapter) { _actionAdapter=actionAdapter; }
osgGA::GUIActionAdapter* getActionAdapter() { return _actionAdapter; } osgGA::GUIActionAdapter* getActionAdapter() { return _actionAdapter; }

View File

@ -59,6 +59,14 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
META_NodeVisitor(osgUtil, CullVisitor) META_NodeVisitor(osgUtil, CullVisitor)
/** Convert 'this' into a osgUtil::CullVisitor pointer if Object is a osgUtil::CullVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgUtil::CullVisitor*>(this).*/
virtual osgUtil::CullVisitor* asCullVisitor() { return this; }
/** convert 'const this' into a const osgUtil::CullVisitor pointer if Object is a osgUtil::CullVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgUtil::CullVisitor*>(this).*/
virtual const osgUtil::CullVisitor* asCullVisitor() const { return this; }
/** Create a shallow copy of the CullVisitor, used by CullVisitor::create() to clone the prototype. */ /** Create a shallow copy of the CullVisitor, used by CullVisitor::create() to clone the prototype. */
virtual CullVisitor* clone() const { return new CullVisitor(*this); } virtual CullVisitor* clone() const { return new CullVisitor(*this); }

View File

@ -56,7 +56,6 @@ class Intersector : public osg::Referenced
_disabledCount(0), _disabledCount(0),
_precisionHint(USE_DOUBLE_CALCULATIONS) {} _precisionHint(USE_DOUBLE_CALCULATIONS) {}
void setCoordinateFrame(CoordinateFrame cf) { _coordinateFrame = cf; } void setCoordinateFrame(CoordinateFrame cf) { _coordinateFrame = cf; }
CoordinateFrame getCoordinateFrame() const { return _coordinateFrame; } CoordinateFrame getCoordinateFrame() const { return _coordinateFrame; }
@ -168,8 +167,16 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
META_NodeVisitor(osgUtil, IntersectionVisitor) META_NodeVisitor(osgUtil, IntersectionVisitor)
virtual void reset(); /** Convert 'this' into a osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgUtil::IntersectionVisitor*>(this).*/
virtual osgUtil::IntersectionVisitor* asIntersectionVisitor() { return this; }
/** convert 'const this' into a const osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgUtil::IntersectionVisitor*>(this).*/
virtual const osgUtil::IntersectionVisitor* asIntersectionVisitor() const { return this; }
virtual void reset();
/** Set the intersector that will be used to intersect with the scene, and to store any hits that occur.*/ /** Set the intersector that will be used to intersect with the scene, and to store any hits that occur.*/
void setIntersector(Intersector* intersector); void setIntersector(Intersector* intersector);

View File

@ -43,6 +43,14 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
META_NodeVisitor(osgUtil, UpdateVisitor) META_NodeVisitor(osgUtil, UpdateVisitor)
/** Convert 'this' into a osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor, otherwise return 0.
* Equivalent to dynamic_cast<osgUtil::UpdateVisitor*>(this).*/
virtual osgUtil::UpdateVisitor* asUpdateVisitor() { return this; }
/** convert 'const this' into a const osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor, otherwise return 0.
* Equivalent to dynamic_cast<const osgUtil::UpdateVisitor*>(this).*/
virtual const osgUtil::UpdateVisitor* asUpdateVisitor() const { return this; }
virtual void reset(); virtual void reset();
/** During traversal each type of node calls its callbacks and its children traversed. */ /** During traversal each type of node calls its callbacks and its children traversed. */

View File

@ -42,7 +42,7 @@ void Technique::traverse_implementation(osg::NodeVisitor& nv, Effect* fx)
} }
// special actions must be taken if the node visitor is actually a CullVisitor // special actions must be taken if the node visitor is actually a CullVisitor
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(&nv); osgUtil::CullVisitor *cv = nv.asCullVisitor();
// traverse all passes // traverse all passes
for (int i=0; i<getNumPasses(); ++i) { for (int i=0; i<getNumPasses(); ++i) {

View File

@ -18,7 +18,7 @@ using namespace osgGA;
void EventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) void EventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::EventVisitor* ev = nv->asEventVisitor();
if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{ {
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
@ -33,7 +33,7 @@ void EventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
void EventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable) void EventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::EventVisitor* ev = nv->asEventVisitor();
if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{ {
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();

View File

@ -26,7 +26,7 @@ GUIEventHandler::~GUIEventHandler()
// adapt EventHandler usage to old style GUIEventHandler usage // adapt EventHandler usage to old style GUIEventHandler usage
bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::EventVisitor* ev = nv->asEventVisitor();
osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter(); osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
if (ea && ev && ev->getActionAdapter()) if (ea && ev && ev->getActionAdapter())
{ {

View File

@ -50,7 +50,7 @@ void Widget::setExtents(const osg::BoundingBoxf& bb)
void Widget::updateFocus(osg::NodeVisitor& nv) void Widget::updateFocus(osg::NodeVisitor& nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0; osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
if (ev && aa) if (ev && aa)
{ {
@ -214,7 +214,7 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics(); if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
if (ev) if (ev)
{ {
updateFocus(nv); updateFocus(nv);

View File

@ -298,7 +298,7 @@ void Dragger::traverse(osg::NodeVisitor& nv)
{ {
if (_handleEvents && nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR) if (_handleEvents && nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
if (ev) if (ev)
{ {
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();

View File

@ -55,7 +55,7 @@ osgParticle::ParticleProcessor::ParticleProcessor(const ParticleProcessor& copy,
void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv) void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
{ {
// typecast the NodeVisitor to CullVisitor // typecast the NodeVisitor to CullVisitor
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
// continue only if the visitor actually is a cull visitor // continue only if the visitor actually is a cull visitor
if (cv) { if (cv) {

View File

@ -135,7 +135,7 @@ void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv)
if (_sortMode != NO_SORT) if (_sortMode != NO_SORT)
{ {
// sort particles // sort particles
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
osg::Matrixd modelview = *(cv->getModelViewMatrix()); osg::Matrixd modelview = *(cv->getModelViewMatrix());

View File

@ -22,7 +22,7 @@ osgParticle::ParticleSystemUpdater::ParticleSystemUpdater(const ParticleSystemUp
void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv) void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
{ {
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
if (nv.getFrameStamp()) if (nv.getFrameStamp())

View File

@ -182,7 +182,7 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
return; return;
} }
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (!cv) if (!cv)
{ {
return; return;

View File

@ -38,7 +38,7 @@ class Logos: public osg::Drawable
virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable, osg::State*) const virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable, osg::State*) const
{ {
Logos *logos = dynamic_cast <Logos *>(drawable); Logos *logos = dynamic_cast <Logos *>(drawable);
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(visitor); osgUtil::CullVisitor *cv = visitor->asCullVisitor();
if (!cv) return true; if (!cv) return true;
unsigned int contextID = cv->getState()!=0 ? cv->getState()->getContextID() : 0; unsigned int contextID = cv->getState()!=0 ? cv->getState()->getContextID() : 0;

View File

@ -107,7 +107,7 @@ void TXPNode::traverse(osg::NodeVisitor& nv)
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
//#define PRINT_TILEMAPP_TIMEINFO //#define PRINT_TILEMAPP_TIMEINFO

View File

@ -179,7 +179,7 @@ void Cursor::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
if (!ev) return; if (!ev) return;
osgGA::EventQueue::Events& events = ev->getEvents(); osgGA::EventQueue::Events& events = ev->getEvents();
@ -239,7 +239,7 @@ void Cursor::traverse(osg::NodeVisitor& nv)
#if 0 #if 0
if (!_camera) if (!_camera)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
_camera = cv->getCurrentCamera(); _camera = cv->getCurrentCamera();

View File

@ -196,7 +196,7 @@ void Timeout::traverse(osg::NodeVisitor& nv)
{ {
if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (_displayTimeout && cv) if (_displayTimeout && cv)
{ {
osgUtil::RenderStage* previous_stage = cv->getCurrentRenderBin()->getStage(); osgUtil::RenderStage* previous_stage = cv->getCurrentRenderBin()->getStage();
@ -248,7 +248,7 @@ void Timeout::traverse(osg::NodeVisitor& nv)
bool previous_displayTimeout = _displayTimeout; bool previous_displayTimeout = _displayTimeout;
bool needToDismiss = false; bool needToDismiss = false;
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
osgViewer::Viewer* viewer = ev ? dynamic_cast<osgViewer::Viewer*>(ev->getActionAdapter()) : 0; osgViewer::Viewer* viewer = ev ? dynamic_cast<osgViewer::Viewer*>(ev->getActionAdapter()) : 0;
if (ev) if (ev)
{ {

View File

@ -84,7 +84,7 @@ void ShadowTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) cull(*cv); if (cv) cull(*cv);
else _shadowedScene->osg::Group::traverse(nv); else _shadowedScene->osg::Group::traverse(nv);
} }

View File

@ -168,8 +168,8 @@ VDSMCameraCullCallback::VDSMCameraCullCallback(ViewDependentShadowMap* vdsm, osg
void VDSMCameraCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv) void VDSMCameraCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = nv->asCullVisitor();
osg::Camera* camera = dynamic_cast<osg::Camera*>(node); osg::Camera* camera = node->asCamera();
OSG_INFO<<"VDSMCameraCullCallback::operator()(osg::Node* "<<camera<<", osg::NodeVisitor* "<<cv<<")"<<std::endl; OSG_INFO<<"VDSMCameraCullCallback::operator()(osg::Node* "<<camera<<", osg::NodeVisitor* "<<cv<<")"<<std::endl;
#if 1 #if 1

View File

@ -113,7 +113,7 @@ void Impostor::traverse(osg::NodeVisitor& nv)
return; return;
} }
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (!cv) if (!cv)
{ {
LOD::traverse(nv); LOD::traverse(nv);

View File

@ -141,7 +141,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
t1 = timer.tick(); t1 = timer.tick();
#endif #endif
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
#ifdef USE_TIMER #ifdef USE_TIMER
t2 = timer.tick(); t2 = timer.tick();

View File

@ -1330,7 +1330,7 @@ void OverlayNode::traverse_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeV
return; return;
} }
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (!cv) if (!cv)
{ {
Group::traverse(nv); Group::traverse(nv);
@ -1384,7 +1384,7 @@ void OverlayNode::traverse_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVis
return; return;
} }
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (!cv) if (!cv)
{ {
Group::traverse(nv); Group::traverse(nv);

View File

@ -72,7 +72,7 @@ void DisplacementMappingTechnique::traverse(osg::NodeVisitor& nv)
{ {
// if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false); // if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false);
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -81,7 +81,7 @@ void DisplacementMappingTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);

View File

@ -1456,7 +1456,7 @@ void GeometryTechnique::traverse(osg::NodeVisitor& nv)
{ {
if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false); if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false);
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -1465,7 +1465,7 @@ void GeometryTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);

View File

@ -92,7 +92,7 @@ void Terrain::traverse(osg::NodeVisitor& nv)
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR) if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
{ {
// need to check if any TerrainTechniques need to have their update called on them. // need to check if any TerrainTechniques need to have their update called on them.
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
typedef std::list< osg::ref_ptr<TerrainTile> > TerrainTileList; typedef std::list< osg::ref_ptr<TerrainTile> > TerrainTileList;
@ -125,7 +125,7 @@ void Terrain::traverse(osg::NodeVisitor& nv)
if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
osg::StateSet* ss = _geometryPool.valid() ? _geometryPool->getRootStateSetForTerrain(this) : 0; osg::StateSet* ss = _geometryPool.valid() ? _geometryPool->getRootStateSetForTerrain(this) : 0;
if (cv && ss) if (cv && ss)
{ {

View File

@ -114,7 +114,7 @@ void TerrainTechnique::traverse(osg::NodeVisitor& nv)
{ {
if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false); if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false);
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -124,7 +124,7 @@ void TerrainTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);

View File

@ -38,7 +38,7 @@ bool CloseCallback::run(osg::Object* object, osg::Parameters&, osg::Parameters&)
_closeWidget->setVisible(false); _closeWidget->setVisible(false);
} }
osg::Node* node = dynamic_cast<osg::Node*>(object); osg::Node* node = object->asNode();
if (node) if (node)
{ {
osg::NodePathList nodePathList = node->getParentalNodePaths(); osg::NodePathList nodePathList = node->getParentalNodePaths();

View File

@ -61,7 +61,7 @@ void Widget::setExtents(const osg::BoundingBoxf& bb)
void Widget::updateFocus(osg::NodeVisitor& nv) void Widget::updateFocus(osg::NodeVisitor& nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0; osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
if (ev && aa) if (ev && aa)
{ {
@ -209,7 +209,7 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
{ {
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics(); if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = nv.asEventVisitor();
if (ev) if (ev)
{ {
if (_visible && _enabled) if (_visible && _enabled)
@ -255,7 +255,7 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
else if (_visible || else if (_visible ||
(nv.getVisitorType()!=osg::NodeVisitor::UPDATE_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::INTERSECTION_VISITOR) ) (nv.getVisitorType()!=osg::NodeVisitor::UPDATE_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::INTERSECTION_VISITOR) )
{ {
osgUtil::CullVisitor* cv = (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) ? dynamic_cast<osgUtil::CullVisitor*>(&nv) : 0; osgUtil::CullVisitor* cv = (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) ? nv.asCullVisitor() : 0;
if (cv && _widgetStateSet.valid()) cv->pushStateSet(_widgetStateSet.get()); if (cv && _widgetStateSet.valid()) cv->pushStateSet(_widgetStateSet.get());
GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin(); GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
@ -476,7 +476,7 @@ bool Widget::computeExtentsPositionInLocalCoordinates(osgGA::EventVisitor* ev, o
if (event->getNumPointerData()>=1) if (event->getNumPointerData()>=1)
{ {
const osgGA::PointerData* pd = event->getPointerData(event->getNumPointerData()-1); const osgGA::PointerData* pd = event->getPointerData(event->getNumPointerData()-1);
camera = dynamic_cast<const osg::Camera*>(pd->object.get()); camera = pd->object->asCamera();
if (camera) if (camera)
{ {
x = pd->getXnormalized(); x = pd->getXnormalized();

View File

@ -719,11 +719,11 @@ void SceneView::cull()
else else
{ {
if (!_cullVisitorLeft.valid()) _cullVisitorLeft = dynamic_cast<CullVisitor*>(_cullVisitor->clone()); if (!_cullVisitorLeft.valid()) _cullVisitorLeft = _cullVisitor->clone();
if (!_stateGraphLeft.valid()) _stateGraphLeft = dynamic_cast<StateGraph*>(_stateGraph->cloneType()); if (!_stateGraphLeft.valid()) _stateGraphLeft = dynamic_cast<StateGraph*>(_stateGraph->cloneType());
if (!_renderStageLeft.valid()) _renderStageLeft = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL)); if (!_renderStageLeft.valid()) _renderStageLeft = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL));
if (!_cullVisitorRight.valid()) _cullVisitorRight = dynamic_cast<CullVisitor*>(_cullVisitor->clone()); if (!_cullVisitorRight.valid()) _cullVisitorRight = _cullVisitor->clone();
if (!_stateGraphRight.valid()) _stateGraphRight = dynamic_cast<StateGraph*>(_stateGraph->cloneType()); if (!_stateGraphRight.valid()) _stateGraphRight = dynamic_cast<StateGraph*>(_stateGraph->cloneType());
if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL)); if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL));

View File

@ -276,7 +276,7 @@ void FixedFunctionTechnique::traverse(osg::NodeVisitor& nv)
{ {
if (_volumeTile->getDirty()) _volumeTile->init(); if (_volumeTile->getDirty()) _volumeTile->init();
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -286,7 +286,7 @@ void FixedFunctionTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);

View File

@ -163,7 +163,7 @@ class RTTCameraCullCallback : public osg::NodeCallback
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = nv->asCullVisitor();
cv->pushProjectionMatrix(_tileData->projectionMatrix.get()); cv->pushProjectionMatrix(_tileData->projectionMatrix.get());
@ -937,7 +937,7 @@ class RTTBackfaceCameraCullCallback : public osg::NodeCallback
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = nv->asCullVisitor();
cv->pushProjectionMatrix(_tileData->projectionMatrix.get()); cv->pushProjectionMatrix(_tileData->projectionMatrix.get());
@ -1157,7 +1157,7 @@ void MultipassTechnique::traverse(osg::NodeVisitor& nv)
{ {
if (_volumeTile->getDirty()) _volumeTile->init(); if (_volumeTile->getDirty()) _volumeTile->init();
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -1167,7 +1167,7 @@ void MultipassTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);

View File

@ -525,7 +525,7 @@ void RayTracedTechnique::traverse(osg::NodeVisitor& nv)
{ {
if (_volumeTile->getDirty()) _volumeTile->init(); if (_volumeTile->getDirty()) _volumeTile->init();
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -535,7 +535,7 @@ void RayTracedTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);

View File

@ -33,7 +33,7 @@ class RTTCameraCullCallback : public osg::NodeCallback
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = nv->asCullVisitor();
_volumeScene->osg::Group::traverse(*nv); _volumeScene->osg::Group::traverse(*nv);
@ -135,7 +135,7 @@ TileData* VolumeScene::getTileData(osgUtil::CullVisitor* cv, osgVolume::VolumeTi
void VolumeScene::traverse(osg::NodeVisitor& nv) void VolumeScene::traverse(osg::NodeVisitor& nv)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (!cv) if (!cv)
{ {
Group::traverse(nv); Group::traverse(nv);

View File

@ -63,7 +63,7 @@ void VolumeTechnique::traverse(osg::NodeVisitor& nv)
{ {
if (_volumeTile->getDirty()) _volumeTile->init(); if (_volumeTile->getDirty()) _volumeTile->init();
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv); osgUtil::UpdateVisitor* uv = nv.asUpdateVisitor();
if (uv) if (uv)
{ {
update(uv); update(uv);
@ -73,7 +73,7 @@ void VolumeTechnique::traverse(osg::NodeVisitor& nv)
} }
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
{ {
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); osgUtil::CullVisitor* cv = nv.asCullVisitor();
if (cv) if (cv)
{ {
cull(cv); cull(cv);