OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NodeVisitor.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 OSG_NODEVISITOR
15 #define OSG_NODEVISITOR 1
16 
17 #include <osg/Node>
18 #include <osg/Matrix>
19 #include <osg/FrameStamp>
20 
21 namespace osg {
22 
23 class Billboard;
24 class ClearNode;
25 class ClipNode;
26 class CoordinateSystemNode;
27 class Geode;
28 class Group;
29 class LightSource;
30 class LOD;
31 class MatrixTransform;
32 class OccluderNode;
33 class OcclusionQueryNode;
34 class PagedLOD;
35 class PositionAttitudeTransform;
36 class Projection;
37 class ProxyNode;
38 class Sequence;
39 class Switch;
40 class TexGenNode;
41 class Transform;
42 class Camera;
43 class CameraView;
44 class Drawable;
45 class Geometry;
46 
47 const unsigned int UNINITIALIZED_FRAME_NUMBER=0xffffffff;
48 
49 #define META_NodeVisitor(library, name) \
50  virtual const char* libraryName() const { return #library; }\
51  virtual const char* className() const { return #name; }
52 
67 class OSG_EXPORT NodeVisitor : public virtual Object
68 {
69  public:
70 
72  {
76  TRAVERSE_ACTIVE_CHILDREN
77  };
78 
80  {
81  NODE_VISITOR = 0,
86  INTERSECTION_VISITOR
87  };
88 
89  NodeVisitor(TraversalMode tm=TRAVERSE_NONE);
90 
91  NodeVisitor(VisitorType type,TraversalMode tm=TRAVERSE_NONE);
92 
94 
95  virtual ~NodeVisitor();
96 
98 
99 
101  virtual NodeVisitor* asNodeVisitor() { return this; }
102 
105  virtual const NodeVisitor* asNodeVisitor() const { return this; }
106 
107 
112  virtual void reset() {}
113 
114 
118  inline void setVisitorType(VisitorType type) { _visitorType = type; }
119 
121  inline VisitorType getVisitorType() const { return _visitorType; }
122 
124  inline void setTraversalNumber(unsigned int fn) { _traversalNumber = fn; }
125 
127  inline unsigned int getTraversalNumber() const { return _traversalNumber; }
128 
130  inline void setFrameStamp(FrameStamp* fs) { _frameStamp = fs; }
131 
133  inline const FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
134 
135 
145  inline void setTraversalMask(Node::NodeMask mask) { _traversalMask = mask; }
146 
148  inline Node::NodeMask getTraversalMask() const { return _traversalMask; }
149 
155  inline void setNodeMaskOverride(Node::NodeMask mask) { _nodeMaskOverride = mask; }
156 
158  inline Node::NodeMask getNodeMaskOverride() const { return _nodeMaskOverride; }
159 
166  inline bool validNodeMask(const osg::Node& node) const
167  {
168  return (getTraversalMask() & (getNodeMaskOverride() | node.getNodeMask()))!=0;
169  }
170 
176  inline void setTraversalMode(TraversalMode mode) { _traversalMode = mode; }
177 
179  inline TraversalMode getTraversalMode() const { return _traversalMode; }
180 
185  inline void traverse(Node& node)
186  {
187  if (_traversalMode==TRAVERSE_PARENTS) node.ascend(*this);
188  else if (_traversalMode!=TRAVERSE_NONE) node.traverse(*this);
189  }
190 
198  inline void pushOntoNodePath(Node* node) { if (_traversalMode!=TRAVERSE_PARENTS) _nodePath.push_back(node); else _nodePath.insert(_nodePath.begin(),node); }
199 
204  inline void popFromNodePath() { if (_traversalMode!=TRAVERSE_PARENTS) _nodePath.pop_back(); else _nodePath.erase(_nodePath.begin()); }
205 
208  NodePath& getNodePath() { return _nodePath; }
209 
212  const NodePath& getNodePath() const { return _nodePath; }
213 
216  virtual osg::Vec3 getEyePoint() const { return Vec3(0.0f,0.0f,0.0f); }
217 
220  virtual osg::Vec3 getViewPoint() const { return getEyePoint(); }
221 
225  virtual float getDistanceToEyePoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
226 
230  virtual float getDistanceFromEyePoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
231 
235  virtual float getDistanceToViewPoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
236 
237  virtual void apply(Drawable& drawable);
238  virtual void apply(Geometry& geometry);
239 
240  virtual void apply(Node& node);
241 
242  virtual void apply(Geode& node);
243  virtual void apply(Billboard& node);
244 
245  virtual void apply(Group& node);
246 
247  virtual void apply(ProxyNode& node);
248 
249  virtual void apply(Projection& node);
250 
251  virtual void apply(CoordinateSystemNode& node);
252 
253  virtual void apply(ClipNode& node);
254  virtual void apply(TexGenNode& node);
255  virtual void apply(LightSource& node);
256 
257  virtual void apply(Transform& node);
258  virtual void apply(Camera& node);
259  virtual void apply(CameraView& node);
260  virtual void apply(MatrixTransform& node);
261  virtual void apply(PositionAttitudeTransform& node);
262 
263  virtual void apply(Switch& node);
264  virtual void apply(Sequence& node);
265  virtual void apply(LOD& node);
266  virtual void apply(PagedLOD& node);
267  virtual void apply(ClearNode& node);
268  virtual void apply(OccluderNode& node);
269  virtual void apply(OcclusionQueryNode& node);
270 
271 
274  {
275  public:
276 
278  Referenced(true) {}
279 
280  virtual void requestNodeFile(const std::string& fileName, osg::NodePath& nodePath, float priority, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& databaseRequest, const osg::Referenced* options=0) = 0;
281 
282  protected:
284  };
285 
287  void setDatabaseRequestHandler(DatabaseRequestHandler* handler) { _databaseRequestHandler = handler; }
288 
290  DatabaseRequestHandler* getDatabaseRequestHandler() { return _databaseRequestHandler.get(); }
291 
293  const DatabaseRequestHandler* getDatabaseRequestHandler() const { return _databaseRequestHandler.get(); }
294 
295 
298  {
299  public:
300 
302  Referenced(true) {}
303 
304  virtual double getPreLoadTime() const = 0;
305 
306  virtual osg::Image* readImageFile(const std::string& fileName, const osg::Referenced* options=0) = 0;
307 
308  virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options=0) = 0;
309 
310  protected:
311  virtual ~ImageRequestHandler() {}
312  };
313 
315  void setImageRequestHandler(ImageRequestHandler* handler) { _imageRequestHandler = handler; }
316 
318  ImageRequestHandler* getImageRequestHandler() { return _imageRequestHandler.get(); }
319 
321  const ImageRequestHandler* getImageRequestHandler() const { return _imageRequestHandler.get(); }
322 
323 
324 
325  protected:
326 
328  unsigned int _traversalNumber;
329 
331 
335 
337 
340 
341 };
342 
343 
346 {
347  public:
348 
350  NodeAcceptOp(const NodeAcceptOp& naop):_nv(naop._nv) {}
351 
352  void operator () (Node* node) { node->accept(_nv); }
353  void operator () (ref_ptr<Node> node) { node->accept(_nv); }
354 
355  protected:
356 
357  NodeAcceptOp& operator = (const NodeAcceptOp&) { return *this; }
358 
360 };
361 
362 }
363 
364 #endif
#define OSG_EXPORT
Definition: Export.h:43
NodeAcceptOp(const NodeAcceptOp &naop)
Definition: NodeVisitor.h:350
void setTraversalNumber(unsigned int fn)
Definition: NodeVisitor.h:124
TraversalMode _traversalMode
Definition: NodeVisitor.h:332
ImageRequestHandler * getImageRequestHandler()
Definition: NodeVisitor.h:318
ref_ptr< FrameStamp > _frameStamp
Definition: NodeVisitor.h:330
Node::NodeMask getTraversalMask() const
Definition: NodeVisitor.h:148
unsigned int getTraversalNumber() const
Definition: NodeVisitor.h:127
virtual float getDistanceToViewPoint(const Vec3 &, bool) const
Definition: NodeVisitor.h:235
NodeMask getNodeMask() const
Definition: Node.h:356
Node::NodeMask _nodeMaskOverride
Definition: NodeVisitor.h:334
void popFromNodePath()
Definition: NodeVisitor.h:204
void setVisitorType(VisitorType type)
Definition: NodeVisitor.h:118
bool validNodeMask(const osg::Node &node) const
Definition: NodeVisitor.h:166
NodeAcceptOp & operator=(const NodeAcceptOp &)
Definition: NodeVisitor.h:357
virtual const NodeVisitor * asNodeVisitor() const
Definition: NodeVisitor.h:105
TraversalMode getTraversalMode() const
Definition: NodeVisitor.h:179
NodeAcceptOp(NodeVisitor &nv)
Definition: NodeVisitor.h:349
Node::NodeMask _traversalMask
Definition: NodeVisitor.h:333
virtual void reset()
Definition: NodeVisitor.h:112
virtual float getDistanceFromEyePoint(const Vec3 &, bool) const
Definition: NodeVisitor.h:230
virtual osg::Vec3 getEyePoint() const
Definition: NodeVisitor.h:216
void operator()(Node *node)
Definition: NodeVisitor.h:352
VisitorType getVisitorType() const
Definition: NodeVisitor.h:121
VisitorType _visitorType
Definition: NodeVisitor.h:327
META_Object(osg, NodeVisitor) virtual NodeVisitor *asNodeVisitor()
Definition: NodeVisitor.h:97
const FrameStamp * getFrameStamp() const
Definition: NodeVisitor.h:133
Definition: LOD.h:35
NodePath & getNodePath()
Definition: NodeVisitor.h:208
virtual osg::Vec3 getViewPoint() const
Definition: NodeVisitor.h:220
Vec3f Vec3
Definition: Vec3.h:21
unsigned int _traversalNumber
Definition: NodeVisitor.h:328
void traverse(Node &node)
Definition: NodeVisitor.h:185
const NodePath & getNodePath() const
Definition: NodeVisitor.h:212
virtual void accept(NodeVisitor &nv)
void setTraversalMode(TraversalMode mode)
Definition: NodeVisitor.h:176
virtual void ascend(NodeVisitor &nv)
const DatabaseRequestHandler * getDatabaseRequestHandler() const
Definition: NodeVisitor.h:293
ref_ptr< DatabaseRequestHandler > _databaseRequestHandler
Definition: NodeVisitor.h:338
void pushOntoNodePath(Node *node)
Definition: NodeVisitor.h:198
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: GLU.h:71
virtual void traverse(NodeVisitor &)
Definition: Node.h:174
Definition: Node.h:71
Definition: AlphaFunc.h:19
virtual float getDistanceToEyePoint(const Vec3 &, bool) const
Definition: NodeVisitor.h:225
DatabaseRequestHandler * getDatabaseRequestHandler()
Definition: NodeVisitor.h:290
void setFrameStamp(FrameStamp *fs)
Definition: NodeVisitor.h:130
Node::NodeMask getNodeMaskOverride() const
Definition: NodeVisitor.h:158
unsigned int NodeMask
Definition: Node.h:352
void setImageRequestHandler(ImageRequestHandler *handler)
Definition: NodeVisitor.h:315
void setTraversalMask(Node::NodeMask mask)
Definition: NodeVisitor.h:145
void setNodeMaskOverride(Node::NodeMask mask)
Definition: NodeVisitor.h:155
NodeVisitor & _nv
Definition: NodeVisitor.h:359
ref_ptr< ImageRequestHandler > _imageRequestHandler
Definition: NodeVisitor.h:339
OSGDB_EXPORT osg::Image * readImageFile(const std::string &filename, const Options *options)
std::vector< Node * > NodePath
Definition: Node.h:44
NodePath _nodePath
Definition: NodeVisitor.h:336
const unsigned int UNINITIALIZED_FRAME_NUMBER
Definition: NodeVisitor.h:47
void setDatabaseRequestHandler(DatabaseRequestHandler *handler)
Definition: NodeVisitor.h:287
const ImageRequestHandler * getImageRequestHandler() const
Definition: NodeVisitor.h:321