AGX Dynamics  2.37.2.0
Deformable1DAttachment.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 #ifndef AGXMODEL_DEFORMABLE1DATTACHMENT_H
18 #define AGXMODEL_DEFORMABLE1DATTACHMENT_H
19 
20 #include <agxModel/export.h>
21 
22 #include <agx/LockJoint.h>
23 #include <agx/BallJoint.h>
24 #include <agx/Hinge.h>
25 #include <agx/Prismatic.h>
26 
27 namespace agxModel
28 {
29  class Deformable1DNode;
30 
32 
37  {
38  public:
43  {
45  ROTATE_TO_NODE_DIRECTION
46  };
47 
48  public:
56  template< typename T >
57  static agxModel::NodeAttachmentRef createFromWorld( agx::Vec3 worldPoint, agx::RigidBody* rb );
58 
66  template< typename T >
67  static agxModel::NodeAttachmentRef createFromBody( agx::Vec3 bodyPoint, agx::RigidBody* rb );
68 
76  template< typename T >
77  static agxModel::NodeAttachmentRef createFromWorld( agx::AffineMatrix4x4 worldTransform, agx::RigidBody* rb );
78 
86  template< typename T >
87  static agxModel::NodeAttachmentRef createFromBody( agx::AffineMatrix4x4 bodyTransform, agx::RigidBody* rb );
88 
89  public:
94  void setName( const agx::String& name );
95 
99  const agx::String& getName() const;
100 
104  agx::Frame* getFrame() const;
105 
109  agx::Constraint* getConstraint() const;
110 
114  agx::RigidBody* getRigidBody() const;
115 
119  agx::AffineMatrix4x4 getWorldMatrix() const;
120 
121  InitializationMode getInitMode() const;
122 
123 
124  public:
128  virtual agx::Bool initialize(agxModel::Deformable1DNode* node);
129 
131 
135  virtual void storeLightData( agxStream::StorageStream& str ) const override;
136 
140  virtual void restoreLightData( agxStream::StorageStream& str ) override;
141 
142  protected:
150 
154  void store( agxStream::OutputArchive& out ) const override;
155 
159  void restore( agxStream::InputArchive& in ) override;
160 
161  protected:
165  virtual ~NodeAttachment();
166 
170  virtual agx::ConstraintRef createConstraint( agx::RigidBodyRef rb1, agx::FrameRef f1, agx::RigidBodyRef rb2, agx::FrameRef f2 ) const = 0;
171 
172  protected:
178  };
179 
183  template< typename T >
185  {
186  public:
193  NodeAttachmentT( agx::RigidBody* rb, agx::Frame* rbAttachmentFrame, agxModel::NodeAttachment::InitializationMode initMode ) : NodeAttachment( rb, rbAttachmentFrame, initMode ) {}
194 
195  protected:
199  NodeAttachmentT() : NodeAttachment( nullptr, nullptr, agxModel::NodeAttachment::ROTATE_TO_NODE_DIRECTION ) {}
200 
204  virtual ~NodeAttachmentT() {}
205 
210  {
211  return new T( rb1, f1, rb2, f2 );
212  }
213  };
214 
215 #ifdef SWIG
216  %template(NodeAttachmentTBallJoint) agxModel::NodeAttachmentT<agx::BallJoint>;
217  %template(NodeAttachmentTLockJoint) agxModel::NodeAttachmentT<agx::LockJoint>;
218  %template(NodeAttachmentTHinge) agxModel::NodeAttachmentT<agx::Hinge>;
219  %template(NodeAttachmentTPrismatic) agxModel::NodeAttachmentT<agx::Prismatic>;
220 #endif
221 
226  {
227  public:
233  PointNodeAttachment( agx::RigidBody* rb, const agx::Vec3& relPosition );
234 
236 
237  protected:
242 
246  virtual ~PointNodeAttachment();
247  };
248 
253  {
254  public:
261  RigidNodeAttachment( agx::RigidBody* rb, const agx::Vec3& relPosition );
262 
269  RigidNodeAttachment( agx::RigidBody* rb, const agx::AffineMatrix4x4& relTransform );
270 
272 
273  protected:
278 
282  virtual ~RigidNodeAttachment();
283  };
284 
289  {
290  public:
297  RotatingNodeAttachment( agx::RigidBody* rb, const agx::Vec3& relPosition );
298 
304  RotatingNodeAttachment( agx::RigidBody* rb, const agx::AffineMatrix4x4& relTransform );
305 
307 
308  protected:
313 
317  virtual ~RotatingNodeAttachment();
318  };
319 
324  {
325  public:
332  SlidingNodeAttachment( agx::RigidBody* rb, const agx::Vec3& relPosition );
333 
339  SlidingNodeAttachment( agx::RigidBody* rb, const agx::AffineMatrix4x4& relTransform );
340 
342 
343  protected:
348 
352  virtual ~SlidingNodeAttachment();
353  };
354 
355  template< typename T >
357  {
358  return createFromBody< T >( (rb != nullptr ? rb->getFrame()->transformPointToLocal( worldPoint ) : worldPoint), rb );
359  }
360 
361  template< typename T >
363  {
364  return new T( rb, bodyPoint );
365  }
366 
367  template< typename T >
369  {
370  return createFromBody< T >( (rb != nullptr ? worldTransform * rb->getTransform().inverse() : worldTransform), rb );
371  }
372 
373  template< typename T >
375  {
376  return new T( rb, bodyTransform );
377  }
378 }
379 
380 #endif // AGXMODEL_DEFORMABLE1DATTACHMENT_H
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
Node attachment using ball joint, i.e., the node will rotate about this attachment.
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
virtual agx::ConstraintRef createConstraint(agx::RigidBodyRef rb1, agx::FrameRef f1, agx::RigidBodyRef rb2, agx::FrameRef f2) const override
The base class for a constraint.
Definition: Constraint.h:88
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
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
Base class for attachments to Deformable1D nodes.
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
Node attachment using lock joint, i.e., the node cannot move relative to this attachment.
Node attachment using prismatic joint, i.e., the node can slide along this attachment.
Node attachment using hinge joint, i.e., the node can rotate about this attachment.
static agxModel::NodeAttachmentRef createFromWorld(agx::Vec3 worldPoint, agx::RigidBody *rb)
Creates an node attachment given a point in world frame.
NodeAttachmentT()
Default constructor for serialization.
Helper class to create give type of constraint for the different attachments.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
NodeAttachmentT(agx::RigidBody *rb, agx::Frame *rbAttachmentFrame, agxModel::NodeAttachment::InitializationMode initMode)
Construct given rigid body and a relative frame.
agx::Vec3 transformPointToLocal(const agx::Vec3 &pointWorld) const
Transform point from the world coordinate frame to this frame.
Definition: Frame.h:626
static agxModel::NodeAttachmentRef createFromBody(agx::Vec3 bodyPoint, agx::RigidBody *rb)
Creates an node attachment given a point in rb local frame.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
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
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
#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 AGXMODEL_EXPORT
virtual ~NodeAttachmentT()
Reference counted object, protected destructor.
InitializationMode
Each attachment implementation controls the initialization mode.
Special node implementation of segments in e.g., a Deformable1D object.