2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_NODE
|
|
|
|
#define OSG_NODE 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/StateSet>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <osg/BoundingSphere>
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <osg/NodeCallback>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
class NodeVisitor;
|
|
|
|
class Group;
|
2002-09-12 23:34:31 +08:00
|
|
|
class Transform;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** META_Node macro define the standard clone, isSameKindAs, className
|
|
|
|
* and accept methods. Use when subclassing from Node to make it
|
|
|
|
* more convinient to define the required pure virtual methods.*/
|
2002-06-06 21:25:36 +08:00
|
|
|
#define META_Node(library,name) \
|
2002-03-27 07:52:52 +08:00
|
|
|
virtual osg::Object* cloneType() const { return osgNew name (); } \
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return osgNew name (*this,copyop); } \
|
2001-11-03 04:11:37 +08:00
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
2001-09-22 10:42:08 +08:00
|
|
|
virtual const char* className() const { return #name; } \
|
2002-06-06 21:25:36 +08:00
|
|
|
virtual const char* libraryName() const { return #library; } \
|
2002-02-06 05:54:46 +08:00
|
|
|
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } } \
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Base class for all internal nodes in the scene graph.
|
|
|
|
Provides interface for most common node operations (Composite Pattern).
|
|
|
|
*/
|
|
|
|
class SG_EXPORT Node : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Construct a node.
|
|
|
|
Initialize the parent list to empty, node name to "" and
|
|
|
|
bounding sphere dirty flag to true.*/
|
|
|
|
Node();
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Node(const Node&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
|
|
|
/** clone the an object of the same type as the node.*/
|
2002-03-27 07:52:52 +08:00
|
|
|
virtual Object* cloneType() const { return osgNew Node(); }
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
|
|
|
/** return a clone of a node, with Object* return type.*/
|
2002-03-27 07:52:52 +08:00
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew Node(*this,copyop); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** return true if this and obj are of the same kind of object.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Node*>(obj)!=NULL; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
/** return the name of the node's library.*/
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** return the name of the node's class type.*/
|
|
|
|
virtual const char* className() const { return "Node"; }
|
|
|
|
|
2002-09-12 23:34:31 +08:00
|
|
|
/** convert 'this' into a Group pointer if Node is a Group, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<Group*>(this).*/
|
|
|
|
virtual Group* asGroup() { return 0; }
|
|
|
|
/** convert 'const this' into a const Group pointer if Node is a Group, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const Group*>(this).*/
|
|
|
|
virtual const Group* asGroup() const { return 0; }
|
|
|
|
|
|
|
|
/** convert 'this' into a Transform pointer if Node is a Transform, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<Transform*>(this).*/
|
|
|
|
virtual Transform* asTransform() { return 0; }
|
|
|
|
/** convert 'const this' into a const Transform pointer if Node is a Transform, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const Transform*>(this).*/
|
|
|
|
virtual const Transform* asTransform() const { return 0; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Visitor Pattern : calls the apply method of a NodeVisitor with this node's type.*/
|
|
|
|
virtual void accept(NodeVisitor& nv);
|
|
|
|
/** Traverse upwards : calls parents' accept method with NodeVisitor.*/
|
|
|
|
virtual void ascend(NodeVisitor& nv);
|
|
|
|
/** Traverse downwards : calls children's accept method with NodeVisitor.*/
|
|
|
|
virtual void traverse(NodeVisitor& /*nv*/) {}
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the name of node using C++ style string.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setName( const std::string& name ) { _name = name; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Set the name of node using a C style string.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setName( const char* name ) { _name = name; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the name of node.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const std::string& getName() const { return _name; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** A vector of osg::Group pointers which is used to store the parent(s) of node.*/
|
|
|
|
typedef std::vector<Group*> ParentList;
|
|
|
|
|
|
|
|
/** Get the parent list of node. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const ParentList& getParents() const { return _parents; }
|
|
|
|
|
|
|
|
/** Get the a copy of parent list of node. A copy is returned to
|
2001-09-22 10:42:08 +08:00
|
|
|
* prevent modification of the parent list.*/
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
inline ParentList getParents() { return _parents; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
inline Group* getParent(unsigned int i) { return _parents[i]; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/**
|
2001-09-20 05:08:56 +08:00
|
|
|
* Get a single const parent of node.
|
2001-01-11 00:32:10 +08:00
|
|
|
* @param i index of the parent to get.
|
|
|
|
* @return the parent i.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline const Group* getParent(unsigned int i) const { return _parents[i]; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/**
|
|
|
|
* Get the number of parents of node.
|
|
|
|
* @return the number of parents of this node.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumParents() const { return _parents.size(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Set app node callback, called during app traversal. */
|
|
|
|
void setAppCallback(NodeCallback* nc);
|
|
|
|
|
|
|
|
/** Get app node callback, called during app traversal. */
|
|
|
|
inline NodeCallback* getAppCallback() { return _appCallback.get(); }
|
|
|
|
|
|
|
|
/** Get const app node callback, called during app traversal. */
|
|
|
|
inline const NodeCallback* getAppCallback() const { return _appCallback.get(); }
|
|
|
|
|
|
|
|
/** Get the number of Children of this node which require App traversal,
|
|
|
|
* since they have an AppCallback attached to them or their children.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumChildrenRequiringAppTraversal() const { return _numChildrenRequiringAppTraversal; }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2001-10-19 20:56:37 +08:00
|
|
|
|
2002-04-15 21:15:48 +08:00
|
|
|
/** Set cull node callback, called during cull traversal. */
|
|
|
|
void setCullCallback(NodeCallback* nc) { _cullCallback = nc; }
|
|
|
|
|
2002-11-11 16:04:40 +08:00
|
|
|
/** Get cull node callback, called during cull traversal. */
|
2002-04-15 21:15:48 +08:00
|
|
|
inline NodeCallback* getCullCallback() { return _cullCallback.get(); }
|
|
|
|
|
2002-11-11 16:04:40 +08:00
|
|
|
/** Get const cull node callback, called during cull traversal. */
|
2002-04-15 21:15:48 +08:00
|
|
|
inline const NodeCallback* getCullCallback() const { return _cullCallback.get(); }
|
|
|
|
|
2001-10-19 20:56:37 +08:00
|
|
|
/** Set the view frustum/small feature culling of this node to be active or inactive.
|
|
|
|
* The default value to true for _cullingActive. Used a guide
|
|
|
|
* to the cull traversal.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setCullingActive(bool active);
|
2001-10-19 20:56:37 +08:00
|
|
|
|
2002-06-03 23:39:41 +08:00
|
|
|
/** Get the view frustum/small feature _cullingActive flag for this node. Used a guide
|
2001-10-19 20:56:37 +08:00
|
|
|
* to the cull traversal.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool getCullingActive() const { return _cullingActive; }
|
2001-10-19 20:56:37 +08:00
|
|
|
|
|
|
|
/** Get the number of Children of this node which have culling disabled.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumChildrenWithCullingDisabled() const { return _numChildrenWithCullingDisabled; }
|
2001-10-19 20:56:37 +08:00
|
|
|
|
2002-06-03 23:39:41 +08:00
|
|
|
/** Return true if this node can be culled by view frustum, occlusion or small feature culling during the cull traversal.
|
|
|
|
* note, return true only if no children have culling disabled, and the local _cullingActive flag is true.*/
|
2002-11-11 16:52:24 +08:00
|
|
|
inline bool isCullingActive() const { return _numChildrenWithCullingDisabled==0 && _cullingActive && getBound().valid(); }
|
2002-06-03 23:39:41 +08:00
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
/** Get the number of Children of this node which are or have OccluderNode's.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumChildrenWithOccluderNodes() const { return _numChildrenWithOccluderNodes; }
|
2002-06-10 21:50:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** return true if this node is an OccluderNode or the subgraph below this node are OccluderNodes.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
bool containsOccluderNodes() const;
|
2001-10-19 20:56:37 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
typedef unsigned int NodeMask;
|
|
|
|
/** Set the node mask. Note, node mask is will be replaced by TraversalMask.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setNodeMask(NodeMask nm) { _nodeMask = nm; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the node Mask. Note, node mask is will be replaced by TraversalMask.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline NodeMask getNodeMask() const { return _nodeMask; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A vector of std::string's which are used to describe the object.*/
|
|
|
|
typedef std::vector<std::string> DescriptionList;
|
|
|
|
|
|
|
|
/** Get the description list of the const node.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const DescriptionList& getDescriptions() const { return _descriptions; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the description list of the const node.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline DescriptionList& getDescriptions() { return _descriptions; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get a single const description of the const node.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline const std::string& getDescription(unsigned int i) const { return _descriptions[i]; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get a single description of the node.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline std::string& getDescription(unsigned int i) { return _descriptions[i]; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the number of descriptions of the node.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumDescriptions() const { return _descriptions.size(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Add a description string to the node.*/
|
|
|
|
void addDescription(const std::string& desc) { _descriptions.push_back(desc); }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** set the node's StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setStateSet(osg::StateSet* dstate) { _stateset = dstate; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-05-04 06:47:57 +08:00
|
|
|
/** return the node's StateSet, if one does not already exist create it
|
|
|
|
* set the node and return the newly created StateSet. This ensures
|
|
|
|
* that a valid StateSet is always returned and can be used directly.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
osg::StateSet* getOrCreateStateSet();
|
2002-05-04 06:47:57 +08:00
|
|
|
|
|
|
|
/** return the node's StateSet. returns NULL if a stateset is not attached.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline osg::StateSet* getStateSet() { return _stateset.get(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-05-04 06:47:57 +08:00
|
|
|
/** return the node's const StateSet. returns NULL if a stateset is not attached.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the bounding sphere of node.
|
|
|
|
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const BoundingSphere& getBound() const
|
|
|
|
{
|
|
|
|
if(!_bsphere_computed) computeBound();
|
|
|
|
return _bsphere;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Mark this node's bounding sphere dirty.
|
|
|
|
Forcing it to be computed on the next call to getBound().*/
|
|
|
|
void dirtyBound();
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/** Node destructor. Note, is protected so that Nodes cannot
|
|
|
|
be deleted other than by being dereferenced and the reference
|
|
|
|
count being zero (see osg::Referenced), preventing the deletion
|
|
|
|
of nodes which are still in use. This also means that
|
|
|
|
Node's cannot be created on stack i.e Node node will not compile,
|
|
|
|
forcing all nodes to be created on the heap i.e Node* node
|
|
|
|
= new Node().*/
|
|
|
|
virtual ~Node();
|
|
|
|
|
|
|
|
|
|
|
|
/** Compute the bounding sphere around Node's geometry or children.
|
|
|
|
This method is automatically called by getBound() when the bounding
|
|
|
|
sphere has been marked dirty via dirtyBound().*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeBound() const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
mutable BoundingSphere _bsphere;
|
|
|
|
mutable bool _bsphere_computed;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
std::string _name;
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
void addParent(osg::Group* node);
|
|
|
|
void removeParent(osg::Group* node);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
ParentList _parents;
|
2002-01-19 06:34:07 +08:00
|
|
|
friend class osg::Group;
|
2002-07-10 23:35:47 +08:00
|
|
|
friend class osg::Drawable;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-10-19 20:56:37 +08:00
|
|
|
ref_ptr<NodeCallback> _appCallback;
|
2002-09-02 20:31:35 +08:00
|
|
|
unsigned int _numChildrenRequiringAppTraversal;
|
|
|
|
void setNumChildrenRequiringAppTraversal(unsigned int num);
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2002-04-15 21:15:48 +08:00
|
|
|
ref_ptr<NodeCallback> _cullCallback;
|
|
|
|
|
2001-10-19 20:56:37 +08:00
|
|
|
bool _cullingActive;
|
2002-09-02 20:31:35 +08:00
|
|
|
unsigned int _numChildrenWithCullingDisabled;
|
|
|
|
void setNumChildrenWithCullingDisabled(unsigned int num);
|
2001-10-19 20:56:37 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
unsigned int _numChildrenWithOccluderNodes;
|
|
|
|
void setNumChildrenWithOccluderNodes(unsigned int num);
|
2002-06-10 21:50:25 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
NodeMask _nodeMask;
|
|
|
|
|
|
|
|
DescriptionList _descriptions;
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
ref_ptr<StateSet> _stateset;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A vector of Nodes pointers which is used to describe the path from a root node to a descendant.*/
|
|
|
|
typedef std::vector<Node*> NodePath;
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|