OpenSceneGraph 3.6.5
Node
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
15#ifndef OSG_NODE
16#define OSG_NODE 1
17
18#include <osg/Object>
19#include <osg/StateSet>
20#include <osg/BoundingSphere>
21#include <osg/BoundingBox>
22#include <osg/Callback>
23
24#include <string>
25#include <vector>
26
27
28// forward declare osgTerrrain::Terrain to enable declaration of asTerrain() method.
29namespace osgTerrain {
30class Terrain;
31}
32
33namespace osg {
34
35// forcing declare classes to enable declaration of as*() methods.
36class NodeVisitor;
37class Drawable;
38class Geometry;
39class Group;
40class Transform;
41class Node;
42class Switch;
43class Geode;
44class Camera;
45
47typedef std::vector< Node* > NodePath;
48
50typedef std::vector< NodePath > NodePathList;
51
53typedef std::vector< Matrix > MatrixList;
54
55
59#define META_Node(library,name) \
60 virtual osg::Object* cloneType() const { return new name (); } \
61 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
62 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
63 virtual const char* className() const { return #name; } \
64 virtual const char* libraryName() const { return #library; } \
65 virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } } \
66
67
71class OSG_EXPORT Node : public Object
72{
73 public:
74
79
81 Node(const Node&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
82
84 virtual Object* cloneType() const { return new Node(); }
85
87 virtual Object* clone(const CopyOp& copyop) const { return new Node(*this,copyop); }
88
90 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Node*>(obj)!=NULL; }
91
93 virtual const char* libraryName() const { return "osg"; }
94
96 virtual const char* className() const { return "Node"; }
97
100 virtual Node* asNode() { return this; }
101
104 virtual const Node* asNode() const { return this; }
105
108 virtual Drawable* asDrawable() { return 0; }
111 virtual const Drawable* asDrawable() const { return 0; }
112
115 virtual Geometry* asGeometry() { return 0; }
118 virtual const Geometry* asGeometry() const { return 0; }
119
122 virtual Group* asGroup() { return 0; }
125 virtual const Group* asGroup() const { return 0; }
126
129 virtual Transform* asTransform() { return 0; }
130
133 virtual const Transform* asTransform() const { return 0; }
134
135
136
139 virtual Switch* asSwitch() { return 0; }
140
143 virtual const Switch* asSwitch() const { return 0; }
144
147 virtual Geode* asGeode() { return 0; }
148
151 virtual const Geode* asGeode() const { return 0; }
152
155 virtual osgTerrain::Terrain* asTerrain() { return 0; }
156
159 virtual const osgTerrain::Terrain* asTerrain() const { return 0; }
160
161
163 virtual void accept(NodeVisitor& nv);
165 virtual void ascend(NodeVisitor& nv);
167 virtual void traverse(NodeVisitor& /*nv*/) {}
168
170 typedef std::vector<Group*> ParentList;
171
173 inline const ParentList& getParents() const { return _parents; }
174
177 inline ParentList getParents() { return _parents; }
178
179 inline Group* getParent(unsigned int i) { return _parents[i]; }
180
186 inline const Group* getParent(unsigned int i) const { return _parents[i]; }
187
192 inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
193
194
195
198 NodePathList getParentalNodePaths(osg::Node* haltTraversalAtNode=0) const;
199
202 MatrixList getWorldMatrices(const osg::Node* haltTraversalAtNode=0) const;
203
204
207
208 template<class T> void setUpdateCallback(const ref_ptr<T>& nc) { setUpdateCallback(nc.get()); }
209
211 inline Callback* getUpdateCallback() { return _updateCallback.get(); }
212
214 inline const Callback* getUpdateCallback() const { return _updateCallback.get(); }
215
217 inline void addUpdateCallback(Callback* nc) {
218 if (nc != NULL) {
219 if (_updateCallback.valid()) _updateCallback->addNestedCallback(nc);
220 else setUpdateCallback(nc);
221 }
222 }
223
224 template<class T> void addUpdateCallback(const ref_ptr<T>& nc) { addUpdateCallback(nc.get()); }
225
228 if (nc != NULL && _updateCallback.valid()) {
229 if (_updateCallback == nc)
230 {
231 ref_ptr<osg::Callback> new_nested_callback = nc->getNestedCallback();
232 nc->setNestedCallback(0);
233 setUpdateCallback(new_nested_callback.get());
234 }
235 else _updateCallback->removeNestedCallback(nc);
236 }
237 }
238
239 template<class T> void removeUpdateCallback(const ref_ptr<T>& nc) { removeUpdateCallback(nc.get()); }
240
244
245
248
249 template<class T> void setEventCallback(const ref_ptr<T>& nc) { setEventCallback(nc.get()); }
250
252 inline Callback* getEventCallback() { return _eventCallback.get(); }
253
255 inline const Callback* getEventCallback() const { return _eventCallback.get(); }
256
258 inline void addEventCallback(Callback* nc) {
259 if (nc != NULL) {
260 if (_eventCallback.valid()) _eventCallback->addNestedCallback(nc);
261 else setEventCallback(nc);
262 }
263 }
264
265 template<class T> void addEventCallback(const ref_ptr<T>& nc) { addEventCallback(nc.get()); }
266
268 inline void removeEventCallback(Callback* nc) {
269 if (nc != NULL && _eventCallback.valid()) {
270 if (_eventCallback == nc)
271 {
272 ref_ptr<osg::Callback> new_nested_callback = nc->getNestedCallback();
273 nc->setNestedCallback(0);
274 setEventCallback(new_nested_callback.get()); // replace the callback by the nested one
275 }
276 else _eventCallback->removeNestedCallback(nc);
277 }
278 }
279
280 template<class T> void removeEventCallback(const ref_ptr<T>& nc) { removeEventCallback(nc.get()); }
281
285
286
289
290 template<class T> void setCullCallback(const ref_ptr<T>& nc) { setCullCallback(nc.get()); }
291
293 inline Callback* getCullCallback() { return _cullCallback.get(); }
294
296 inline const Callback* getCullCallback() const { return _cullCallback.get(); }
297
299 inline void addCullCallback(Callback* nc) {
300 if (nc != NULL) {
301 if (_cullCallback.valid()) _cullCallback->addNestedCallback(nc);
302 else setCullCallback(nc);
303 }
304 }
305
306 template<class T> void addCullCallback(const ref_ptr<T>& nc) { addCullCallback(nc.get()); }
307
309 inline void removeCullCallback(Callback* nc) {
310 if (nc != NULL && _cullCallback.valid()) {
311 if (_cullCallback == nc)
312 {
313 ref_ptr<osg::Callback> new_nested_callback = nc->getNestedCallback();
314 nc->setNestedCallback(0);
315 setCullCallback(new_nested_callback.get()); // replace the callback by the nested one
316 }
317 else _cullCallback->removeNestedCallback(nc);
318 }
319 }
320
321 template<class T> void removeCullCallback(const ref_ptr<T>& nc) { removeCullCallback(nc.get()); }
322
326 void setCullingActive(bool active);
327
330 inline bool getCullingActive() const { return _cullingActive; }
331
334
337 inline bool isCullingActive() const { return _numChildrenWithCullingDisabled==0 && _cullingActive && getBound().valid(); }
338
341
342
345
346
363 typedef unsigned int NodeMask;
365 inline void setNodeMask(NodeMask nm) { _nodeMask = nm; }
367 inline NodeMask getNodeMask() const { return _nodeMask; }
368
369
370
372 void setStateSet(osg::StateSet* stateset);
373
374 template<class T> void setStateSet(const osg::ref_ptr<T>& stateset) { setStateSet(stateset.get()); }
375
380
382 inline osg::StateSet* getStateSet() { return _stateset.get(); }
383
385 inline const osg::StateSet* getStateSet() const { return _stateset.get(); }
386
387
389 typedef std::vector<std::string> DescriptionList;
390
392 void setDescriptions(const DescriptionList& descriptions);
393
396
399
400
402 const std::string& getDescription(unsigned int i) const;
403
405 std::string& getDescription(unsigned int i);
406
408 unsigned int getNumDescriptions() const;
409
411 void addDescription(const std::string& desc);
412
413
415 void setInitialBound(const osg::BoundingSphere& bsphere) { _initialBound = bsphere; dirtyBound(); }
416
419
423
424
425 inline const BoundingSphere& getBound() const
426 {
428 {
430 if (_computeBoundCallback.valid())
431 _boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
432 else
433 _boundingSphere.expandBy(computeBound());
434
436 }
437 return _boundingSphere;
438 }
439
444
457
460
461 template<class T> void setComputeBoundingSphereCallback(const ref_ptr<T>& callback) { setComputeBoundingSphereCallback(callback.get()); }
462
465
468
470 virtual void setThreadSafeRefUnref(bool threadSafe);
471
473 virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/);
474
478 virtual void releaseGLObjects(osg::State* = 0) const;
479
480
481 protected:
482
490 virtual ~Node();
491
492
493
498
499 void addParent(osg::Group* parent);
501
503 friend class osg::Group;
504 friend class osg::Drawable;
505 friend class osg::StateSet;
506
510
514
516
519 void setNumChildrenWithCullingDisabled(unsigned int num);
520
522 void setNumChildrenWithOccluderNodes(unsigned int num);
523
525
527
528};
529
530}
531
532#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
std::vector< Matrix > MatrixList
A vector of NodePath, typically used to describe all the paths from a node to the potential root node...
Definition Node:53
std::vector< NodePath > NodePathList
A vector of NodePath, typically used to describe all the paths from a node to the potential root node...
Definition Node:50
BoundingSphered BoundingSphere
Definition BoundingSphere:308
std::vector< Node * > NodePath
A vector of Nodes pointers which is used to describe the path from a root node to a descendant.
Definition Node:47
The osgTerrain library is a NodeKit that provides geospecifc terrain rendering support.
Definition Node:29
Definition Callback:34
osg::Callback * getNestedCallback()
Definition Callback:89
void setNestedCallback(osg::Callback *cb)
Definition Callback:88
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
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
Definition Geometry:31
General group node which maintains a list of children.
Definition Group:29
Base class for all internal nodes in the scene graph.
Definition Node:72
virtual const osgTerrain::Terrain * asTerrain() const
convert 'const this' into a const Terrain pointer if Node is a Terrain, otherwise return 0.
Definition Node:159
void setEventCallback(const ref_ptr< T > &nc)
Definition Node:249
virtual void releaseGLObjects(osg::State *=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
void setCullCallback(Callback *nc)
Set cull node callback, called during cull traversal.
Definition Node:288
void setUpdateCallback(const ref_ptr< T > &nc)
Definition Node:208
void setUpdateCallback(Callback *nc)
Set update node callback, called during update traversal.
ref_ptr< Callback > _eventCallback
Definition Node:511
const Group * getParent(unsigned int i) const
Get a single const parent of node.
Definition Node:186
std::string & getDescription(unsigned int i)
Get a single description of the node.
virtual const Geode * asGeode() const
convert 'const this' into a const Geode pointer if Node is a Geode, otherwise return 0.
Definition Node:151
bool _cullingActive
Definition Node:517
void addDescription(const std::string &desc)
Add a description string to the node.
unsigned int _numChildrenWithOccluderNodes
Definition Node:521
void setEventCallback(Callback *nc)
Set event node callback, called during event traversal.
virtual void traverse(NodeVisitor &)
Traverse downwards : calls children's accept method with NodeVisitor.
Definition Node:167
ref_ptr< ComputeBoundingSphereCallback > _computeBoundCallback
Definition Node:495
unsigned int getNumParents() const
Get the number of parents of node.
Definition Node:192
bool containsOccluderNodes() const
return true if this node is an OccluderNode or the subgraph below this node are OccluderNodes.
DescriptionList & getDescriptions()
Get the description list of the node.
ref_ptr< Callback > _updateCallback
Definition Node:507
void setNumChildrenRequiringUpdateTraversal(unsigned int num)
NodeMask _nodeMask
Definition Node:524
void setNumChildrenWithOccluderNodes(unsigned int num)
virtual const char * libraryName() const
return the name of the node's library.
Definition Node:93
void removeEventCallback(Callback *nc)
Convenience method that removes a given callback from a node, even if that callback is nested.
Definition Node:268
bool isCullingActive() const
Return true if this node can be culled by view frustum, occlusion or small feature culling during the...
Definition Node:337
bool getCullingActive() const
Get the view frustum/small feature _cullingActive flag for this node.
Definition Node:330
unsigned int getNumDescriptions() const
Get the number of descriptions of the node.
virtual Geometry * asGeometry()
convert 'this' into a Geometry pointer if Node is a Geometry, otherwise return 0.
Definition Node:115
NodePathList getParentalNodePaths(osg::Node *haltTraversalAtNode=0) const
Get the list of node paths parent paths.
unsigned int getNumChildrenRequiringEventTraversal() const
Get the number of Children of this node which require Event traversal, since they have an Event Callb...
Definition Node:284
virtual Group * asGroup()
convert 'this' into a Group pointer if Node is a Group, otherwise return 0.
Definition Node:122
ref_ptr< StateSet > _stateset
Definition Node:526
NodeMask getNodeMask() const
Get the node Mask.
Definition Node:367
void setNumChildrenRequiringEventTraversal(unsigned int num)
std::vector< Group * > ParentList
A vector of osg::Group pointers which is used to store the parent(s) of node.
Definition Node:170
void removeCullCallback(Callback *nc)
Convenience method that removes a given callback from a node, even if that callback is nested.
Definition Node:309
void addParent(osg::Group *parent)
virtual Geode * asGeode()
Convert 'this' into a Geode pointer if Node is a Geode, otherwise return 0.
Definition Node:147
const osg::StateSet * getStateSet() const
Return the node's const StateSet.
Definition Node:385
osg::StateSet * getStateSet()
Return the node's StateSet.
Definition Node:382
unsigned int getNumChildrenWithCullingDisabled() const
Get the number of Children of this node which have culling disabled.
Definition Node:333
virtual Drawable * asDrawable()
convert 'this' into a Drawable pointer if Node is a Drawable, otherwise return 0.
Definition Node:108
virtual void resizeGLObjectBuffers(unsigned int)
Resize any per context GLObject buffers to specified size.
virtual const Switch * asSwitch() const
convert 'const this' into a const Switch pointer if Node is a Switch, otherwise return 0.
Definition Node:143
void removeUpdateCallback(const ref_ptr< T > &nc)
Definition Node:239
void addEventCallback(const ref_ptr< T > &nc)
Definition Node:265
ref_ptr< Callback > _cullCallback
Definition Node:515
void setStateSet(const osg::ref_ptr< T > &stateset)
Definition Node:374
unsigned int getNumChildrenWithOccluderNodes() const
Get the number of Children of this node which are or have OccluderNode's.
Definition Node:340
Node()
Construct a node.
osg::StateSet * getOrCreateStateSet()
return the node's StateSet, if one does not already exist create it set the node and return the newly...
void setInitialBound(const osg::BoundingSphere &bsphere)
Set the initial bounding volume to use when computing the overall bounding volume.
Definition Node:415
Group * getParent(unsigned int i)
Definition Node:179
virtual ~Node()
Node destructor.
void setCullingActive(bool active)
Set the view frustum/small feature culling of this node to be active or inactive.
virtual const Group * asGroup() const
convert 'const this' into a const Group pointer if Node is a Group, otherwise return 0.
Definition Node:125
void setComputeBoundingSphereCallback(ComputeBoundingSphereCallback *callback)
Set the compute bound callback to override the default computeBound.
Definition Node:459
virtual osgTerrain::Terrain * asTerrain()
Convert 'this' into a Transform pointer if Node is a Terrain, otherwise return 0.
Definition Node:155
std::vector< std::string > DescriptionList
A vector of std::string's which are used to describe the object.
Definition Node:389
void addEventCallback(Callback *nc)
Convenience method that sets the event callback of the node if it doesn't exist, or nest it into the ...
Definition Node:258
Callback * getUpdateCallback()
Get update node callback, called during update traversal.
Definition Node:211
virtual BoundingSphere computeBound() const
Compute the bounding sphere around Node's geometry or children.
friend class osg::Group
Definition Node:503
void addUpdateCallback(const ref_ptr< T > &nc)
Definition Node:224
virtual bool isSameKindAs(const Object *obj) const
return true if this and obj are of the same kind of object.
Definition Node:90
const BoundingSphere & getInitialBound() const
Set the initial bounding volume to use when computing the overall bounding volume.
Definition Node:418
virtual const char * className() const
return the name of the node's class type.
Definition Node:96
virtual Transform * asTransform()
Convert 'this' into a Transform pointer if Node is a Transform, otherwise return 0.
Definition Node:129
void setNodeMask(NodeMask nm)
Set the node mask.
Definition Node:365
Callback * getCullCallback()
Get cull node callback, called during cull traversal.
Definition Node:293
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
const Callback * getUpdateCallback() const
Get const update node callback, called during update traversal.
Definition Node:214
virtual const Transform * asTransform() const
convert 'const this' into a const Transform pointer if Node is a Transform, otherwise return 0.
Definition Node:133
unsigned int _numChildrenRequiringUpdateTraversal
Definition Node:508
const Callback * getCullCallback() const
Get const cull node callback, called during cull traversal.
Definition Node:296
void setCullCallback(const ref_ptr< T > &nc)
Definition Node:290
MatrixList getWorldMatrices(const osg::Node *haltTraversalAtNode=0) const
Get the list of matrices that transform this node from local coordinates to world coordinates.
virtual const Node * asNode() const
convert 'const this' into a const Node pointer if Object is a Node, otherwise return 0.
Definition Node:104
virtual const Drawable * asDrawable() const
convert 'const this' into a const Drawable pointer if Node is a Drawable, otherwise return 0.
Definition Node:111
void addCullCallback(Callback *nc)
Convenience method that sets the cull callback of the node if it doesn't exist, or nest it into the e...
Definition Node:299
void addCullCallback(const ref_ptr< T > &nc)
Definition Node:306
BoundingSphere _initialBound
Definition Node:494
void removeUpdateCallback(Callback *nc)
Convenience method that removes a given callback from a node, even if that callback is nested.
Definition Node:227
void setDescriptions(const DescriptionList &descriptions)
Set the list of string descriptions.
virtual void setThreadSafeRefUnref(bool threadSafe)
Set whether to use a mutex to ensure ref() and unref() are thread safe.
ParentList getParents()
Get the a copy of parent list of node.
Definition Node:177
void removeEventCallback(const ref_ptr< T > &nc)
Definition Node:280
const std::string & getDescription(unsigned int i) const
Get a single const description of the const node.
void setNumChildrenWithCullingDisabled(unsigned int num)
virtual Object * cloneType() const
clone an object of the same type as the node.
Definition Node:84
void setComputeBoundingSphereCallback(const ref_ptr< T > &callback)
Definition Node:461
const ParentList & getParents() const
Get the parent list of node.
Definition Node:173
unsigned int NodeMask
This is a set of bits (flags) that represent the Node.
Definition Node:363
const DescriptionList & getDescriptions() const
Get the const description list of the const node.
virtual Node * asNode()
Convert 'this' into a Node pointer if Object is a Node, otherwise return 0.
Definition Node:100
virtual Switch * asSwitch()
Convert 'this' into a Switch pointer if Node is a Switch, otherwise return 0.
Definition Node:139
void removeCullCallback(const ref_ptr< T > &nc)
Definition Node:321
void setStateSet(osg::StateSet *stateset)
Set the node's StateSet.
virtual Object * clone(const CopyOp &copyop) const
return a clone of a node, with Object* return type.
Definition Node:87
virtual void accept(NodeVisitor &nv)
Visitor Pattern : calls the apply method of a NodeVisitor with this node's type.
void addUpdateCallback(Callback *nc)
Convenience method that sets the update callback of the node if it doesn't exist, or nest it into the...
Definition Node:217
virtual const Geometry * asGeometry() const
convert 'const this' into a const Geometry pointer if Node is a Geometry, otherwise return 0.
Definition Node:118
void removeParent(osg::Group *parent)
void dirtyBound()
Mark this node's bounding sphere dirty.
virtual void ascend(NodeVisitor &nv)
Traverse upwards : calls parents' accept method with NodeVisitor.
Callback * getEventCallback()
Get event node callback, called during event traversal.
Definition Node:252
bool _boundingSphereComputed
Definition Node:497
Node(const Node &, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
friend class osg::Drawable
Definition Node:504
ParentList _parents
Definition Node:502
const ComputeBoundingSphereCallback * getComputeBoundingSphereCallback() const
Get the const compute bound callback.
Definition Node:467
const BoundingSphere & getBound() const
Definition Node:425
BoundingSphere _boundingSphere
Definition Node:496
ComputeBoundingSphereCallback * getComputeBoundingSphereCallback()
Get the compute bound callback.
Definition Node:464
const Callback * getEventCallback() const
Get const event node callback, called during event traversal.
Definition Node:255
unsigned int _numChildrenRequiringEventTraversal
Definition Node:512
unsigned int _numChildrenWithCullingDisabled
Definition Node:518
Callback to allow users to override the default computation of bounding volume.
Definition Node:447
ComputeBoundingSphereCallback()
Definition Node:448
META_Object(osg, ComputeBoundingSphereCallback)
ComputeBoundingSphereCallback(const ComputeBoundingSphereCallback &org, const CopyOp &copyop)
Definition Node:450
virtual BoundingSphere computeBound(const osg::Node &) const
Definition Node:455
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Object()
Construct an object.
Definition Object:69
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
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
Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
Definition Terrain:28
#define NULL
Definition Export:55
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.