AGX Dynamics  2.38.0.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 ];
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::AttachmentPair::getAttachment2
agx::Attachment * getAttachment2() const
Definition: Attachment.h:538
agx::UInt
uint64_t UInt
Definition: Integer.h:27
agx::Attachment::Transformed
Transformed
Data access enum.
Definition: Attachment.h:42
agx::Real
double Real
Definition: Real.h:42
agx::AttachmentPair::CustomData::~CustomData
virtual ~CustomData()
Reference counted object, protected destructor.
Definition: Attachment.h:330
agx::RigidBodyAttachment
Constraint attachment class for agx::RigidBody.
Definition: Attachment.h:207
agxData::transform
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
agx::Vector< AngleRef >
agxStream::out
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.
Definition: OutputArchive.h:412
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
agx::Attachment::m_transformed
agx::Vec3 m_transformed[NUM_ELEMENTS]
Definition: Attachment.h:198
agx::AffineMatrix4x4T< Real >
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agx::Attachment::getFrame
agx::Frame * getFrame() const
Definition: Attachment.h:468
agx::AttachmentPair::m_customData
CustomDataRef m_customData
Definition: Attachment.h:459
agxStream::StorageStream
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::AttachmentPair
Constraint attachment pair class.
Definition: Attachment.h:300
agx::AttachmentPair::operator[]
agx::Attachment * operator[](agx::UInt i) const
Definition: Attachment.h:527
agx::Attachment::ANCHOR_POS
@ ANCHOR_POS
Constraint attachment world position.
Definition: Attachment.h:47
agx::observer_ptr< RigidBody >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxStream::in
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:399
agx::Attachment::get
const agx::Vec3 & get(agx::Attachment::Transformed entry) const
Definition: Attachment.h:463
agx::ref_ptr< Frame >
PushDisableWarnings.h
agx::AttachmentPair::get
const agx::Vec3 & get(agx::AttachmentPair::Transformed entry) const
Definition: Attachment.h:543
agx::Attachment::U
@ U
Constraint attachment x-axis.
Definition: Attachment.h:44
agx::AttachmentRef
agx::ref_ptr< Attachment > AttachmentRef
Definition: Attachment.h:202
agx::RigidBodyAttachment::m_hadValidRb
agx::Bool m_hadValidRb
Definition: Attachment.h:290
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agx::AttachmentPair::Transformed
Transformed
Data access enum.
Definition: Attachment.h:306
agx::AttachmentPair::m_transformed
agx::Vec3 m_transformed[NUM_ELEMENTS]
Definition: Attachment.h:458
agx::AttachmentPair::getAttachment1
agx::Attachment * getAttachment1() const
Definition: Attachment.h:533
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
RigidBody.h
agx::AttachmentPair::CustomDataRef
agx::ref_ptr< CustomData > CustomDataRef
Definition: Attachment.h:333
agx::AttachmentPair::m_attachments
AttachmentRef m_attachments[2]
Definition: Attachment.h:457
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
agx::getAngle
Real getAngle(const Vec3 &a, const Vec3 &b, const Vec3 &c)
a and b should be orthogonal
Definition: ConstraintImplementation.h:1419
agx::Bool
bool Bool
Definition: Integer.h:40
agx::RigidBodyAttachment::getRigidBody
agx::RigidBody * getRigidBody() const
Definition: Attachment.h:522
ConstraintAngle.h
agx::Attachment::N
@ N
Constraint attachment z-axis.
Definition: Attachment.h:46
agx::Attachment
Constraint attachment base class for any type of frame.
Definition: Attachment.h:36
agx::Angle
Constraint angle class.
Definition: ConstraintAngle.h:31
agx::RigidBodyAttachment::m_rb
agx::RigidBodyObserver m_rb
Definition: Attachment.h:289
agx::Attachment::as
T * as()
Unsafe version, static cast of this to T.
Definition: Attachment.h:486
agx::Attachment::V
@ V
Constraint attachment y-axis.
Definition: Attachment.h:45
agx::Vec3T
A class holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3Template.h:45
agx::AttachmentPair::CustomData
Custom data for separation pair.
Definition: Attachment.h:318
agx::AttachmentPair::SEPARATION
@ SEPARATION
Separation vector, i.e., the vector from frame 2 to frame 1.
Definition: Attachment.h:308
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agx::Attachment::safeAs
T * safeAs()
Dynamic cast of this to T.
Definition: Attachment.h:499
agx::Attachment::CM_TO_ANCHOR_POS
@ CM_TO_ANCHOR_POS
Vector from center of mass (if moving) to anchor point given in world frame.
Definition: Attachment.h:48
agx::Attachment::m_relFrame
agx::FrameRef m_relFrame
Definition: Attachment.h:199
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::RigidBodyAttachmentRef
agx::ref_ptr< RigidBodyAttachment > RigidBodyAttachmentRef
Definition: Attachment.h:293
agx::ref_ptr::get
T * get() const
Definition: ref_ptr.h:256
agx::AttachmentPair::m_angles
AngleContainer m_angles
Definition: Attachment.h:460
agx::Attachment::is
agx::Bool is() const
PopDisableWarnings.h