TrueReality  v0.1.1912
trCore::Nodes::NodeVisitor Class Reference

Visitor for type safe operations on trCore::Nodes. More...

#include <NodeVisitor.h>

Inheritance diagram for trCore::Nodes::NodeVisitor:
Collaboration diagram for trCore::Nodes::NodeVisitor:

Public Types

enum  TraversalMode { TRAVERSE_NONE = 0, TRAVERSE_PARENTS = 1, TRAVERSE_ALL_CHILDREN = 2, TRAVERSE_ACTIVE_CHILDREN = 3 }
 
enum  VisitorType {
  NODE_VISITOR = 0, UPDATE_VISITOR = 1, EVENT_VISITOR = 2, COLLECT_OCCLUDER_VISITOR = 3,
  CULL_VISITOR = 4, INTERSECTION_VISITOR = 5
}
 
using BaseClass = trBase::Base
 
- Public Types inherited from trBase::Base
using BaseClass = trBase::SmrtClass
 
- Public Types inherited from trBase::SmrtClass
using BaseClass = osg::Referenced
 

Public Member Functions

 NodeVisitor (TraversalMode tm=TRAVERSE_NONE, const std::string name=CLASS_TYPE)
 Holds the class type name for efficient comparisons. More...
 
 NodeVisitor (VisitorType type, TraversalMode tm=TRAVERSE_NONE, const std::string name=CLASS_TYPE)
 Constructor. More...
 
virtual const std::string & GetType () const override
 Returns the class type. More...
 
virtual void SetName (const std::string &name)
 Sets this instances name. More...
 
virtual osg::NodeVisitor * AsOSGVisitor ()
 Returns a pointer to the internal OSG Node. More...
 
virtual const osg::NodeVisitor * AsOSGVisitor () const
 Returns a constant pointer to the internal OSG Node. More...
 
virtual void Reset ()
 Method to call to reset visitor. More...
 
void SetVisitorType (VisitorType type)
 Set the VisitorType, used to distinguish different visitors during traversal of the scene, typically used in the Node:Traverse() method to select which behavior to use for different types of traversal/visitors. More...
 
VisitorType GetVisitorType () const
 Get the VisitorType. More...
 
void SetTraversalNumber (unsigned int fn)
 Set the traversal number. More...
 
unsigned int GetTraversalNumber () const
 Get the traversal number. More...
 
void SetFrameStamp (FrameStamp *fs)
 Set the FrameStamp that this traversal is associated with. More...
 
const FrameStampGetFrameStamp () const
 Get the FrameStamp that this traversal is associated with. More...
 
void SetTraversalMask (Node::NodeMask mask)
 Set the TraversalMask of this NodeVisitor. More...
 
Node::NodeMask GetTraversalMask () const
 Get the TraversalMask. More...
 
void SetNodeMaskOverride (Node::NodeMask mask)
 
Node::NodeMask GetNodeMaskOverride () const
 
bool ValidNodeMask (const Nodes::Node &node) const
 Method to called by Node and its subclass' Node::Accept() method, if the result is true it is used to cull operations of nodes and their subgraphs. More...
 
void SetTraversalMode (TraversalMode mode)
 Set the traversal mode for Node::Traverse() to use when deciding which children of a node to traverse. More...
 
TraversalMode GetTraversalMode () const
 Get the traversal mode. More...
 
void Traverse (Node &node)
 Method for handling traversal of a nodes. More...
 
void PushOntoNodePath (Node *node)
 Method called by Node::Accept() method before a call to the NodeVisitor::Apply(..). More...
 
void PopFromNodePath ()
 Method called by Node::Accept() method after a call to NodeVisitor::Apply(..). More...
 
NodePathGetNodePath ()
 Get the non const NodePath from the top most node applied down to the current Node being visited. More...
 
const NodePathGetNodePath () const
 Get the const NodePath from the top most node applied down to the current Node being visited. More...
 
virtual trBase::Vec3 GetEyePoint () const
 Get the eye point in local coordinates. More...
 
virtual trBase::Vec3 GetViewPoint () const
 Get the view point in local coordinates. More...
 
virtual float GetDistanceToEyePoint (const trBase::Vec3 &, bool) const
 Get the distance from a point to the eye point, distance value in local coordinate system. More...
 
virtual float GetDistanceFromEyePoint (const trBase::Vec3 &, bool) const
 Get the distance of a point from the eye point, distance value in the eye coordinate system. More...
 
virtual float GetDistanceToViewPoint (const trBase::Vec3 &, bool) const
 Get the distance from a point to the view point, distance value in local coordinate system. More...
 
- Public Member Functions inherited from trBase::Base
 Base (const std::string &name=CLASS_TYPE)
 Holds the class type name for efficient comparisons. More...
 
virtual const std::string & GetName ()
 Returns this instances name. More...
 
virtual const std::string & GetName () const
 Returns this instances name. More...
 
virtual void SetUUID (const trBase::UniqueId &id)
 Overwrites the default internal UUID with the passed in one. More...
 
virtual const trBase::UniqueIdGetUUID (void)
 Returns the instances Universally Unique ID. More...
 
- Public Member Functions inherited from trBase::SmrtClass
 SmrtClass ()
 Adds an easy and swappable access to the base class. More...
 
 SmrtClass (bool threadSafeRefUnref)
 Constructor. More...
 
 SmrtClass (const SmrtClass &inst)
 Copy constructor. More...
 
virtual bool GetThreadSafeRefUnref ()
 Get whether a mutex is used to ensure Ref() and UnRef() are thread safe. More...
 
OpenThreads::Mutex * GetRefMutex () const
 Get the mutex used to ensure thread safety of Ref()/UnRef(). More...
 
int Ref () const
 Increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
int Unref () const
 Decrement the reference count by one, indicating that a pointer to this object is no longer referencing it. More...
 
int UnRefNoDelete () const
 Decrement the reference count by one, indicating that a pointer to this object is no longer referencing it. More...
 
int ReferenceCount () const
 Return the number of pointers currently referencing this object. More...
 

Static Public Attributes

static const trUtil::RefStr CLASS_TYPE = trUtil::RefStr("trCore::Nodes::NodeVisitor")
 Adds an easy and swappable access to the base class. More...
 
- Static Public Attributes inherited from trBase::Base
static const trUtil::RefStr CLASS_TYPE = trUtil::RefStr("trBase::Base")
 Adds an easy and swappable access to the base class. More...
 

Protected Member Functions

 ~NodeVisitor ()
 Destructor. More...
 
- Protected Member Functions inherited from trBase::Base
 ~Base ()
 Base destructor. More...
 
- Protected Member Functions inherited from trBase::SmrtClass
 ~SmrtClass ()
 

Protected Attributes

trBase::SmrtPtr< osg::NodeVisitor > mNodeVisitor
 The node visitor. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from trBase::SmrtClass
static OpenThreads::Mutex * GetGlobalReferencedMutex ()
 Get the optional global Referenced mutex, this can be shared between all trBase::SmrtClass. More...
 

Detailed Description

Visitor for type safe operations on trCore::Nodes.

Based on GOF's Visitor pattern. The NodeVisitor 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 call the appropriate Apply(..) method of the NodeVisitor. To 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 not be called.

Author
Maxim Serebrennik

Definition at line 55 of file trCore/Nodes/NodeVisitor.h.

Member Typedef Documentation

◆ BaseClass

Member Enumeration Documentation

◆ TraversalMode

Enumerator
TRAVERSE_NONE 
TRAVERSE_PARENTS 
TRAVERSE_ALL_CHILDREN 
TRAVERSE_ACTIVE_CHILDREN 

Definition at line 59 of file trCore/Nodes/NodeVisitor.h.

◆ VisitorType

Enumerator
NODE_VISITOR 
UPDATE_VISITOR 
EVENT_VISITOR 
COLLECT_OCCLUDER_VISITOR 
CULL_VISITOR 
INTERSECTION_VISITOR 

Definition at line 67 of file trCore/Nodes/NodeVisitor.h.

Constructor & Destructor Documentation

◆ NodeVisitor() [1/2]

trCore::Nodes::NodeVisitor::NodeVisitor ( TraversalMode  tm = TRAVERSE_NONE,
const std::string  name = CLASS_TYPE 
)

Holds the class type name for efficient comparisons.

Constructor.

Parameters
tm(Optional) The time.
name(Optional) The name.

Definition at line 168 of file trCore/Nodes/NodeVisitor.cpp.

◆ NodeVisitor() [2/2]

trCore::Nodes::NodeVisitor::NodeVisitor ( VisitorType  type,
TraversalMode  tm = TRAVERSE_NONE,
const std::string  name = CLASS_TYPE 
)

Constructor.

Parameters
typeThe type.
tm(Optional) The time.
name(Optional) The name.

Definition at line 174 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor, and trCore::Nodes::ToVisitorType().

Here is the call graph for this function:

◆ ~NodeVisitor()

trCore::Nodes::NodeVisitor::~NodeVisitor ( )
protected

Destructor.

Definition at line 340 of file trCore/Nodes/NodeVisitor.cpp.

Member Function Documentation

◆ AsOSGVisitor() [1/2]

osg::NodeVisitor * trCore::Nodes::NodeVisitor::AsOSGVisitor ( )
virtual

Returns a pointer to the internal OSG Node.

Returns
Null if it fails, else a pointer to an osg::Node.

Definition at line 194 of file trCore/Nodes/NodeVisitor.cpp.

References trBase::SmrtPtr< T >::Get(), and mNodeVisitor.

Here is the call graph for this function:

◆ AsOSGVisitor() [2/2]

const osg::NodeVisitor * trCore::Nodes::NodeVisitor::AsOSGVisitor ( ) const
virtual

Returns a constant pointer to the internal OSG Node.

Returns
Null if it fails, else a pointer to a const osg::Node.

Definition at line 200 of file trCore/Nodes/NodeVisitor.cpp.

References trBase::SmrtPtr< T >::Get(), and mNodeVisitor.

Here is the call graph for this function:

◆ GetDistanceFromEyePoint()

float trCore::Nodes::NodeVisitor::GetDistanceFromEyePoint ( const trBase::Vec3 ,
bool   
) const
inlinevirtual

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. If the GetDistanceFromEyePoint(pos) is not implemented than a default value of 0.0 is returned.*.

Parameters
parameter1The first parameter.
parameter2True to parameter 2.
Returns
The distance from eye point.

Definition at line 391 of file trCore/Nodes/NodeVisitor.h.

◆ GetDistanceToEyePoint()

float trCore::Nodes::NodeVisitor::GetDistanceToEyePoint ( const trBase::Vec3 ,
bool   
) const
inlinevirtual

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. If the GetDistanceFromEyePoint(pos) is not implemented then a default value of 0.0 is returned.

Parameters
parameter1The first parameter.
parameter2True to parameter 2.
Returns
The distance to eye point.

Definition at line 376 of file trCore/Nodes/NodeVisitor.h.

◆ GetDistanceToViewPoint()

float trCore::Nodes::NodeVisitor::GetDistanceToViewPoint ( const trBase::Vec3 ,
bool   
) const
inlinevirtual

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.*.

Parameters
parameter1The first parameter.
parameter2True to parameter 2.
Returns
The distance to view point.

Definition at line 406 of file trCore/Nodes/NodeVisitor.h.

◆ GetEyePoint()

trBase::Vec3 trCore::Nodes::NodeVisitor::GetEyePoint ( ) const
inlinevirtual

Get the eye point in local coordinates.

Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.

Returns
The eye point.

Definition at line 351 of file trCore/Nodes/NodeVisitor.h.

◆ GetFrameStamp()

const FrameStamp * trCore::Nodes::NodeVisitor::GetFrameStamp ( ) const
inline

Get the FrameStamp that this traversal is associated with.

NOTE: The user must handle the destruction of the returned pointer

Returns
Null if it fails, else the frame stamp.

Definition at line 242 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ GetNodeMaskOverride()

Node::NodeMask trCore::Nodes::NodeVisitor::GetNodeMaskOverride ( ) const
inline

Definition at line 266 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ GetNodePath() [1/2]

NodePath * trCore::Nodes::NodeVisitor::GetNodePath ( )

Get the non const NodePath from the top most node applied down to the current Node being visited.

Returns
The node path. It is up to the user to take control of the pointers life cycle to make sure there are no memory leaks.

Definition at line 308 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ GetNodePath() [2/2]

const NodePath * trCore::Nodes::NodeVisitor::GetNodePath ( ) const

Get the const NodePath from the top most node applied down to the current Node being visited.

Returns
The node path. It is up to the user to take control of the pointers life cycle to make sure there are no memory leaks.

Definition at line 324 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ GetTraversalMask()

Node::NodeMask trCore::Nodes::NodeVisitor::GetTraversalMask ( ) const
inline

Get the TraversalMask.

Returns
The traversal mask.

Definition at line 254 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ GetTraversalMode()

NodeVisitor::TraversalMode trCore::Nodes::NodeVisitor::GetTraversalMode ( ) const
inline

Get the traversal mode.

Returns
The traversal mode.

Definition at line 284 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor, and trCore::Nodes::ToTraversalMode().

Here is the call graph for this function:

◆ GetTraversalNumber()

unsigned int trCore::Nodes::NodeVisitor::GetTraversalNumber ( ) const
inline

Get the traversal number.

Typically used to denote the frame count.

Returns
The traversal number.

Definition at line 230 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ GetType()

const std::string & trCore::Nodes::NodeVisitor::GetType ( ) const
overridevirtual

Returns the class type.

Returns
The type.

Implements trBase::Base.

Definition at line 181 of file trCore/Nodes/NodeVisitor.cpp.

References CLASS_TYPE.

◆ GetViewPoint()

trBase::Vec3 trCore::Nodes::NodeVisitor::GetViewPoint ( ) const
inlinevirtual

Get the view point in local coordinates.

Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.

Returns
The view point.

Definition at line 361 of file trCore/Nodes/NodeVisitor.h.

◆ GetVisitorType()

NodeVisitor::VisitorType trCore::Nodes::NodeVisitor::GetVisitorType ( ) const
inline

Get the VisitorType.

Returns
The visitor type.

Definition at line 218 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor, and trCore::Nodes::ToVisitorType().

Here is the call graph for this function:

◆ PopFromNodePath()

void trCore::Nodes::NodeVisitor::PopFromNodePath ( )
inline

Method called by Node::Accept() method after a call to NodeVisitor::Apply(..).

Note, the user does not typically call PopFromNodePath() as it will be called automatically by the Node::Accept() method.

Definition at line 302 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ PushOntoNodePath()

void trCore::Nodes::NodeVisitor::PushOntoNodePath ( Node node)
inline

Method called by Node::Accept() method before a call to the NodeVisitor::Apply(..).

The back of the list will, therefore, be the current node being visited inside the Apply(..), and the rest of the list will be the parental sequence of nodes 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.

Parameters
[in,out]nodeIf non-null, the node.

Definition at line 296 of file trCore/Nodes/NodeVisitor.cpp.

References trCore::Nodes::Node::AsOSGNode(), and mNodeVisitor.

Here is the call graph for this function:

◆ Reset()

void trCore::Nodes::NodeVisitor::Reset ( )
virtual

Method to call to reset visitor.

Useful if your visitor accumulates state during a traversal, and you plan to reuse the visitor. To flush that state for the next traversal: call reset() prior to each traversal.

Definition at line 206 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ SetFrameStamp()

void trCore::Nodes::NodeVisitor::SetFrameStamp ( FrameStamp fs)
inline

Set the FrameStamp that this traversal is associated with.

Parameters
[in,out]fsIf non-null, the file system.

Definition at line 236 of file trCore/Nodes/NodeVisitor.cpp.

References trCore::Nodes::FrameStamp::AsOSGClass(), and mNodeVisitor.

Here is the call graph for this function:

◆ SetName()

void trCore::Nodes::NodeVisitor::SetName ( const std::string &  name)
virtual

Sets this instances name.

Parameters
nameThe name.

Reimplemented from trBase::Base.

Definition at line 187 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor, and trBase::Base::SetName().

Here is the call graph for this function:

◆ SetNodeMaskOverride()

void trCore::Nodes::NodeVisitor::SetNodeMaskOverride ( Node::NodeMask  mask)
inline

Definition at line 260 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ SetTraversalMask()

void trCore::Nodes::NodeVisitor::SetTraversalMask ( Node::NodeMask  mask)
inline

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. ValidNodeMask() is called automatically in the Node::Accept() method before any call to NodeVisitor::Apply(), Apply() is only ever called if ValidNodeMask returns true. Note, if NodeVisitor::_traversalMask is 0 then all operations will be switched off for all nodes. Whereas setting both _traversalMask and _nodeMaskOverride to 0xffffffff will allow a visitor to work on all nodes regardless of their own Node::_nodeMask state.

Parameters
maskThe mask.

Definition at line 248 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ SetTraversalMode()

void trCore::Nodes::NodeVisitor::SetTraversalMode ( NodeVisitor::TraversalMode  mode)
inline

Set the traversal mode for Node::Traverse() to use when 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.

Parameters
modeThe mode.

Definition at line 278 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor, and trCore::Nodes::ToTraversalMode().

Here is the call graph for this function:

◆ SetTraversalNumber()

void trCore::Nodes::NodeVisitor::SetTraversalNumber ( unsigned int  fn)
inline

Set the traversal number.

Typically used to denote the frame count.

Parameters
fnThe function.

Definition at line 224 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor.

◆ SetVisitorType()

void trCore::Nodes::NodeVisitor::SetVisitorType ( VisitorType  type)
inline

Set the VisitorType, used to distinguish different visitors during traversal of the scene, typically used in the Node:Traverse() method to select which behavior to use for different types of traversal/visitors.

Parameters
typeThe type.

Definition at line 212 of file trCore/Nodes/NodeVisitor.cpp.

References mNodeVisitor, and trCore::Nodes::ToVisitorType().

Here is the call graph for this function:

◆ Traverse()

void trCore::Nodes::NodeVisitor::Traverse ( Node node)
inline

Method for handling traversal of a nodes.

If you intend to use the visitor for actively traversing the scene graph then make sure the Accept() methods call this method unless they handle traversal directly.

Parameters
[in,out]nodeThe node.

Definition at line 290 of file trCore/Nodes/NodeVisitor.cpp.

References trCore::Nodes::Node::AsOSGNode(), and mNodeVisitor.

Here is the call graph for this function:

◆ ValidNodeMask()

bool trCore::Nodes::NodeVisitor::ValidNodeMask ( const Nodes::Node node) const
inline

Method to called by Node and its subclass' Node::Accept() method, if the result is true it is used to cull operations of nodes and their subgraphs.

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.

Parameters
nodeThe node.
Returns
True if it succeeds, false if it fails.

Definition at line 272 of file trCore/Nodes/NodeVisitor.cpp.

References trCore::Nodes::Node::AsOSGNode(), and mNodeVisitor.

Here is the call graph for this function:

Member Data Documentation

◆ CLASS_TYPE

const trUtil::RefStr trCore::Nodes::NodeVisitor::CLASS_TYPE = trUtil::RefStr("trCore::Nodes::NodeVisitor")
static

Adds an easy and swappable access to the base class.

Definition at line 79 of file trCore/Nodes/NodeVisitor.h.

Referenced by GetType(), and trCore::Nodes::ToTraversalMode().

◆ mNodeVisitor


The documentation for this class was generated from the following files: