148 template<
typename VisitorT>
149 SystemNode* visitBf( VisitorT visitor )
const;
159 template<
typename VisitorT>
160 SystemNode* visitChildrenBf( VisitorT visitor )
const;
170 template<
typename VisitorT>
171 SystemNode* visitDf( VisitorT visitor )
const;
181 template<
typename VisitorT>
182 SystemNode* visitChildrenDf( VisitorT visitor )
const;
202 template<
typename PredicateT>
203 SystemNode* findChild( PredicateT pred,
bool recurse =
true )
const;
213 T* findChild(
bool recurse =
true )
const;
226 template<
typename PredicateT>
227 SystemNode* findParent( PredicateT pred )
const;
233 T* findParent()
const;
241 template<
typename VisitorT>
242 void visitChildren( VisitorT visitor,
bool recurse =
true )
const;
250 template<
typename T,
typename VisitorT>
251 void visitChildrenOfType( VisitorT visitor,
bool recurse =
true)
const;
359 void printTree(
std::ostream& out) const;
366 void printTree(
std::ostream& out,
size_t& depth) const;
370 virtual
void store(
agxStream::OutputArchive& out ) const override;
371 virtual
void restore(
agxStream::InputArchive& in ) override;
395 virtual void invoke(
const CallbackEvent& callbackEvent );
406 using Flags = agx::BitState<Flag, std::underlying_type_t<Flag>>;
418 bool setEnvironment( Environment* environment );
421 Environment* m_environment;
423 InternalState m_state;
426 template<typename VisitorT>
430 if ( visitor( *self ) )
433 return this->visitChildrenBf( visitor );
436 template<
typename VisitorT>
437 SystemNode* SystemNode::visitChildrenBf( VisitorT visitor )
const
439 using SystemNodeQueue = std::queue<SystemNode*>;
441 SystemNodeQueue queue;
443 for (
auto& child : m_children )
446 while ( !queue.empty() ) {
447 auto node = queue.front();
450 if ( visitor( *node ) )
453 for (
auto& child : node->m_children )
460 template<
typename VisitorT>
464 if ( visitor( *self ) )
467 return this->visitChildrenDf( visitor );
470 template<
typename VisitorT>
471 SystemNode* SystemNode::visitChildrenDf( VisitorT visitor )
const
473 using SystemNodeStack = std::stack<SystemNode*>;
475 SystemNodeStack stack;
477 for (
auto& myChild : m_children ) {
478 stack.push( myChild );
480 while ( !stack.empty() ) {
481 auto node = stack.top();
484 if ( visitor( *node ) )
487 for (
auto it = node->m_children.rbegin(); it != node->m_children.rend(); ++it )
496 T* SystemNode::getChild()
const
498 return this->
template findChild<T>(
false );
501 template<
typename PredicateT>
502 SystemNode* SystemNode::findChild( PredicateT pred,
bool recurse )
const
505 return this->visitChildrenDf( [&pred](
const SystemNode& node )
511 auto it = std::find_if( m_children.begin(),
515 return child != nullptr && pred( *child.get() );
517 return it != m_children.end() ?
524 T* SystemNode::findChild(
bool recurse )
const
526 auto child = this->findChild( [](
const SystemNode& child )
528 return child.template asSafe<T>() !=
nullptr;
531 return child !=
nullptr ? child->template as<T>() :
nullptr;
534 template<
typename VisitorT>
535 void SystemNode::visitChildren( VisitorT visitor,
bool recurse )
const
538 this->visitChildrenBf( [&visitor](
SystemNode& child )
545 for (
auto& child : m_children )
550 template<
typename PredicateT>
553 auto parent =
const_cast<SystemNode*
>( this );
554 while ( ( parent = parent->getParent() ) !=
nullptr && !pred( *parent ) )
561 T* SystemNode::findParent()
const
563 auto parent = this->findParent( [](
const SystemNode& parent )
565 return parent.template asSafe<T>() !=
nullptr;
567 return parent !=
nullptr ? parent->template asSafe<T>() :
nullptr;
570 template<
typename T,
typename VisitorT>
571 void SystemNode::visitChildrenOfType( VisitorT visitor,
bool recurse )
const
573 this->visitChildren( [&visitor](
SystemNode& child )
575 if (
auto childT = child.template asSafe<T>() )
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
#define AGX_DECLARE_VECTOR_TYPES(type)
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc.
Sensor environment implementation where different sensors collects data given a set of added objects,...
System node is a separate step/operation in an execution tree representing a sensor (or such) in a se...
virtual void execute(const CallbackData &data)
Execute this system, integrating it data.dt forward in time.
virtual void onChildAdded(SystemNode &child)
Called when child has been added to this parent.
const agx::Name & getName() const
void setName(const agx::Name &name)
Assign name to this node.
void setEnable(bool enable)
Enable/disable this node.
bool detachChild(SystemNode *child)
Detach/erase child from vector of children, silently.
virtual bool addNotification()
Called when this system node has been added to a sensor environment.
size_t getNumChildren() const
SystemNode * getRoot() const
virtual void removeNotification()
Called when this system node is being removed from a sensor environment.
bool appendChild(SystemNode *child)
Append child to vector of children, silently.
virtual bool onAdd(agx::Referenced &instance)
Called when an object has been added to the sensor environment.
bool hasChild(const SystemNode *child, bool recurse=true) const
Environment * getEnvironment() const
bool addChild(SystemNode *child)
Add unique child to this node.
virtual void cleanup()=0
The sensor environment is being put down, clean everything.
SystemNode(const SystemNode &)=delete
Disallow direct copying of nodes.
SystemNode * getChild(size_t index) const
virtual void synchronize(const CallbackData &data)
Synchronization from the main thread.
virtual bool insertParent(SystemNode &parent)
Inserts new parent to this node.
virtual void synchronizeGraphics(const agxRender::RenderManager &renderManager)
At the very end of a step, synchronize any graphics related aspects of the system node.
virtual void complete()
Complete the execution of this system, finishing the integration forward in time.
virtual bool onRemove(agx::Referenced &instance)
Called when an object has been removed from the sensor environment.
virtual void onChildRemoved(SystemNode &child)
Called when child has been removed from this parent.
virtual ~SystemNode()=default
bool removeChild(SystemNode *child)
Remove child from this node.
virtual void result(const CallbackData &data)
If necessary assemble, and fetch results related to this system node after a step by data....
SystemNode * getParent() const
virtual bool eraseAndConnect()
Erase this node from the tree and connect its children to the current parent of this node.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Representation of a name string.
Base class providing referencing counted objects.
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
Namespace containing classes for handling debug rendering of collision geometries,...
The agxSensor namespace contains components to model real-time sensors connected to the physics of AG...
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.