UpdateVisitor
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_UPDATEVISITOR
#define OSGUTIL_UPDATEVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/LOD>
#include <osg/Switch>
#include <osg/LightSource>
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgUtil/Export>
namespace osgUtil {
class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
{
public:
UpdateVisitor();
virtual ~UpdateVisitor();
META_NodeVisitor(osgUtil, UpdateVisitor)
virtual osgUtil::UpdateVisitor* asUpdateVisitor() { return this; }
virtual const osgUtil::UpdateVisitor* asUpdateVisitor() const { return this; }
virtual void reset();
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Drawable& drawable)
{
osg::Callback* callback = drawable.getUpdateCallback();
if (callback)
{
osg::DrawableUpdateCallback* drawable_callback = callback->asDrawableUpdateCallback();
osg::NodeCallback* node_callback = callback->asNodeCallback();
if (drawable_callback) drawable_callback->update(this,&drawable);
if (node_callback) (*node_callback)(&drawable, this);
if (!drawable_callback && !node_callback) callback->run(&drawable, this);
}
handle_callbacks(drawable.getStateSet());
}
// The following overrides are technically redundant as the default implementation would eventually trickle down to
// apply(osg::Node&); - however defining these explicitly should save a couple of virtual function calls
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
protected:
// /** Prevent unwanted copy construction.*/
// UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
inline void handle_callbacks(osg::StateSet* stateset)
{
if (stateset && stateset->requiresUpdateTraversal())
{
stateset->runUpdateCallbacks(this);
}
}
inline void handle_callbacks_and_traverse(osg::Node& node)
{
handle_callbacks(node.getStateSet());
osg::Callback* callback = node.getUpdateCallback();
if (callback) callback->run(&node,this);
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
}
};
}
#endif
Billboard
Geode
LOD
LightSource
NodeVisitor
OccluderNode
Projection
Switch
Transform
osgUtil::UpdateVisitor
Definition UpdateVisitor:38
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Billboard &node)
Definition UpdateVisitor:79
osgUtil::UpdateVisitor::reset
virtual void reset()
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Node &node)
Definition UpdateVisitor:57
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Geode &node)
Definition UpdateVisitor:78
osgUtil::UpdateVisitor::META_NodeVisitor
META_NodeVisitor(osgUtil, UpdateVisitor) virtual osgUtil
Definition UpdateVisitor:44
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Projection &node)
Definition UpdateVisitor:83
osgUtil::UpdateVisitor::apply
virtual void apply(osg::LOD &node)
Definition UpdateVisitor:85
osgUtil::UpdateVisitor::asUpdateVisitor
virtual const osgUtil::UpdateVisitor * asUpdateVisitor() const
Definition UpdateVisitor:52
osgUtil::UpdateVisitor::handle_callbacks
void handle_callbacks(osg::StateSet *stateset)
Definition UpdateVisitor:97
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Group &node)
Definition UpdateVisitor:81
osgUtil::UpdateVisitor::UpdateVisitor
UpdateVisitor()
osgUtil::UpdateVisitor::~UpdateVisitor
virtual ~UpdateVisitor()
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Drawable &drawable)
Definition UpdateVisitor:59
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Switch &node)
Definition UpdateVisitor:84
osgUtil::UpdateVisitor::apply
virtual void apply(osg::OccluderNode &node)
Definition UpdateVisitor:86
osgUtil::UpdateVisitor::apply
virtual void apply(osg::LightSource &node)
Definition UpdateVisitor:80
osgUtil::UpdateVisitor::apply
virtual void apply(osg::Transform &node)
Definition UpdateVisitor:82
osgUtil::UpdateVisitor::handle_callbacks_and_traverse
void handle_callbacks_and_traverse(osg::Node &node)
Definition UpdateVisitor:105
osg::Billboard
Definition Billboard:27
osg::Callback
Definition Callback:34
osg::Callback::run
virtual bool run(osg::Object *object, osg::Object *data)
Definition Callback:80
osg::Callback::asDrawableUpdateCallback
virtual DrawableUpdateCallback * asDrawableUpdateCallback()
Definition Callback:61
osg::Callback::asNodeCallback
virtual NodeCallback * asNodeCallback()
Definition Callback:52
osg::DrawableUpdateCallback
Definition Callback:298
osg::DrawableUpdateCallback::update
virtual void update(osg::NodeVisitor *, osg::Drawable *)
Definition Callback:315
osg::Drawable
Definition Drawable:89
osg::Geode
Definition Geode:29
osg::Group
Definition Group:29
osg::LOD
Definition LOD:36
osg::LightSource
Definition LightSource:25
osg::NodeCallback
Definition Callback:215
osg::NodeVisitor
Definition NodeVisitor:82
osg::NodeVisitor::traverse
void traverse(Node &node)
Definition NodeVisitor:274
osg::Node
Definition Node:72
osg::Node::getStateSet
osg::StateSet * getStateSet()
Definition Node:382
osg::Node::getUpdateCallback
Callback * getUpdateCallback()
Definition Node:211
osg::Node::getNumChildrenRequiringUpdateTraversal
unsigned int getNumChildrenRequiringUpdateTraversal() const
Definition Node:243
osg::OccluderNode
Definition OccluderNode:27
osg::Projection
Definition Projection:25
osg::StateSet
Definition StateSet:46
osg::StateSet::requiresUpdateTraversal
bool requiresUpdateTraversal() const
Definition StateSet:474
osg::StateSet::runUpdateCallbacks
void runUpdateCallbacks(osg::NodeVisitor *nv)
osg::Switch
Definition Switch:27
osg::Transform
Definition Transform:75
osgUtil
Definition NodeVisitor:25
Export
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
ScriptEngine