AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
CollectBodiesAndWiresVisitor.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXUTIL_COLLECT_BODIES_AND_WIRES_VISITOR_H
18#define AGXUTIL_COLLECT_BODIES_AND_WIRES_VISITOR_H
19
20#include <agx/agx.h>
21#include <agxWire/Wire.h>
22
23namespace agxUtil {
24
33 {
34 public:
35
39
42
45
47 RigidBodyPtrSetVector& getBodies() { return m_bodies; }
49 const RigidBodyPtrSetVector& getBodies() const { return m_bodies; }
50
52 WirePtrSetVector& getWires() { return m_wires; }
54 const WirePtrSetVector& getWires() const { return m_wires; }
55
57 const WireNodeRefVector& getUserWireNodes() const { return m_userWireNodes; }
58
59 protected:
60
62
63 virtual void visit(agx::RigidBody* body)
64 {
65 // Ignore powerline bodies
66 if (!body->isPowerlineBody())
67 m_bodies.insert(body);
68 }
69
70 virtual void visit(agxSDK::Assembly* assembly)
71 {
72 assembly->traverse(this);
73 }
74
75 // Visit "wires"
76 virtual void visit(agxSDK::EventListener* listener)
77 {
78 if ( listener == nullptr )
79 return;
80
81 auto wire = listener->asSafe<agxWire::Wire>();
82 if (wire == nullptr || m_wires.contains( wire ) || wire->getConstraint() == nullptr)
83 return;
84
85 const auto constraint = wire->getConstraint();
86 for (auto it = constraint->getBeginIterator(); it != constraint->getEndIterator(); ++it) {
87 auto rb = (*it)->getRigidBody();
89 m_bodies.insert( rb );
90 else
91 m_userWireNodes.push_back( *it );
92 }
93
94 m_wires.insert(wire);
95 }
96
97 virtual void visit(const agx::RigidBody*body) const
98 {
99 const_cast<CollectBodiesAndWiresVisitor *>(this)->visit(body);
100 }
101
102 virtual void visit(const agxSDK::Assembly* assembly)const
103 {
104 const_cast<CollectBodiesAndWiresVisitor *>(this)->visit(assembly);
105 }
106
107 virtual void visit(const agxSDK::EventListener*listener) const
108 {
109 const_cast<CollectBodiesAndWiresVisitor *>(this)->visit(listener);
110 }
111
115 };
116}
117
118#endif
119
#define AGXPHYSICS_EXPORT
Class for visiting all elements in a tree of Assemblies.
Definition: Assembly.h:932
virtual void visit(agx::Constraint *)
Definition: Assembly.h:945
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:70
virtual void traverse(AssemblyVisitor *visitor)
Traverse the assembly tree recursively using a visitor.
An EventListener can be associated to a Simulation and triggered upon various events.
Definition: EventListener.h:40
This visitor will visit each rigid body and wire in an assembly (or collection) and extract them to a...
const WireNodeRefVector & getUserWireNodes() const
virtual void visit(agxSDK::EventListener *listener)
virtual void visit(const agxSDK::EventListener *listener) const
virtual void visit(const agx::RigidBody *body) const
const RigidBodyPtrSetVector & getBodies() const
virtual void visit(const agxSDK::Assembly *assembly) const
virtual void visit(agxSDK::Assembly *assembly)
virtual void visit(agx::RigidBody *body)
Interface and placeholder of controllers/helpers for wires.
Definition: Wire.h:62
agxWire::WireDistanceCompositeConstraint * getConstraint() const
Definition: Wire.h:1082
static agx::Bool isLumpedNode(const agx::RigidBody *rb)
T * asSafe()
Safe subclass casting, return nullptr if template type does not match.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
bool isPowerlineBody() const
Definition: RigidBody.h:1326
The agxUtil namespace contain classes and methods for utility functionality.