AGX Dynamics  2.37.3.2
able/Attachment.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #pragma once
18 
19 #include <agx/Referenced.h>
20 #include <agx/RigidBody.h>
21 
22 #include <agx/Constraint.h>
23 #include <agx/BallJoint.h>
24 #include <agx/LockJoint.h>
25 
26 
27 #include <agx/AffineMatrix4x4.h>
28 #include <agx/Vec3.h>
29 
30 #include <agxStream/Serializable.h>
31 
32 #include <agxCable/export.h>
33 
34 
35 
36 namespace agxCable
37 {
38  class CableSegment;
39 }
40 
41 
42 
43 namespace agxCable
44 {
47 
48 
50  {
51  public:
56  {
58  ROTATE_TO_NODE_DIRECTION
59  };
60 
61 
62  template<typename T>
63  static agxCable::SegmentAttachmentRef createFromWorld(const agx::Vec3& worldPoint, agx::RigidBody* body);
64 
65  template<typename T>
66  static agxCable::SegmentAttachmentRef createFromBody(const agx::Vec3& bodyPoint, agx::RigidBody* body);
67 
68  template<typename T>
69  static agxCable::SegmentAttachmentRef createFromWorld(
70  const agx::AffineMatrix4x4& worldTransform, agx::RigidBody* body);
71 
72  template<typename T>
73  static agxCable::SegmentAttachmentRef createFromBody(const agx::AffineMatrix4x4& bodyTransform, agx::RigidBody* body);
74 
75 
76  void setName( const agx::Name& name );
77  const agx::Name& getName() const;
78 
79  agx::Frame* getFrame() const;
80 
81  agx::Constraint* getConstraint() const;
82 
83  agx::RigidBody* getRigidBody() const;
84 
85  agx::AffineMatrix4x4 getWorldMatrix() const;
86 
88  public:
89  virtual agx::Bool initialize(agxCable::CableSegment* segment);
90 
92  void store(agxStream::OutputArchive& out) const override;
93  void restore(agxStream::InputArchive& in) override;
95 
96  protected:
97  SegmentAttachment(agx::RigidBody* body, agx::Frame* rbSegmentAttachmentFrame,
98  agxCable::SegmentAttachment::InitializationMode initMode);
99 
100  SegmentAttachment(const agx::Name& name, agx::RigidBody* body, agx::Frame* bodyAttachmentFrame,
101  agx::Constraint* constraint, InitializationMode initMode);
102 
103  virtual ~SegmentAttachment();
104 
105  virtual agx::ConstraintRef createConstraint(
106  agx::RigidBodyRef body1, agx::FrameRef frame1,
107  agx::RigidBodyRef body2, agx::FrameRef frame2) const = 0;
108 
109 
110  protected:
111  agx::Name m_name;
112  agx::RigidBodyRef m_body;
113  agx::FrameRef m_bodyAttachmentFrame;
114  agx::ConstraintRef m_constraint;
115  InitializationMode m_initMode;
116  };
117 
118 
119 
120 
124  template<typename T>
125  class SegmentAttachmentT : public agxCable::SegmentAttachment
126  {
127  public:
135  agx::RigidBody* body, agx::Frame* rbSegmentAttachmentFrame,
137  : SegmentAttachment(body, rbSegmentAttachmentFrame, initMode)
138  {
139  }
140 
141  protected:
146  : SegmentAttachment(nullptr, nullptr, agxCable::SegmentAttachment::ROTATE_TO_NODE_DIRECTION)
147  {
148  }
149 
150 
151  SegmentAttachmentT(const agx::Name& name, agx::RigidBody* body, agx::Frame* bodyAttachmentFrame,
153  : SegmentAttachment(name, body, bodyAttachmentFrame, constraint, initMode)
154  {
155  }
156 
160  virtual ~SegmentAttachmentT() {}
161 
166  agx::RigidBodyRef body1, agx::FrameRef frame1,
167  agx::RigidBodyRef body2, agx::FrameRef frame2) const override
168  {
169  return new T(body1, frame1, body2, frame2);
170  }
171  };
172 
173 #ifdef SWIG
174 %template(SegmentAttachmentBallJoint) agxCable::SegmentAttachmentT<agx::BallJoint>;
175 %template(SegmentAttachmentLockJoint) agxCable::SegmentAttachmentT<agx::LockJoint>;
176 #endif
177 
179  {
180  public:
181  PointSegmentAttachment(agx::RigidBody* body, const agx::Vec3& relativeTranslate);
182 
184  public:
185  PointSegmentAttachment(const agx::Name& name, agx::RigidBody* body, agx::Frame* bodyAttachmentFrame,
187  : SegmentAttachmentT<agx::BallJoint>(name, body, bodyAttachmentFrame, constraint, initMode)
188  {
189  }
190 
192  using agxCable::SegmentAttachment::restore;
194 
195  protected:
197  virtual ~PointSegmentAttachment();
198  };
199 
200 
201 
203  {
204  public:
205  RigidSegmentAttachment(agx::RigidBody* body, const agx::Vec3& relativeTranslate);
206  RigidSegmentAttachment(agx::RigidBody* body, const agx::AffineMatrix4x4& relativeTransform);
207 
208 
210  public:
211  RigidSegmentAttachment(const agx::Name& name, agx::RigidBody* body, agx::Frame* bodyAttachmentFrame,
213  : SegmentAttachmentT<agx::LockJoint>(name, body, bodyAttachmentFrame, constraint, initMode)
214  {
215  }
216 
218  using agxCable::SegmentAttachment::restore;
220 
221  protected:
223  virtual ~RigidSegmentAttachment();
224  };
225 
226 
227 
228  template<typename T>
230  const agx::Vec3& worldPoint, agx::RigidBody* body)
231  {
232  agx::Vec3 localPoint = body != nullptr ? body->getFrame()->transformPointToLocal(worldPoint) : worldPoint;
233  return createFromBody<T>(localPoint, body);
234  }
235 
236 
237 
238  template<typename T>
240  const agx::Vec3& bodyPoint, agx::RigidBody* body)
241  {
242  return new T(body, bodyPoint);
243  }
244 
245 
246 
247  template<typename T>
249  const agx::AffineMatrix4x4& worldTransform, agx::RigidBody* body)
250  {
251  agx::AffineMatrix4x4 localTransform =
252  body != nullptr ? worldTransform * body->getTransform().inverse() : worldTransform;
253  return createFromBody<T>(localTransform, body);
254  }
255 
256 
257 
258  template<typename T>
260  const agx::AffineMatrix4x4& bodyTransform, agx::RigidBody* body)
261  {
262  return new T(body, bodyTransform);
263  }
264 }
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
static agxCable::SegmentAttachmentRef createFromWorld(const agx::Vec3 &worldPoint, agx::RigidBody *body)
static agxCable::SegmentAttachmentRef createFromBody(const agx::Vec3 &bodyPoint, agx::RigidBody *body)
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
agx::Frame * getFrame()
Returns the model frame containing model the transformation and utilities to manipulate position...
Definition: RigidBody.h:1460
bool Bool
Definition: Integer.h:48
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
Helper class to create give type of constraint for the different SegmentAttachments.
The base class for a constraint.
Definition: Constraint.h:88
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
const agx::AffineMatrix4x4 & getTransform() const
Current model frame transform, given in world coordinate frame.
Definition: RigidBody.h:1609
Base class providing referencing counted objects.
Definition: Referenced.h:119
virtual ~SegmentAttachmentT()
Reference counted object, protected destructor.
SegmentAttachmentT(const agx::Name &name, agx::RigidBody *body, agx::Frame *bodyAttachmentFrame, agx::Constraint *constraint, agxCable::SegmentAttachment::InitializationMode initMode)
Contain classes for 6 DOF lumped element cables/wires/ropes.
A CableSegment represents a single link of a cable.
Definition: CableSegment.h:45
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::ref_ptr< Constraint > ConstraintRef
Definition: Constraint.h:53
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
InitializationMode
Each SegmentAttachment implementation controls the initialization mode.
agx::Vec3 transformPointToLocal(const agx::Vec3 &pointWorld) const
Transform point from the world coordinate frame to this frame.
Definition: Frame.h:626
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
virtual agx::ConstraintRef createConstraint(agx::RigidBodyRef body1, agx::FrameRef frame1, agx::RigidBodyRef body2, agx::FrameRef frame2) const override
agx::ref_ptr< RigidBody > RigidBodyRef
Definition: RigidBody.h:47
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
SegmentAttachmentT()
Default constructor for serialization.
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
SegmentAttachmentT(agx::RigidBody *body, agx::Frame *rbSegmentAttachmentFrame, agxCable::SegmentAttachment::InitializationMode initMode)
Construct given rigid body and a relative frame.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define AGXCABLE_EXPORT
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97