OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UpdateVisitor.h
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 
30 namespace osgUtil {
31 
38 {
39  public:
40 
41  UpdateVisitor();
42  virtual ~UpdateVisitor();
43 
45 
46  virtual void reset();
47 
49  virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
50 
51  virtual void apply(osg::Drawable& drawable)
52  {
53  osg::Callback* callback = drawable.getUpdateCallback();
54  if (callback)
55  {
56  osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
57  osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
58  osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
59 
60  if (drawable_callback) drawable_callback->update(this,&drawable);
61  if (node_callback) (*node_callback)(&drawable, this);
62 
63  if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
64  }
65 
66  handle_callbacks(drawable.getStateSet());
67  }
68 
69  virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
70  virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
71 
72  virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
73 
74  virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
75  virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); }
76  virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); }
77  virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
78  virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
79  virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
80 
81 
82  protected:
83 
84 // /** Prevent unwanted copy construction.*/
85 // UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
86 
88  UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
89 
90  inline void handle_callbacks(osg::StateSet* stateset)
91  {
92  if (stateset && stateset->requiresUpdateTraversal())
93  {
94  stateset->runUpdateCallbacks(this);
95  }
96  }
97 
99  {
100  handle_callbacks(node.getStateSet());
101 
102  osg::Callback* callback = node.getUpdateCallback();
103  if (callback) callback->run(&node,this);
104  else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
105  }
106 };
107 
108 }
109 
110 #endif
111 
virtual void apply(osg::LightSource &node)
Definition: UpdateVisitor.h:72
virtual void apply(osg::Group &node)
Definition: UpdateVisitor.h:74
void runUpdateCallbacks(osg::NodeVisitor *nv)
Callback * getUpdateCallback()
Definition: Node.h:216
virtual void apply(osg::Billboard &node)
Definition: UpdateVisitor.h:70
virtual void update(osg::NodeVisitor *, osg::Drawable *)
Definition: Drawable.h:283
bool run(osg::Object *object, osg::Object *data)
virtual void apply(osg::Geode &node)
Definition: UpdateVisitor.h:69
unsigned int getNumChildrenRequiringUpdateTraversal() const
Definition: Node.h:244
Definition: LOD.h:35
virtual bool run(osg::Object *object, osg::Object *data)
Definition: Callback.h:42
void handle_callbacks(osg::StateSet *stateset)
Definition: UpdateVisitor.h:90
#define META_NodeVisitor(library, name)
Definition: NodeVisitor.h:49
virtual void apply(osg::Transform &node)
Definition: UpdateVisitor.h:75
virtual void apply(osg::OccluderNode &node)
Definition: UpdateVisitor.h:79
virtual void apply(osg::Switch &node)
Definition: UpdateVisitor.h:77
virtual void apply(osg::LOD &node)
Definition: UpdateVisitor.h:78
virtual void apply(osg::Projection &node)
Definition: UpdateVisitor.h:76
Definition: Node.h:71
virtual void apply(osg::Drawable &drawable)
Definition: UpdateVisitor.h:51
#define OSGUTIL_EXPORT
Definition: Export.h:40
virtual void apply(osg::Node &node)
Definition: UpdateVisitor.h:49
bool requiresUpdateTraversal() const
Definition: StateSet.h:437
void handle_callbacks_and_traverse(osg::Node &node)
Definition: UpdateVisitor.h:98
osg::StateSet * getStateSet()
Definition: Node.h:369
Shader generator framework.
Definition: RenderInfo.h:20