AGXDynamics
2.35.0.2
CollectBodiesAndWiresVisitor.h
Go to the documentation of this file.
1
/*
2
Copyright 2007-2022. Algoryx Simulation AB.
3
4
All AGX source code, intellectual property, documentation, sample code,
5
tutorials, scene files and technical white papers, are copyrighted, proprietary
6
and confidential material of Algoryx Simulation AB. You may not download, read,
7
store, distribute, publish, copy or otherwise disseminate, use or expose this
8
material unless having a written signed agreement with Algoryx Simulation AB, or having been
9
advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10
valid commercial license from Algoryx Simulation AB.
11
12
Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13
from using this software, unless otherwise stated in written agreements with
14
Algoryx 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
23
namespace
agxUtil
{
24
32
class
AGXPHYSICS_EXPORT
CollectBodiesAndWiresVisitor
:
public
agxSDK::AssemblyVisitor
33
{
34
public
:
35
36
using
WirePtrSetVector
=
agx::SetVector<agxWire::Wire*>
;
37
using
RigidBodyPtrSetVector
=
agx::SetVector<agx::RigidBody*>
;
38
using
WireNodeRefVector
=
agx::Vector<agxWire::NodeRef>
;
39
41
CollectBodiesAndWiresVisitor
() {}
42
44
virtual
~CollectBodiesAndWiresVisitor
() {}
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
61
using
agxSDK::AssemblyVisitor::visit
;
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();
88
if
(
agxWire::Wire::isLumpedNode
( rb ) )
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
112
RigidBodyPtrSetVector
m_bodies
;
113
WirePtrSetVector
m_wires
;
114
WireNodeRefVector
m_userWireNodes
;
115
};
116
}
117
118
#endif
119
agxUtil::CollectBodiesAndWiresVisitor::getWires
WirePtrSetVector & getWires()
Definition:
CollectBodiesAndWiresVisitor.h:52
agx::Vector< agxWire::NodeRef >
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition:
RigidBody.h:54
agxSDK::Assembly::traverse
virtual void traverse(AssemblyVisitor *visitor)
Traverse the assembly tree recursively using a visitor.
agxUtil::CollectBodiesAndWiresVisitor::visit
virtual void visit(const agxSDK::Assembly *assembly) const
Definition:
CollectBodiesAndWiresVisitor.h:102
agxUtil::CollectBodiesAndWiresVisitor::visit
virtual void visit(const agx::RigidBody *body) const
Definition:
CollectBodiesAndWiresVisitor.h:97
Wire.h
agxUtil::CollectBodiesAndWiresVisitor::visit
virtual void visit(agx::RigidBody *body)
Definition:
CollectBodiesAndWiresVisitor.h:63
agxUtil::CollectBodiesAndWiresVisitor::m_wires
WirePtrSetVector m_wires
Definition:
CollectBodiesAndWiresVisitor.h:113
agxSDK::EventListener
An EventListener can be associated to a Simulation and triggered upon various events.
Definition:
EventListener.h:40
agxUtil::CollectBodiesAndWiresVisitor::getWires
const WirePtrSetVector & getWires() const
Definition:
CollectBodiesAndWiresVisitor.h:54
agxUtil::CollectBodiesAndWiresVisitor::CollectBodiesAndWiresVisitor
CollectBodiesAndWiresVisitor()
Constructor.
Definition:
CollectBodiesAndWiresVisitor.h:41
agxUtil::CollectBodiesAndWiresVisitor::getBodies
RigidBodyPtrSetVector & getBodies()
Definition:
CollectBodiesAndWiresVisitor.h:47
agxUtil::CollectBodiesAndWiresVisitor::~CollectBodiesAndWiresVisitor
virtual ~CollectBodiesAndWiresVisitor()
Destructor.
Definition:
CollectBodiesAndWiresVisitor.h:44
agxWire::Wire
Interface and placeholder of controllers/helpers for wires.
Definition:
Wire.h:61
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxSDK::AssemblyVisitor
Class for visiting all elements in a tree of Assemblies.
Definition:
Assembly.h:743
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Constraint *)
Definition:
Assembly.h:757
agxUtil::CollectBodiesAndWiresVisitor::getBodies
const RigidBodyPtrSetVector & getBodies() const
Definition:
CollectBodiesAndWiresVisitor.h:49
agxSDK::Assembly
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition:
Assembly.h:66
agxWire::Wire::getConstraint
agxWire::WireDistanceCompositeConstraint * getConstraint() const
Definition:
Wire.h:1081
agx::SetVector< agxWire::Wire * >
agxUtil::CollectBodiesAndWiresVisitor
This visitor will visit each rigid body and wire in an assembly (or collection) and extract them to a...
Definition:
CollectBodiesAndWiresVisitor.h:32
agxUtil::CollectBodiesAndWiresVisitor::m_bodies
RigidBodyPtrSetVector m_bodies
Definition:
CollectBodiesAndWiresVisitor.h:112
agx::Referenced::asSafe
T * asSafe()
Safe subclass casting, return nullptr if template type does not match.
agx.h
agx::RigidBody::isPowerlineBody
bool isPowerlineBody() const
Definition:
RigidBody.h:1703
agxUtil::CollectBodiesAndWiresVisitor::visit
virtual void visit(agxSDK::EventListener *listener)
Definition:
CollectBodiesAndWiresVisitor.h:76
agxUtil::CollectBodiesAndWiresVisitor::visit
virtual void visit(const agxSDK::EventListener *listener) const
Definition:
CollectBodiesAndWiresVisitor.h:107
agxWire::Wire::isLumpedNode
static agx::Bool isLumpedNode(const agx::RigidBody *rb)
agxUtil::CollectBodiesAndWiresVisitor::m_userWireNodes
WireNodeRefVector m_userWireNodes
Definition:
CollectBodiesAndWiresVisitor.h:114
agxUtil::CollectBodiesAndWiresVisitor::getUserWireNodes
const WireNodeRefVector & getUserWireNodes() const
Definition:
CollectBodiesAndWiresVisitor.h:57
agxUtil
The agxUtil namespace contain classes and methods for utility functionality.
Definition:
CylindricalJoint.h:22
agxUtil::CollectBodiesAndWiresVisitor::visit
virtual void visit(agxSDK::Assembly *assembly)
Definition:
CollectBodiesAndWiresVisitor.h:70
include
agxUtil
CollectBodiesAndWiresVisitor.h
Generated on Mon Jan 30 2023 15:44:11 for AGXDynamics by
1.8.17