2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_NODEVISITOR
|
|
|
|
#define OSG_NODEVISITOR 1
|
|
|
|
|
|
|
|
#include <osg/Node>
|
2002-02-06 05:54:46 +08:00
|
|
|
#include <osg/Matrix>
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <osg/FrameStamp>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2016-02-04 21:12:33 +08:00
|
|
|
#include <osg/ValueMap>
|
|
|
|
#include <osg/ValueStack>
|
|
|
|
|
2016-01-21 01:49:10 +08:00
|
|
|
|
|
|
|
namespace osgUtil { class UpdateVisitor; class CullVisitor; class IntersectionVisitor; }
|
|
|
|
namespace osgGA { class EventVisitor; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
class Billboard;
|
2005-04-30 23:16:05 +08:00
|
|
|
class ClearNode;
|
2002-05-02 08:14:40 +08:00
|
|
|
class ClipNode;
|
2005-04-30 23:16:05 +08:00
|
|
|
class CoordinateSystemNode;
|
|
|
|
class Geode;
|
2001-01-11 00:32:10 +08:00
|
|
|
class Group;
|
2005-04-30 23:16:05 +08:00
|
|
|
class LightSource;
|
|
|
|
class LOD;
|
Added DOFTransform, MatrixTransform and PositionAttitudeTransform to NodeVisitor.
Added osg::Matrix/Quat::makeRotate(angle1,axis1,angle2,axis2,angle3,axis3) and
osg::Matrix::rotate(angle1,axis1,angle2,axis2,angle3,axis3) method.
Made osg::Matrix/Quat::makeRotate(heading,pitch,roll) and
osg::Matrix::rotate(heading,pitch,roll) all deprecated API.
Fixed the Quat*Quat & Quat*=Quat multiplication methods so that they multiplied
in the correct order - they were reversed originally due to the Quat code being
based on code example which used the v' = M v ordering, rather than the OSG's
v' = v M ordering.
2002-08-18 22:42:43 +08:00
|
|
|
class MatrixTransform;
|
2005-04-30 23:16:05 +08:00
|
|
|
class OccluderNode;
|
2007-12-21 22:45:16 +08:00
|
|
|
class OcclusionQueryNode;
|
2005-04-30 23:16:05 +08:00
|
|
|
class PagedLOD;
|
Added DOFTransform, MatrixTransform and PositionAttitudeTransform to NodeVisitor.
Added osg::Matrix/Quat::makeRotate(angle1,axis1,angle2,axis2,angle3,axis3) and
osg::Matrix::rotate(angle1,axis1,angle2,axis2,angle3,axis3) method.
Made osg::Matrix/Quat::makeRotate(heading,pitch,roll) and
osg::Matrix::rotate(heading,pitch,roll) all deprecated API.
Fixed the Quat*Quat & Quat*=Quat multiplication methods so that they multiplied
in the correct order - they were reversed originally due to the Quat code being
based on code example which used the v' = M v ordering, rather than the OSG's
v' = v M ordering.
2002-08-18 22:42:43 +08:00
|
|
|
class PositionAttitudeTransform;
|
2002-04-01 00:40:44 +08:00
|
|
|
class Projection;
|
2005-04-30 23:16:05 +08:00
|
|
|
class ProxyNode;
|
2002-08-04 02:11:21 +08:00
|
|
|
class Sequence;
|
2005-04-30 23:16:05 +08:00
|
|
|
class Switch;
|
|
|
|
class TexGenNode;
|
|
|
|
class Transform;
|
2006-11-27 22:52:07 +08:00
|
|
|
class Camera;
|
2005-10-05 17:48:53 +08:00
|
|
|
class CameraView;
|
2014-05-12 20:10:35 +08:00
|
|
|
class Drawable;
|
|
|
|
class Geometry;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2016-01-21 01:49:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-23 04:11:05 +08:00
|
|
|
const unsigned int UNINITIALIZED_FRAME_NUMBER=0xffffffff;
|
|
|
|
|
2013-01-25 02:48:34 +08:00
|
|
|
#define META_NodeVisitor(library, name) \
|
2008-12-17 20:13:15 +08:00
|
|
|
virtual const char* libraryName() const { return #library; }\
|
|
|
|
virtual const char* className() const { return #name; }
|
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Visitor for type safe operations on osg::Nodes.
|
2012-03-22 01:36:20 +08:00
|
|
|
Based on GOF's Visitor pattern. The NodeVisitor
|
2001-10-11 04:20:14 +08:00
|
|
|
is useful for developing type safe operations to nodes
|
|
|
|
in the scene graph (as per Visitor pattern), and adds to this
|
|
|
|
support for optional scene graph traversal to allow
|
|
|
|
operations to be applied to whole scenes at once. The Visitor
|
|
|
|
pattern uses a technique of double dispatch as a mechanism to
|
2004-09-03 03:10:33 +08:00
|
|
|
call the appropriate apply(..) method of the NodeVisitor. To
|
2001-10-11 04:20:14 +08:00
|
|
|
use this feature one must use the Node::accept(NodeVisitor) which
|
|
|
|
is extended in each Node subclass, rather than the NodeVisitor
|
|
|
|
apply directly. So use root->accept(myVisitor); instead of
|
|
|
|
myVisitor.apply(*root). The later method will bypass the double
|
|
|
|
dispatch and the appropriate NodeVisitor::apply(..) method will
|
2012-03-22 01:36:20 +08:00
|
|
|
not be called. */
|
2013-09-24 23:08:23 +08:00
|
|
|
class OSG_EXPORT NodeVisitor : public virtual Object
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-08-12 05:26:58 +08:00
|
|
|
enum TraversalMode
|
|
|
|
{
|
2001-01-11 00:32:10 +08:00
|
|
|
TRAVERSE_NONE,
|
|
|
|
TRAVERSE_PARENTS,
|
|
|
|
TRAVERSE_ALL_CHILDREN,
|
2003-01-03 04:10:04 +08:00
|
|
|
TRAVERSE_ACTIVE_CHILDREN
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-12 05:26:58 +08:00
|
|
|
enum VisitorType
|
|
|
|
{
|
|
|
|
NODE_VISITOR = 0,
|
2002-12-19 23:55:40 +08:00
|
|
|
UPDATE_VISITOR,
|
2004-10-24 21:51:44 +08:00
|
|
|
EVENT_VISITOR,
|
2002-08-12 05:26:58 +08:00
|
|
|
COLLECT_OCCLUDER_VISITOR,
|
2014-08-01 02:29:31 +08:00
|
|
|
CULL_VISITOR,
|
|
|
|
INTERSECTION_VISITOR
|
2002-08-12 05:26:58 +08:00
|
|
|
};
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
NodeVisitor(TraversalMode tm=TRAVERSE_NONE);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-12 05:26:58 +08:00
|
|
|
NodeVisitor(VisitorType type,TraversalMode tm=TRAVERSE_NONE);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2013-09-24 23:08:23 +08:00
|
|
|
NodeVisitor(const NodeVisitor& nv, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-07-21 20:18:43 +08:00
|
|
|
virtual ~NodeVisitor();
|
2014-06-06 23:05:31 +08:00
|
|
|
|
2013-09-24 23:08:23 +08:00
|
|
|
META_Object(osg, NodeVisitor)
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2015-06-09 18:49:34 +08:00
|
|
|
/** Convert 'this' into a NodeVisitor pointer if Object is a NodeVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<NodeVisitor*>(this).*/
|
|
|
|
virtual NodeVisitor* asNodeVisitor() { return this; }
|
|
|
|
|
|
|
|
/** convert 'const this' into a const NodeVisitor pointer if Object is a NodeVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const NodeVisitor*>(this).*/
|
|
|
|
virtual const NodeVisitor* asNodeVisitor() const { return this; }
|
|
|
|
|
2016-01-21 01:49:10 +08:00
|
|
|
/** Convert 'this' into a osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<osgUtil::UpdateVisitor*>(this).*/
|
|
|
|
virtual osgUtil::UpdateVisitor* asUpdateVisitor() { return 0; }
|
|
|
|
|
|
|
|
/** convert 'const this' into a const osgUtil::UpdateVisitor pointer if Object is a osgUtil::UpdateVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const osgUtil::UpdateVisitor*>(this).*/
|
|
|
|
virtual const osgUtil::UpdateVisitor* asUpdateVisitor() const { return 0; }
|
|
|
|
|
|
|
|
/** Convert 'this' into a osgUtil::CullVisitor pointer if Object is a osgUtil::CullVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<osgUtil::CullVisitor*>(this).*/
|
|
|
|
virtual osgUtil::CullVisitor* asCullVisitor() { return 0; }
|
|
|
|
|
|
|
|
/** convert 'const this' into a const osgUtil::CullVisitor pointer if Object is a osgUtil::CullVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const osgUtil::CullVisitor*>(this).*/
|
|
|
|
virtual const osgUtil::CullVisitor* asCullVisitor() const { return 0; }
|
|
|
|
|
|
|
|
/** Convert 'this' into a osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<osgGA::EventVisitor*>(this).*/
|
|
|
|
virtual osgGA::EventVisitor* asEventVisitor() { return 0; }
|
|
|
|
|
|
|
|
/** convert 'const this' into a const osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const osgGA::EventVisitor*>(this).*/
|
|
|
|
virtual const osgGA::EventVisitor* asEventVisitor() const { return 0; }
|
|
|
|
|
|
|
|
/** Convert 'this' into a osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<osgUtil::IntersectionVisitor*>(this).*/
|
|
|
|
virtual osgUtil::IntersectionVisitor* asIntersectionVisitor() { return 0; }
|
|
|
|
|
|
|
|
/** convert 'const this' into a const osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const osgUtil::IntersectionVisitor*>(this).*/
|
|
|
|
virtual const osgUtil::IntersectionVisitor* asIntersectionVisitor() const { return 0; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Method to call to reset visitor. Useful if your visitor accumulates
|
2012-03-22 01:36:20 +08:00
|
|
|
state during a traversal, and you plan to reuse the visitor.
|
2004-09-03 03:10:33 +08:00
|
|
|
To flush that state for the next traversal: call reset() prior
|
2001-09-20 05:08:56 +08:00
|
|
|
to each traversal.*/
|
|
|
|
virtual void reset() {}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Set the VisitorType, used to distinguish different visitors during
|
2002-08-12 05:26:58 +08:00
|
|
|
* traversal of the scene, typically used in the Node::traverse() method
|
|
|
|
* to select which behaviour to use for different types of traversal/visitors.*/
|
|
|
|
inline void setVisitorType(VisitorType type) { _visitorType = type; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-12 05:26:58 +08:00
|
|
|
/** Get the VisitorType.*/
|
|
|
|
inline VisitorType getVisitorType() const { return _visitorType; }
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Set the traversal number. Typically used to denote the frame count.*/
|
2010-12-23 04:11:05 +08:00
|
|
|
inline void setTraversalNumber(unsigned int fn) { _traversalNumber = fn; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Get the traversal number. Typically used to denote the frame count.*/
|
2010-12-23 04:11:05 +08:00
|
|
|
inline unsigned int getTraversalNumber() const { return _traversalNumber; }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Set the FrameStamp that this traversal is associated with.*/
|
2001-09-22 10:42:08 +08:00
|
|
|
inline void setFrameStamp(FrameStamp* fs) { _frameStamp = fs; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Get the FrameStamp that this traversal is associated with.*/
|
2001-09-22 10:42:08 +08:00
|
|
|
inline const FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the TraversalMask of this NodeVisitor.
|
|
|
|
* The TraversalMask is used by the NodeVisitor::validNodeMask() method
|
|
|
|
* to determine whether to operate on a node and its subgraph.
|
2004-09-03 03:10:33 +08:00
|
|
|
* validNodeMask() is called automatically in the Node::accept() method before
|
2001-09-22 10:42:08 +08:00
|
|
|
* any call to NodeVisitor::apply(), apply() is only ever called if validNodeMask
|
|
|
|
* returns true. Note, if NodeVisitor::_traversalMask is 0 then all operations
|
2004-09-03 03:10:33 +08:00
|
|
|
* will be switched off for all nodes. Whereas setting both _traversalMask and
|
2001-09-22 10:42:08 +08:00
|
|
|
* _nodeMaskOverride to 0xffffffff will allow a visitor to work on all nodes
|
|
|
|
* regardless of their own Node::_nodeMask state.*/
|
2002-10-30 20:58:26 +08:00
|
|
|
inline void setTraversalMask(Node::NodeMask mask) { _traversalMask = mask; }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
/** Get the TraversalMask.*/
|
2002-10-30 20:58:26 +08:00
|
|
|
inline Node::NodeMask getTraversalMask() const { return _traversalMask; }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
/** Set the NodeMaskOverride mask.
|
2012-03-22 01:36:20 +08:00
|
|
|
* Used in validNodeMask() to determine whether to operate on a node or its
|
2001-09-22 10:42:08 +08:00
|
|
|
* subgraph, by OR'ing NodeVisitor::_nodeMaskOverride with the Node's own Node::_nodeMask.
|
|
|
|
* Typically used to force on nodes which may have
|
|
|
|
* been switched off by their own Node::_nodeMask.*/
|
2002-10-30 20:58:26 +08:00
|
|
|
inline void setNodeMaskOverride(Node::NodeMask mask) { _nodeMaskOverride = mask; }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
/** Get the NodeMaskOverride mask.*/
|
2002-10-30 20:58:26 +08:00
|
|
|
inline Node::NodeMask getNodeMaskOverride() const { return _nodeMaskOverride; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Method to called by Node and its subclass' Node::accept() method, if the result is true
|
2004-09-03 03:10:33 +08:00
|
|
|
* it is used to cull operations of nodes and their subgraphs.
|
2001-09-22 10:42:08 +08:00
|
|
|
* Return true if the result of a bit wise and of the NodeVisitor::_traversalMask
|
|
|
|
* with the bit or between NodeVistor::_nodeMaskOverride and the Node::_nodeMask.
|
|
|
|
* default values for _traversalMask is 0xffffffff, _nodeMaskOverride is 0x0,
|
|
|
|
* and osg::Node::_nodeMask is 0xffffffff. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool validNodeMask(const osg::Node& node) const
|
2001-09-22 10:42:08 +08:00
|
|
|
{
|
|
|
|
return (getTraversalMask() & (getNodeMaskOverride() | node.getNodeMask()))!=0;
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Set the traversal mode for Node::traverse() to use when
|
2001-01-11 00:32:10 +08:00
|
|
|
deciding which children of a node to traverse. If a
|
|
|
|
NodeVisitor has been attached via setTraverseVisitor()
|
|
|
|
and the new mode is not TRAVERSE_VISITOR then the attached
|
|
|
|
visitor is detached. Default mode is TRAVERSE_NONE.*/
|
2003-01-03 04:10:04 +08:00
|
|
|
inline void setTraversalMode(TraversalMode mode) { _traversalMode = mode; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the traversal mode.*/
|
2002-10-30 20:58:26 +08:00
|
|
|
inline TraversalMode getTraversalMode() const { return _traversalMode; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2016-02-04 21:12:33 +08:00
|
|
|
|
|
|
|
/** Set the ValueMap used to store Values that can be reused over a series of traversals. */
|
|
|
|
inline void setValueMap(ValueMap* ps) { _valueMap = ps; }
|
|
|
|
|
|
|
|
/** Get the ValueMap. */
|
|
|
|
inline ValueMap* getValueMap() { return _valueMap.get(); }
|
|
|
|
|
|
|
|
/** Get the ValueMap. */
|
|
|
|
inline const ValueMap* getValueMap() const { return _valueMap.get(); }
|
|
|
|
|
|
|
|
/** Get the ValueMap. */
|
|
|
|
inline ValueMap* getOrCreateValueMap()
|
|
|
|
{
|
|
|
|
if (!_valueMap) _valueMap = new ValueMap;
|
|
|
|
return _valueMap.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the ValueStack used to stack Values during traversal. */
|
|
|
|
inline void setValueStack(ValueStack* ps) { _valueStack = ps; }
|
|
|
|
|
|
|
|
/** Get the ValueStack. */
|
|
|
|
inline ValueStack* getValueStack() { return _valueStack.get(); }
|
|
|
|
|
|
|
|
/** Get the const ValueStack. */
|
|
|
|
inline const ValueStack* getValueStack() const { return _valueStack.get(); }
|
|
|
|
|
|
|
|
/** Get the ValueStack. */
|
|
|
|
inline ValueStack* getOrCreateValueStack()
|
|
|
|
{
|
|
|
|
if (!_valueStack) _valueStack = new ValueStack;
|
|
|
|
return _valueStack.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Method for handling traversal of a nodes.
|
2012-03-22 01:36:20 +08:00
|
|
|
If you intend to use the visitor for actively traversing
|
2001-01-11 00:32:10 +08:00
|
|
|
the scene graph then make sure the accept() methods call
|
|
|
|
this method unless they handle traversal directly.*/
|
2002-02-06 05:54:46 +08:00
|
|
|
inline void traverse(Node& node)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-01-03 04:10:04 +08:00
|
|
|
if (_traversalMode==TRAVERSE_PARENTS) node.ascend(*this);
|
2001-09-20 05:08:56 +08:00
|
|
|
else if (_traversalMode!=TRAVERSE_NONE) node.traverse(*this);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Method called by osg::Node::accept() method before
|
2004-09-03 03:10:33 +08:00
|
|
|
* a call to the NodeVisitor::apply(..). The back of the list will,
|
2002-02-06 05:54:46 +08:00
|
|
|
* therefore, be the current node being visited inside the apply(..),
|
2012-03-22 01:36:20 +08:00
|
|
|
* and the rest of the list will be the parental sequence of nodes
|
2002-02-06 05:54:46 +08:00
|
|
|
* from the top most node applied down the graph to the current node.
|
|
|
|
* Note, the user does not typically call pushNodeOnPath() as it
|
|
|
|
* will be called automatically by the Node::accept() method.*/
|
2004-07-30 23:44:59 +08:00
|
|
|
inline void pushOntoNodePath(Node* node) { if (_traversalMode!=TRAVERSE_PARENTS) _nodePath.push_back(node); else _nodePath.insert(_nodePath.begin(),node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Method called by osg::Node::accept() method after
|
|
|
|
* a call to NodeVisitor::apply(..).
|
2004-09-16 03:07:56 +08:00
|
|
|
* Note, the user does not typically call popFromNodePath() as it
|
2002-02-06 05:54:46 +08:00
|
|
|
* will be called automatically by the Node::accept() method.*/
|
2004-07-30 23:44:59 +08:00
|
|
|
inline void popFromNodePath() { if (_traversalMode!=TRAVERSE_PARENTS) _nodePath.pop_back(); else _nodePath.erase(_nodePath.begin()); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Get the non const NodePath from the top most node applied down
|
|
|
|
* to the current Node being visited.*/
|
|
|
|
NodePath& getNodePath() { return _nodePath; }
|
|
|
|
|
|
|
|
/** Get the const NodePath from the top most node applied down
|
|
|
|
* to the current Node being visited.*/
|
|
|
|
const NodePath& getNodePath() const { return _nodePath; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-12-17 23:41:05 +08:00
|
|
|
/** Get the eye point in local coordinates.
|
|
|
|
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.*/
|
|
|
|
virtual osg::Vec3 getEyePoint() const { return Vec3(0.0f,0.0f,0.0f); }
|
|
|
|
|
2006-12-16 01:27:18 +08:00
|
|
|
/** Get the view point in local coordinates.
|
|
|
|
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.*/
|
|
|
|
virtual osg::Vec3 getViewPoint() const { return getEyePoint(); }
|
|
|
|
|
2002-10-07 04:33:13 +08:00
|
|
|
/** Get the distance from a point to the eye point, distance value in local coordinate system.
|
|
|
|
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.
|
2004-09-03 03:10:33 +08:00
|
|
|
* If the getDistanceFromEyePoint(pos) is not implemented then a default value of 0.0 is returned.*/
|
2002-11-12 18:22:38 +08:00
|
|
|
virtual float getDistanceToEyePoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
|
2002-10-07 04:33:13 +08:00
|
|
|
|
|
|
|
/** Get the distance of a point from the eye point, distance value in the eye coordinate system.
|
|
|
|
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.
|
2004-09-03 03:10:33 +08:00
|
|
|
* If the getDistanceFromEyePoint(pos) is not implemented than a default value of 0.0 is returned.*/
|
2002-11-12 18:22:38 +08:00
|
|
|
virtual float getDistanceFromEyePoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2006-12-16 01:27:18 +08:00
|
|
|
/** Get the distance from a point to the view point, distance value in local coordinate system.
|
|
|
|
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.
|
|
|
|
* If the getDistanceToViewPoint(pos) is not implemented then a default value of 0.0 is returned.*/
|
|
|
|
virtual float getDistanceToViewPoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-05-12 20:10:35 +08:00
|
|
|
virtual void apply(Drawable& drawable);
|
2014-06-26 22:16:11 +08:00
|
|
|
virtual void apply(Geometry& geometry);
|
2006-12-16 01:27:18 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(Node& node);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(Geode& node);
|
|
|
|
virtual void apply(Billboard& node);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(Group& node);
|
Added DOFTransform, MatrixTransform and PositionAttitudeTransform to NodeVisitor.
Added osg::Matrix/Quat::makeRotate(angle1,axis1,angle2,axis2,angle3,axis3) and
osg::Matrix::rotate(angle1,axis1,angle2,axis2,angle3,axis3) method.
Made osg::Matrix/Quat::makeRotate(heading,pitch,roll) and
osg::Matrix::rotate(heading,pitch,roll) all deprecated API.
Fixed the Quat*Quat & Quat*=Quat multiplication methods so that they multiplied
in the correct order - they were reversed originally due to the Quat code being
based on code example which used the v' = M v ordering, rather than the OSG's
v' = v M ordering.
2002-08-18 22:42:43 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(ProxyNode& node);
|
2005-04-30 23:16:05 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(Projection& node);
|
Added DOFTransform, MatrixTransform and PositionAttitudeTransform to NodeVisitor.
Added osg::Matrix/Quat::makeRotate(angle1,axis1,angle2,axis2,angle3,axis3) and
osg::Matrix::rotate(angle1,axis1,angle2,axis2,angle3,axis3) method.
Made osg::Matrix/Quat::makeRotate(heading,pitch,roll) and
osg::Matrix::rotate(heading,pitch,roll) all deprecated API.
Fixed the Quat*Quat & Quat*=Quat multiplication methods so that they multiplied
in the correct order - they were reversed originally due to the Quat code being
based on code example which used the v' = M v ordering, rather than the OSG's
v' = v M ordering.
2002-08-18 22:42:43 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(CoordinateSystemNode& node);
|
2004-05-03 05:50:15 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(ClipNode& node);
|
|
|
|
virtual void apply(TexGenNode& node);
|
|
|
|
virtual void apply(LightSource& node);
|
2002-08-22 17:19:41 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(Transform& node);
|
|
|
|
virtual void apply(Camera& node);
|
|
|
|
virtual void apply(CameraView& node);
|
|
|
|
virtual void apply(MatrixTransform& node);
|
|
|
|
virtual void apply(PositionAttitudeTransform& node);
|
Added DOFTransform, MatrixTransform and PositionAttitudeTransform to NodeVisitor.
Added osg::Matrix/Quat::makeRotate(angle1,axis1,angle2,axis2,angle3,axis3) and
osg::Matrix::rotate(angle1,axis1,angle2,axis2,angle3,axis3) method.
Made osg::Matrix/Quat::makeRotate(heading,pitch,roll) and
osg::Matrix::rotate(heading,pitch,roll) all deprecated API.
Fixed the Quat*Quat & Quat*=Quat multiplication methods so that they multiplied
in the correct order - they were reversed originally due to the Quat code being
based on code example which used the v' = M v ordering, rather than the OSG's
v' = v M ordering.
2002-08-18 22:42:43 +08:00
|
|
|
|
2008-06-27 20:35:56 +08:00
|
|
|
virtual void apply(Switch& node);
|
|
|
|
virtual void apply(Sequence& node);
|
|
|
|
virtual void apply(LOD& node);
|
|
|
|
virtual void apply(PagedLOD& node);
|
|
|
|
virtual void apply(ClearNode& node);
|
|
|
|
virtual void apply(OccluderNode& node);
|
|
|
|
virtual void apply(OcclusionQueryNode& node);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Callback for managing database paging, such as generated by PagedLOD nodes.*/
|
2003-07-08 22:44:00 +08:00
|
|
|
class DatabaseRequestHandler : public osg::Referenced
|
|
|
|
{
|
2007-08-22 17:42:27 +08:00
|
|
|
public:
|
2009-05-11 19:39:12 +08:00
|
|
|
|
2007-08-22 17:42:27 +08:00
|
|
|
DatabaseRequestHandler():
|
|
|
|
Referenced(true) {}
|
2009-05-11 19:39:12 +08:00
|
|
|
|
2011-01-13 03:29:24 +08:00
|
|
|
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;
|
2009-05-11 19:39:12 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
protected:
|
|
|
|
virtual ~DatabaseRequestHandler() {}
|
|
|
|
};
|
2009-05-11 19:39:12 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
/** Set the handler for database requests.*/
|
|
|
|
void setDatabaseRequestHandler(DatabaseRequestHandler* handler) { _databaseRequestHandler = handler; }
|
2009-05-11 19:39:12 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
/** Get the handler for database requests.*/
|
|
|
|
DatabaseRequestHandler* getDatabaseRequestHandler() { return _databaseRequestHandler.get(); }
|
|
|
|
|
|
|
|
/** Get the const handler for database requests.*/
|
|
|
|
const DatabaseRequestHandler* getDatabaseRequestHandler() const { return _databaseRequestHandler.get(); }
|
|
|
|
|
|
|
|
|
2010-02-26 02:03:14 +08:00
|
|
|
/** Callback for managing image paging, such as generated by PagedLOD nodes.*/
|
2008-07-22 05:00:57 +08:00
|
|
|
class ImageRequestHandler : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
ImageRequestHandler():
|
|
|
|
Referenced(true) {}
|
2008-07-26 00:11:51 +08:00
|
|
|
|
|
|
|
virtual double getPreLoadTime() const = 0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
virtual osg::ref_ptr<osg::Image> readRefImageFile(const std::string& fileName, const osg::Referenced* options=0) = 0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
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;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
protected:
|
|
|
|
virtual ~ImageRequestHandler() {}
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
/** Set the handler for image requests.*/
|
|
|
|
void setImageRequestHandler(ImageRequestHandler* handler) { _imageRequestHandler = handler; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
/** Get the handler for image requests.*/
|
|
|
|
ImageRequestHandler* getImageRequestHandler() { return _imageRequestHandler.get(); }
|
|
|
|
|
|
|
|
/** Get the const handler for image requests.*/
|
|
|
|
const ImageRequestHandler* getImageRequestHandler() const { return _imageRequestHandler.get(); }
|
|
|
|
|
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
VisitorType _visitorType;
|
2010-12-23 04:11:05 +08:00
|
|
|
unsigned int _traversalNumber;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
ref_ptr<FrameStamp> _frameStamp;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
TraversalMode _traversalMode;
|
|
|
|
Node::NodeMask _traversalMask;
|
|
|
|
Node::NodeMask _nodeMaskOverride;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
NodePath _nodePath;
|
|
|
|
|
|
|
|
ref_ptr<DatabaseRequestHandler> _databaseRequestHandler;
|
2008-07-22 05:00:57 +08:00
|
|
|
ref_ptr<ImageRequestHandler> _imageRequestHandler;
|
2003-05-07 23:26:08 +08:00
|
|
|
|
2016-02-04 21:12:33 +08:00
|
|
|
osg::ref_ptr<ValueMap> _valueMap;
|
|
|
|
osg::ref_ptr<ValueStack> _valueStack;
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Convenience functor for assisting visiting of arrays of osg::Node's.*/
|
2009-01-07 17:49:49 +08:00
|
|
|
class NodeAcceptOp
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2009-01-07 17:49:49 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
NodeAcceptOp(NodeVisitor& nv):_nv(nv) {}
|
|
|
|
NodeAcceptOp(const NodeAcceptOp& naop):_nv(naop._nv) {}
|
|
|
|
|
|
|
|
void operator () (Node* node) { node->accept(_nv); }
|
|
|
|
void operator () (ref_ptr<Node> node) { node->accept(_nv); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2009-01-07 23:35:28 +08:00
|
|
|
NodeAcceptOp& operator = (const NodeAcceptOp&) { return *this; }
|
2009-01-07 17:49:49 +08:00
|
|
|
|
|
|
|
NodeVisitor& _nv;
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
2016-02-04 21:12:33 +08:00
|
|
|
|
|
|
|
class PushPopObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
PushPopObject(NodeVisitor* nv, const Referenced* key, Object* value):
|
|
|
|
_valueStack(0),
|
|
|
|
_key(0)
|
|
|
|
{
|
|
|
|
if (key)
|
|
|
|
{
|
|
|
|
_valueStack = nv->getOrCreateValueStack();
|
|
|
|
_key = key;
|
|
|
|
_valueStack->push(_key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PushPopObject(ValueStack* valueStack, const Referenced* key, Object* value):
|
|
|
|
_valueStack(valueStack),
|
|
|
|
_key(0)
|
|
|
|
{
|
|
|
|
if (_valueStack && key)
|
|
|
|
{
|
|
|
|
_key = key;
|
|
|
|
_valueStack->push(_key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ~PushPopObject()
|
|
|
|
{
|
|
|
|
if (_valueStack) _valueStack->pop(_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ValueStack* _valueStack;
|
|
|
|
const Referenced* _key;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PushPopValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
PushPopValue(NodeVisitor* nv, const Referenced* key, const T& value):
|
|
|
|
_valueStack(0),
|
|
|
|
_key(0)
|
|
|
|
{
|
|
|
|
if (key)
|
|
|
|
{
|
|
|
|
_valueStack = nv->getOrCreateValueStack();
|
|
|
|
_key = key;
|
|
|
|
_valueStack->push(_key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
PushPopValue(ValueStack* valueStack, const Referenced* key, const T& value):
|
|
|
|
_valueStack(valueStack),
|
|
|
|
_key(0)
|
|
|
|
{
|
|
|
|
if (_valueStack && key)
|
|
|
|
{
|
|
|
|
_key = key;
|
|
|
|
_valueStack->push(_key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ~PushPopValue()
|
|
|
|
{
|
|
|
|
if (_valueStack) _valueStack->pop(_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ValueStack* _valueStack;
|
|
|
|
const Referenced* _key;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline ValueStack* getOrCreateUserObjectOfType<NodeVisitor,ValueStack>(NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
return nv->getOrCreateValueStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline ValueMap* getOrCreateUserObjectOfType<NodeVisitor,ValueMap>(NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
return nv->getOrCreateValueMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|