OpenWalnut  1.5.0dev
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
WGEGroupNode Class Reference

Class to wrap around the osg Group node and providing a thread safe add/removal mechanism. More...

#include <WGEGroupNode.h>

+ Inheritance diagram for WGEGroupNode:
+ Collaboration diagram for WGEGroupNode:

Classes

struct  ChildOperation
 A struct denoting an operation on this group. More...
 
class  SafeUpdaterCallback
 Update callback which inserts and removes nodes from m_childRemovalQueue and m_childInsertionQueue to the group node. More...
 

Public Types

typedef WPredicateHelper::ArbitraryPredicateBase< osg::ref_ptr< osg::Node > const > NodePredicate
 The base type of predicate. More...
 

Public Member Functions

 WGEGroupNode ()
 Default constructor. More...
 
void insert (osg::ref_ptr< osg::Node > node)
 Adds the specified node to the child list of this node in a safe manner. More...
 
void remove (osg::ref_ptr< osg::Node > node)
 Removes the specified node from this group in a thread safe manner. More...
 
void remove_if (std::shared_ptr< WGEGroupNode::NodePredicate > predicate)
 Removes a node if the specified predicate evaluates to true. More...
 
void clear ()
 Removes all children from this node. More...
 

Protected Types

enum  ChildOperationType { INSERT = 0 , REMOVE , REMOVE_IF , CLEAR }
 The type of operation to perform. More...
 

Protected Member Functions

virtual ~WGEGroupNode ()
 Destructor. More...
 

Protected Attributes

osg::ref_ptr< SafeUpdaterCallbackm_nodeUpdater
 Node callback used to update this root node. More...
 
std::queue< std::shared_ptr< ChildOperation > > m_childOperationQueue
 Queue of childs that need to be added/removed during the next update cycle. More...
 
std::shared_mutex m_childOperationQueueLock
 Lock used for inserting and removing childs into the child insertion/removal queue. More...
 
bool m_childOperationQueueDirty
 Flag denoting whether the m_childOperationQueue should be considered during the next update of the node. More...
 
bool m_removeAll
 True whenever all child nodes should be removed. More...
 

Detailed Description

Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.

Please be sure to use addUpdateCallback() to set your own update callbacks instead of setUpdateCallback, as this class already has set a callback, which would be overwritten by a subsequent call to setUpdateCallback(). It is derived from osg::MatrixTransform to allow easy transformations of a whole bunch of nodes.

Definition at line 47 of file WGEGroupNode.h.

Member Typedef Documentation

◆ NodePredicate

typedef WPredicateHelper::ArbitraryPredicateBase< osg::ref_ptr< osg::Node > const > WGEGroupNode::NodePredicate

The base type of predicate.

Use a specific WPredicateHelper::ArbitraryPredicate instance. For details, see WPredicateHelper::ArbitraryPredicateBase.

Definition at line 76 of file WGEGroupNode.h.

Member Enumeration Documentation

◆ ChildOperationType

The type of operation to perform.

Enumerator
REMOVE 

insert the specified node

REMOVE_IF 

remove the specified node

CLEAR 

remove all items where the predicate evaluates to true

clear group node completely

Definition at line 123 of file WGEGroupNode.h.

Constructor & Destructor Documentation

◆ WGEGroupNode()

WGEGroupNode::WGEGroupNode ( )

Default constructor.

Definition at line 34 of file WGEGroupNode.cpp.

References m_nodeUpdater.

◆ ~WGEGroupNode()

WGEGroupNode::~WGEGroupNode ( )
protectedvirtual

Destructor.

Definition at line 50 of file WGEGroupNode.cpp.

Member Function Documentation

◆ clear()

void WGEGroupNode::clear ( )

Removes all children from this node.

Definition at line 79 of file WGEGroupNode.cpp.

References CLEAR, m_childOperationQueue, m_childOperationQueueDirty, and m_childOperationQueueLock.

◆ insert()

void WGEGroupNode::insert ( osg::ref_ptr< osg::Node >  node)

Adds the specified node to the child list of this node in a safe manner.

OSG officially requires nodes to be added exclusively during update callbacks. Using this method it is ensured to be added during update cycle.

Parameters
nodethe node to add.
Note
the node may not be added instantly. So do not assume that containsNode ( node ) will return true.

Definition at line 55 of file WGEGroupNode.cpp.

References m_childOperationQueue, m_childOperationQueueDirty, and m_childOperationQueueLock.

Referenced by WGEOffscreenRenderNode::addGeometryRenderPass(), WGEOffscreenRenderNode::addRenderPass(), WGEBorderLayout::WGEBorderLayout(), and WGEOffscreenRenderNode::WGEOffscreenRenderNode().

+ Here is the caller graph for this function:

◆ remove()

void WGEGroupNode::remove ( osg::ref_ptr< osg::Node >  node)

Removes the specified node from this group in a thread safe manner.

It returns if the node has been removed.

Parameters
nodethe node to remove

Definition at line 63 of file WGEGroupNode.cpp.

References m_childOperationQueue, m_childOperationQueueDirty, m_childOperationQueueLock, and REMOVE.

◆ remove_if()

void WGEGroupNode::remove_if ( std::shared_ptr< WGEGroupNode::NodePredicate predicate)

Removes a node if the specified predicate evaluates to true.

See also
WPredicateHelper::ArbitraryPredicate for details.
Parameters
predicatethe predicate.

Definition at line 71 of file WGEGroupNode.cpp.

References m_childOperationQueue, m_childOperationQueueDirty, m_childOperationQueueLock, and REMOVE_IF.

Member Data Documentation

◆ m_childOperationQueue

std::queue< std::shared_ptr< ChildOperation > > WGEGroupNode::m_childOperationQueue
protected

Queue of childs that need to be added/removed during the next update cycle.

It is a pair per operation, where the bool is denoting removal or insertion.

Definition at line 172 of file WGEGroupNode.h.

Referenced by clear(), insert(), WGEGroupNode::SafeUpdaterCallback::operator()(), remove(), and remove_if().

◆ m_childOperationQueueDirty

bool WGEGroupNode::m_childOperationQueueDirty
protected

Flag denoting whether the m_childOperationQueue should be considered during the next update of the node.

Definition at line 182 of file WGEGroupNode.h.

Referenced by clear(), insert(), WGEGroupNode::SafeUpdaterCallback::operator()(), remove(), and remove_if().

◆ m_childOperationQueueLock

std::shared_mutex WGEGroupNode::m_childOperationQueueLock
protected

Lock used for inserting and removing childs into the child insertion/removal queue.

Definition at line 177 of file WGEGroupNode.h.

Referenced by clear(), insert(), WGEGroupNode::SafeUpdaterCallback::operator()(), remove(), and remove_if().

◆ m_nodeUpdater

osg::ref_ptr< SafeUpdaterCallback > WGEGroupNode::m_nodeUpdater
protected

Node callback used to update this root node.

Definition at line 118 of file WGEGroupNode.h.

Referenced by WGEGroupNode().

◆ m_removeAll

bool WGEGroupNode::m_removeAll
protected

True whenever all child nodes should be removed.

Definition at line 187 of file WGEGroupNode.h.

Referenced by WGEGroupNode::SafeUpdaterCallback::operator()().


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