AGX Dynamics  2.37.3.2
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 #ifndef AGX_ATTACHMENT_H
18 #define AGX_ATTACHMENT_H
19 
20 #include <agx/ConstraintAngle.h>
21 #include <agx/RigidBody.h>
22 
23 #ifdef _MSC_VER
24 # pragma warning( push )
25 # pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
26 # pragma warning(disable: 6385) // Disable warning C6385: Reading invalid data
27 #endif
28 
29 
30 namespace agx
31 {
37  {
38  public:
43  {
44  U,
45  V,
46  N,
49  NUM_ELEMENTS
50  };
51 
52  public:
59  static void createAttachmentBase( const agx::Vec3d& N, agx::Vec3d& U, agx::Vec3d& V );
60  static void createAttachmentBase( const agx::Vec3f& N, agx::Vec3f& U, agx::Vec3f& V );
61 
62  public:
67  Attachment( agx::Frame* relFrame );
68 
75  virtual void transform();
76 
80  virtual agx::Bool objectDeleted() const;
81 
85  virtual agx::Bool valid() const;
86 
90  const agx::Vec3& get( agx::Attachment::Transformed entry ) const;
91 
95  agx::Vec3 getLocal( agx::Attachment::Transformed entry ) const;
96 
101  void setFrame( agx::Frame* frame );
102 
106  agx::Frame* getFrame() const;
107 
112  virtual agx::Real calculateDistance( const agx::Attachment* other ) const;
113 
117  virtual agx::Real calculateLinearDistance( const agx::Attachment* other ) const;
118 
122  virtual agx::Real calculateLinearSpeed( const agx::Attachment* other ) const;
123 
127  virtual agx::Real calculateAngularSpeed( const agx::Attachment* other ) const;
128 
132  virtual agx::Vec3 getLinearVelocity() const;
133 
137  virtual agx::Vec3 getAngularVelocity() const;
138 
142  template< typename T >
143  agx::Bool is() const;
144 
150  template< typename T >
151  T* as();
152 
157  template< typename T >
158  T* safeAs();
159 
165  template< typename T >
166  const T* as() const;
167 
172  template< typename T >
173  const T* safeAs() const;
174 
176 
177  protected:
181  Attachment();
182 
186  virtual ~Attachment();
187 
195  void transform( const agx::AffineMatrix4x4& cmTransform, const agx::Vec3& cmToModel, const agx::AffineMatrix4x4& localConstraintTransform );
196 
197  protected:
198  agx::Vec3 m_transformed[ NUM_ELEMENTS ];
200  };
201 
203 
208  {
209  public:
216 
220  virtual agx::Bool objectDeleted() const override;
221 
225  virtual agx::Bool valid() const override;
226 
231  virtual agx::Real calculateDistance( const agx::Attachment* other ) const override;
232 
236  virtual agx::Real calculateLinearDistance( const agx::Attachment* other ) const override;
237 
241  virtual agx::Real calculateLinearSpeed( const agx::Attachment* other ) const override;
242 
246  virtual agx::Real calculateAngularSpeed( const agx::Attachment* other ) const override;
247 
251  virtual agx::Vec3 getLinearVelocity() const override;
252 
256  virtual agx::Vec3 getAngularVelocity() const override;
257 
261  virtual void transform() override;
262 
268  void setRigidBody( agx::RigidBody* rb );
269 
273  agx::RigidBody* getRigidBody() const;
274 
276 
277  protected:
282 
286  virtual ~RigidBodyAttachment();
287 
288  protected:
291  };
292 
294 
301  {
302  public:
307  {
309  NUM_ELEMENTS
310  };
311 
312  public:
319  {
320  public:
324  virtual void transform( const agx::AttachmentPair& attachmentPair ) = 0;
325 
326  protected:
330  virtual ~CustomData() {}
331  };
332 
334 
335  public:
339  AttachmentPair();
340 
344  virtual ~AttachmentPair();
345 
351  void set( agx::Attachment* a1, agx::Attachment* a2 );
352 
357  void add( agx::Angle* angle );
358 
364  agx::Angle* getAngle( agx::UInt index ) const;
365 
369  const agx::AngleContainer& getAngles() const;
370 
374  agx::Bool hasAngle( const agx::Angle* angle ) const;
375 
381  agx::Real calculateAngularSpeed() const;
382 
388  agx::Real calculateLinearSpeed() const;
389 
394  void setCustomData( agx::AttachmentPair::CustomData* customData );
395 
399  agx::AttachmentPair::CustomData* getCustomData() const;
400 
404  agx::Attachment* operator[] ( agx::UInt i ) const;
405 
409  agx::Attachment* getAttachment1() const;
410 
414  agx::Attachment* getAttachment2() const;
415 
419  agx::Bool valid() const;
420 
424  virtual void transform();
425 
429  virtual agx::Bool rebind();
430 
434  const agx::Vec3& get( agx::AttachmentPair::Transformed entry ) const;
435 
439  virtual void store( agxStream::OutputArchive& out ) const;
440 
444  virtual void restore( agxStream::InputArchive& in );
445 
449  virtual void storeLightData( agxStream::StorageStream& str ) const;
450 
454  virtual void restoreLightData( agxStream::StorageStream& str );
455 
456  protected:
457  AttachmentRef m_attachments[ 2 ];
458  agx::Vec3 m_transformed[ NUM_ELEMENTS ];
459  CustomDataRef m_customData;
461  };
462 
464  {
465  return m_transformed[ entry ];
466  }
467 
469  {
470  return m_relFrame;
471  }
472 
473  template< typename T >
475  {
476  return dynamic_cast< const T* >( this ) != nullptr;
477  }
478 
479  template<>
480  AGX_FORCE_INLINE Bool Attachment::is<Attachment>() const
481  {
482  return true;
483  }
484 
485  template< typename T >
487  {
488  // Compiler warns on 'this == nullptr' because it is illegal to call member
489  // functions on nullptr. However, if it helps us find a nullptr dereference
490  // earlier, and with an assert instead of segmentation fault, then I think
491  // it's ok to leave the check.
492  #include <agx/PushDisableWarnings.h>
493  agxAssert( (void *)this == nullptr || this->is<T>() );
494  return static_cast< T* >( this );
495  #include <agx/PopDisableWarnings.h>
496  }
497 
498  template< typename T >
500  {
501  return dynamic_cast< T* >( this );
502  }
503 
504  template< typename T >
506  {
507  // Compiler warns on 'this == nullptr' because it is illegal to call member
508  // functions on nullptr. However, if it helps us find a nullptr dereference
509  // earlier, and with an assert instead of segmentation fault, then I think
510  // it's ok to leave the check.
511  #include <agx/PushDisableWarnings.h>
512  agxAssert( (void *)this == nullptr || this->is< T >() ); return static_cast< const T* >( this );
513  #include <agx/PopDisableWarnings.h>
514  }
515 
516  template< typename T >
518  {
519  return dynamic_cast< const T* >( this );
520  }
521 
523  {
524  return m_rb;
525  }
526 
528  {
529  agxAssert( i < 2 );
530  return m_attachments[ i ].get();
531  }
532 
534  {
535  return (*this)[ 0 ];
536  }
537 
539  {
540  return (*this)[ 1 ];
541  }
542 
544  {
545  return m_transformed[ entry ];
546  }
547 } // namespace agx
548 
549 #ifdef _MSC_VER
550 #pragma warning( pop )
551 #endif
552 
553 #endif
agx::FrameRef m_relFrame
Definition: Attachment.h:199
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
agx::Bool is() const
Constraint attachment z-axis.
Definition: Attachment.h:46
agx::RigidBody * getRigidBody() const
Definition: Attachment.h:522
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...
Transformed
Data access enum.
Definition: Attachment.h:306
virtual ~CustomData()
Reference counted object, protected destructor.
Definition: Attachment.h:330
bool Bool
Definition: Integer.h:48
agx::ref_ptr< CustomData > CustomDataRef
Definition: Attachment.h:333
agx::ref_ptr< Attachment > AttachmentRef
Definition: Attachment.h:202
agx::Frame * getFrame() const
Definition: Attachment.h:468
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
#define AGXPHYSICS_EXPORT
agx::Attachment * getAttachment2() const
Definition: Attachment.h:538
Constraint attachment class for agx::RigidBody.
Definition: Attachment.h:207
#define AGX_FORCE_INLINE
Definition: Object.h:59
Constraint attachment world position.
Definition: Attachment.h:47
Constraint attachment x-axis.
Definition: Attachment.h:44
Custom data for separation pair.
Definition: Attachment.h:318
Base class providing referencing counted objects.
Definition: Referenced.h:119
agx::Attachment * operator[](agx::UInt i) const
Definition: Attachment.h:527
const agx::Vec3 & get(agx::Attachment::Transformed entry) const
Definition: Attachment.h:463
uint32_t UInt
Definition: Integer.h:34
Constraint attachment pair class.
Definition: Attachment.h:300
Constraint attachment base class for any type of frame.
Definition: Attachment.h:36
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::ref_ptr< RigidBodyAttachment > RigidBodyAttachmentRef
Definition: Attachment.h:293
const agx::Vec3 & get(agx::AttachmentPair::Transformed entry) const
Definition: Attachment.h:543
#define agxAssert(expr)
Definition: debug.h:143
Constraint angle class.
T * as()
Unsafe version, static cast of this to T.
Definition: Attachment.h:486
AngleContainer m_angles
Definition: Attachment.h:460
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agx::Attachment * getAttachment1() const
Definition: Attachment.h:533
A class holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3Template.h:45
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
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
Constraint attachment y-axis.
Definition: Attachment.h:45
Separation vector, i.e., the vector from frame 2 to frame 1.
Definition: Attachment.h:308
agx::RigidBodyObserver m_rb
Definition: Attachment.h:289
double Real
Definition: Real.h:42
Transformed
Data access enum.
Definition: Attachment.h:42
Real getAngle(const Vec3 &a, const Vec3 &b, const Vec3 &c)
a and b should be orthogonal
T * safeAs()
Dynamic cast of this to T.
Definition: Attachment.h:499
Vector from center of mass (if moving) to anchor point given in world frame.
Definition: Attachment.h:48
CustomDataRef m_customData
Definition: Attachment.h:459