OpenSceneGraph 3.6.5
UpdateVisitor
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_UPDATEVISITOR
15#define OSGUTIL_UPDATEVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Geode>
19#include <osg/Billboard>
20#include <osg/LOD>
21#include <osg/Switch>
22#include <osg/LightSource>
23#include <osg/Transform>
24#include <osg/Projection>
25#include <osg/OccluderNode>
26#include <osg/ScriptEngine>
27
28#include <osgUtil/Export>
29
30namespace osgUtil {
31
38{
39 public:
40
42 virtual ~UpdateVisitor();
43
49
52 virtual const osgUtil::UpdateVisitor* asUpdateVisitor() const { return this; }
53
54 virtual void reset();
55
57 virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
58
59 virtual void apply(osg::Drawable& drawable)
60 {
61 osg::Callback* callback = drawable.getUpdateCallback();
62 if (callback)
63 {
64 osg::DrawableUpdateCallback* drawable_callback = callback->asDrawableUpdateCallback();
65 osg::NodeCallback* node_callback = callback->asNodeCallback();
66
67 if (drawable_callback) drawable_callback->update(this,&drawable);
68 if (node_callback) (*node_callback)(&drawable, this);
69
70 if (!drawable_callback && !node_callback) callback->run(&drawable, this);
71 }
72
73 handle_callbacks(drawable.getStateSet());
74 }
75
76 // The following overrides are technically redundant as the default implementation would eventually trickle down to
77 // apply(osg::Node&); - however defining these explicitly should save a couple of virtual function calls
78 virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
79 virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
81 virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
82 virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); }
84 virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
85 virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
87
88
89 protected:
90
91// /** Prevent unwanted copy construction.*/
92// UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
93
95 UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
96
97 inline void handle_callbacks(osg::StateSet* stateset)
98 {
99 if (stateset && stateset->requiresUpdateTraversal())
100 {
101 stateset->runUpdateCallbacks(this);
102 }
103 }
104
106 {
108
109 osg::Callback* callback = node.getUpdateCallback();
110 if (callback) callback->run(&node,this);
111 else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
112 }
113};
114
115}
116
117#endif
118
The osgUtil library provides general purpose utility classes such as update, cull and draw traverses,...
Definition NodeVisitor:25
Billboard is a derived form of Geode that orients its osg::Drawable children to face the eye point.
Definition Billboard:27
Definition Callback:34
virtual bool run(osg::Object *object, osg::Object *data)
Invoke the callback, first parameter is the Object that the callback is attached to,...
Definition Callback:80
virtual DrawableUpdateCallback * asDrawableUpdateCallback()
Definition Callback:61
virtual NodeCallback * asNodeCallback()
Definition Callback:52
Deprecated.
Definition Callback:215
Definition Callback:298
virtual void update(osg::NodeVisitor *, osg::Drawable *)
do customized update code.
Definition Callback:315
Pure virtual base class for drawable geometry.
Definition Drawable:89
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
General group node which maintains a list of children.
Definition Group:29
Leaf Node for defining a light in the scene.
Definition LightSource:25
LOD - Level Of Detail group node which allows switching between children depending on distance from e...
Definition LOD:36
Base class for all internal nodes in the scene graph.
Definition Node:72
osg::StateSet * getStateSet()
Return the node's StateSet.
Definition Node:382
Callback * getUpdateCallback()
Get update node callback, called during update traversal.
Definition Node:211
unsigned int getNumChildrenRequiringUpdateTraversal() const
Get the number of Children of this node which require Update traversal, since they have an Update Cal...
Definition Node:243
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
void traverse(Node &node)
Method for handling traversal of a nodes.
Definition NodeVisitor:274
OccluderNode is a Group node which provides hooks for adding ConvexPlanarOccluders to the scene.
Definition OccluderNode:27
Projection nodes set up the frustum/orthographic projection used when rendering the scene.
Definition Projection:25
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
bool requiresUpdateTraversal() const
Return whether this StateSet has update callbacks associated with it, and therefore must be traversed...
Definition StateSet:474
void runUpdateCallbacks(osg::NodeVisitor *nv)
Run the update callbacks attached directly to this StateSet or to its children.
Switch is a Group node that allows switching between children.
Definition Switch:27
A Transform is a group node for which all children are transformed by a 4x4 matrix.
Definition Transform:75
Basic UpdateVisitor implementation for animating a scene.
Definition UpdateVisitor:38
virtual void apply(osg::Billboard &node)
Definition UpdateVisitor:79
virtual void reset()
Method to call to reset visitor.
virtual void apply(osg::Node &node)
During traversal each type of node calls its callbacks and its children traversed.
Definition UpdateVisitor:57
virtual void apply(osg::Geode &node)
Definition UpdateVisitor:78
META_NodeVisitor(osgUtil, UpdateVisitor) virtual osgUtil
Convert 'this' into a osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor,...
Definition UpdateVisitor:44
virtual void apply(osg::Projection &node)
Definition UpdateVisitor:83
virtual void apply(osg::LOD &node)
Definition UpdateVisitor:85
virtual const osgUtil::UpdateVisitor * asUpdateVisitor() const
convert 'const this' into a const osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisito...
Definition UpdateVisitor:52
void handle_callbacks(osg::StateSet *stateset)
Definition UpdateVisitor:97
virtual void apply(osg::Group &node)
Definition UpdateVisitor:81
virtual void apply(osg::Drawable &drawable)
Definition UpdateVisitor:59
virtual void apply(osg::Switch &node)
Definition UpdateVisitor:84
virtual void apply(osg::OccluderNode &node)
Definition UpdateVisitor:86
virtual void apply(osg::LightSource &node)
Definition UpdateVisitor:80
virtual void apply(osg::Transform &node)
Definition UpdateVisitor:82
void handle_callbacks_and_traverse(osg::Node &node)
Definition UpdateVisitor:105
#define OSGUTIL_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.