AGX Dynamics  2.38.0.2
Frame.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_FRAME_H
18 #define AGX_FRAME_H
19 
20 #ifdef _MSC_VER
21 # pragma warning(push)
22 # pragma warning( disable: 4290) //: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
23 #endif
24 
25 #include <agx/observer_ptr.h>
26 #include <agx/Vec3.h>
27 #include <agx/AffineMatrix4x4.h>
28 #include <agx/OrthoMatrix3x3.h>
29 
30 #include <agxStream/Serializable.h>
31 #include <agx/SetVector.h>
32 #include <agxData/EntityPtr.h>
33 #include <agxData/AttributePtr.h>
35 
36 namespace agxSDK
37 {
38  class Assembly;
39 }
40 
41 namespace agxCollide
42 {
43  class Geometry;
44 }
45 
46 namespace agx
47 {
48  class RigidBody;
49  class EulerAngles;
50  class OrthoMatrix3x3;
51 
53 
68  {
69  public:
73  Frame();
74 
78  Frame( const agxData::AttributePtr< AffineMatrix4x4 >& localTransform, const agxData::AttributePtr< AffineMatrix4x4 >& globalTransform );
79 
84  explicit Frame( const agx::AffineMatrix4x4 matrix );
85 
90  Frame( const agx::Frame& frame );
91 
96  Frame& operator = ( const agx::Frame& frame );
97 
98  public:
108  bool setParent( agx::Frame* frame );
109 
113  agx::Frame* getParent();
114 
118  const agx::Frame* getParent() const;
119 
123  bool hasParent() const;
124 
132  void setMatrix( const agx::AffineMatrix4x4& matrix );
133 
138  const agx::AffineMatrix4x4& getMatrix() const;
139 
140 
144  bool isFinite() const;
145 
150  void setLocalMatrix( const agx::AffineMatrix4x4& matrix );
151 
155  const agx::AffineMatrix4x4& getLocalMatrix() const;
156 
160  agx::Vec3 getTranslate() const;
161 
166  void setTranslate( const agx::Vec3& translate );
167 
174  void setTranslate( agx::Real x, agx::Real y, agx::Real z );
175 
179  agx::Vec3 getLocalTranslate() const;
180 
185  void setLocalTranslate( const agx::Vec3& translate );
186 
193  void setLocalTranslate( agx::Real x, agx::Real y, agx::Real z );
194 
198  agx::Quat getRotate() const;
199 
204  void setRotate( const agx::Quat& rotation );
205 
210  void setRotate( const agx::OrthoMatrix3x3& rotation );
211 
216  void setRotate( const agx::EulerAngles& euler);
217 
221  Quat getLocalRotate() const;
222 
227  void setLocalRotate( const agx::Quat& rotation );
228 
233  void setLocalRotate( const agx::EulerAngles& rotation );
234 
240  agx::Vec3 transformVectorToWorld( const agx::Vec3& vectorLocal ) const;
241 
250 
257  agx::Vec3& transformVectorToWorld( const agx::Vec3& localVector, agx::Vec3& worldVector ) const;
258 
264  agx::Vec3 transformPointToWorld( const agx::Vec3& pointLocal ) const;
265 
274 
281  agx::Vec3& transformPointToWorld( const agx::Vec3& localPoint, agx::Vec3& worldPoint ) const;
282 
288  agx::Vec3 transformVectorToLocal( const agx::Vec3& worldVector ) const;
289 
297  agx::Vec3 transformVectorToLocal( agx::Real vx, agx::Real vy, agx::Real vz ) const;
298 
305  agx::Vec3& transformVectorToLocal( const agx::Vec3& vectorWorld, agx::Vec3& vectorLocal ) const;
306 
312  agx::Vec3 transformPointToLocal( const agx::Vec3& pointWorld ) const;
313 
321  agx::Vec3 transformPointToLocal( agx::Real px, agx::Real py, agx::Real pz ) const;
322 
329  agx::Vec3& transformPointToLocal( const agx::Vec3& pointWorld, agx::Vec3& pointLocal ) const;
330 
350  void transferDataIntoLeaves( bool keepLocalVelocity = true, bool clearTransform=true );
351 
362  void setAllowTransferIntoChildren( bool allow );
363 
367  bool allowTransferDataIntoChildren() const;
368 
376  void transferChildren( agx::Frame* newParent );
377 
381  bool hasChildren() const;
382 
388  bool removeChild( agx::Frame* frame );
389 
393  void removeAllChildren();
394 
398  agx::RigidBody* getRigidBody();
399 
403  const agx::RigidBody* getRigidBody() const;
404 
409  void setMatrixPointers( const agxData::AttributePtr< agx::AffineMatrix4x4 >& localTransform, const agxData::AttributePtr< agx::AffineMatrix4x4 >& globalTransform );
410 
414  void setEntityData(agxData::AttributePtr< agx::AffineMatrix4x4 > localTransform, agxData::AttributePtr< agx::AffineMatrix4x4 > globalTransform);
415 
420  void updateLocalMatrix();
421 
430  void updateLocalMatrixSSE();
431 
433 
434  protected:
438  virtual ~Frame();
439 
440  private:
441  friend class RigidBody;
442  friend class agxCollide::Geometry;
443 
447  void setRigidBody( agx::RigidBody* body );
448 
452  void setGeometry( agxCollide::Geometry* geometry );
453 
457  void propagateUpdate();
458 
464  void postTransformUpdate();
465 
471  bool addChild( agx::Frame* frame );
472 
473 
474 
475  private:
477 
478  private:
479  Physics::FrameRef m_entity;
480  mutable agxData::AttributePtr< AffineMatrix4x4 > m_globalTransform;
482 
485  bool m_allowTransferDataIntoChildren;
486  Frame* m_parent;
487  FramePtrVector m_children;
488  };
489 
491  {
492  m_localTransform.get() = matrix;
493  const Frame* parent = getParent();
494  if (parent)
495  m_localTransform.get().postMult(parent->getMatrix().inverse());
496 
497  this->postTransformUpdate();
498  }
499 
501  {
502  m_localTransform.get() = m_parent ? m_globalTransform.get() * m_parent->m_globalTransform.get().inverse() : m_globalTransform.get();
503  }
504 
505 
507  {
508  return m_parent;
509  }
510 
512  {
513  return m_parent;
514  }
515 
517  {
518  return m_parent != nullptr;
519  }
520 
522  {
523  return m_localTransform.get();
524  }
525 
527  {
528  m_localTransform.get() = matrix;
529  this->postTransformUpdate();
530  }
531 
533  {
534  return getMatrix().getTranslate();
535  }
536 
537  AGX_FORCE_INLINE void Frame::setTranslate( const Vec3& translate )
538  {
539  if ( getParent() )
540  m_localTransform.get().setTranslate ( translate * m_parent->getMatrix().inverse() );
541  else
542  m_localTransform.get().setTranslate( translate );
543 
544  this->postTransformUpdate();
545  }
546 
548  {
549  setTranslate( Vec3( x, y, z ) );
550  }
551 
553  {
554  return m_localTransform.get().getTranslate();
555  }
556 
558  {
559  m_localTransform.get().setTranslate( translate );
560  this->postTransformUpdate();
561  }
562 
564  {
565  setLocalTranslate( Vec3( x, y, z ) );
566  }
567 
569  {
570  Vec3 vectorWorld;
571  return transformVectorToWorld( vectorLocal, vectorWorld );
572  }
573 
575  {
576  return transformVectorToWorld( Vec3( vx, vy, vz ) );
577  }
578 
579  AGX_FORCE_INLINE Vec3& Frame::transformVectorToWorld( const Vec3& localVector, Vec3& worldVector ) const
580  {
581  const AffineMatrix4x4& m = getMatrix();
582 
583  m.transform3x3( localVector, worldVector );
584  return worldVector;
585  }
586 
588  {
589  Vec3 wP;
590  return transformPointToWorld( pointLocal, wP);
591  }
592 
594  {
595  return transformPointToWorld( Vec3( px, py, pz ) );
596  }
597 
598  AGX_FORCE_INLINE Vec3& Frame::transformPointToWorld( const Vec3& localPoint, Vec3& worldPoint ) const
599  {
600  const AffineMatrix4x4& m = getMatrix();
601 
602  worldPoint = m.preMult( localPoint );
603  return worldPoint;
604  }
605 
607  {
608  Vec3 localVector;
609  return transformVectorToLocal( worldVector, localVector );
610  }
611 
613  {
614  return transformVectorToLocal( Vec3( vx, vy, vz ) );
615  }
616 
617  AGX_FORCE_INLINE Vec3& Frame::transformVectorToLocal( const Vec3& vectorWorld, Vec3& vectorLocal ) const
618  {
620 
621  m.setTranslate( 0, 0, 0 );
622  vectorLocal = m.postMult( vectorWorld );
623  return vectorLocal;
624  }
625 
627  {
628  Vec3 pointLocal;
629  return transformPointToLocal( pointWorld, pointLocal );
630  }
631 
633  {
634  return transformPointToLocal( Vec3( px, py, pz ) );
635  }
636 
637  AGX_FORCE_INLINE Vec3& Frame::transformPointToLocal( const Vec3& pointWorld, Vec3& pointLocal ) const
638  {
640 
641  pointLocal = m.preMult( pointWorld );
642  return pointLocal;
643  }
644 
646  {
647  return m_allowTransferDataIntoChildren;
648  }
649 
651  {
652  m_allowTransferDataIntoChildren = allow;
653  }
654 
656  {
657  return !m_children.empty();
658  }
659 
661  {
662  FramePtrVector::iterator it = m_children.begin();
663  for(; it != m_children.end(); ++it)
664  {
665  (*it)->m_parent = nullptr;
666  }
667  m_children.clear();
668  }
669 
671  {
672  if(m_children.erase( frame ))
673  {
674  frame->m_parent = nullptr;
675  return true;
676  }
677  return false;
678  }
679 
681  {
682  return m_rigidBody.get();
683  }
684 
686  {
687  return m_rigidBody;
688  }
689 
690  #define AGX_ADD_FRAME_TRANSFORM_INTERFACE() \
691  AGX_FORCE_INLINE const agx::AffineMatrix4x4& getTransform() const { return getFrame()->getMatrix(); } \
692  AGX_FORCE_INLINE agx::Vec3 getPosition() const { return getFrame()->getTranslate(); } \
693  AGX_FORCE_INLINE agx::Quat getRotation() const { return getFrame()->getRotate(); }
694 
695 } // namespace agx
696 
697 #ifdef _MSC_VER
698 # pragma warning(pop)
699 #endif
700 
701 #endif
agx::Frame::setTranslate
void setTranslate(const agx::Vec3 &translate)
Assign the final (world) translate of this frame.
Definition: Frame.h:537
agxWire::transformPointToWorld
static agx::Vec3 transformPointToWorld(const agx::Vec3 &p, const agxCollide::Geometry *g)
Transforms a point given in shape coordinates to world given geometry g.
Definition: WireUtils.h:81
agx::Real
double Real
Definition: Real.h:42
agx::OrthoMatrix3x3
Specialized types of matrices for holding orthogonal transformation matrices.
Definition: OrthoMatrix3x3.h:33
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::Frame::getTranslate
agx::Vec3 getTranslate() const
Definition: Frame.h:532
agx::AffineMatrix4x4T< Real >
agx::Matrix4x4T::transform3x3
Vec3T< T > & transform3x3(const Vec3T< T > &vIn, Vec3T< T > &vOut) const
Definition: Matrix4x4.h:971
agx::SetVector::erase
bool erase(const T2 &key)
Erase an element from the container.
Definition: SetVector.h:397
agx::Frame::transformPointToLocal
agx::Vec3 transformPointToLocal(const agx::Vec3 &pointWorld) const
Transform point from the world coordinate frame to this frame.
Definition: Frame.h:626
agx::Physics::FramePtrVector
agx::VectorPOD< FramePtr > FramePtrVector
Definition: FrameEntity.h:232
agx::Frame::hasChildren
bool hasChildren() const
Definition: Frame.h:655
agx::SetVector::end
iterator end()
Definition: SetVector.h:316
agxData::AttributePtr
Definition: AttributePtr.h:27
agx::Frame::getMatrix
const agx::AffineMatrix4x4 & getMatrix() const
FrameEntity.h
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::Frame::removeAllChildren
void removeAllChildren()
Remove all children of this frame.
Definition: Frame.h:660
agx::SetVector::begin
iterator begin()
Definition: SetVector.h:276
agx::observer_ptr< agx::RigidBody >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::AffineMatrix4x4T::preMult
void preMult(const AffineMatrix4x4T< T > &)
Definition: AffineMatrix4x4.h:752
AffineMatrix4x4.h
agx::SetVector::clear
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements.
Definition: SetVector.h:446
agx::SetVector::empty
bool empty() const
Return true if the container is empty.
Definition: SetVector.h:128
AttributePtr.h
agx::Frame::setLocalMatrix
void setLocalMatrix(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this frame ignoring any eventual parent transformation.
Definition: Frame.h:526
EntityPtr.h
Vec3.h
agx::Frame::getLocalMatrix
const agx::AffineMatrix4x4 & getLocalMatrix() const
Definition: Frame.h:521
agx::SetVector< Frame * >
agx::Vec3
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
agx::Frame::setLocalTranslate
void setLocalTranslate(const agx::Vec3 &translate)
Assign the parent relative translate of this frame.
Definition: Frame.h:557
agx::Frame::transformVectorToLocal
agx::Vec3 transformVectorToLocal(const agx::Vec3 &worldVector) const
Transform vector from the world coordinate frame to this frame.
Definition: Frame.h:606
agx::Matrix4x4T::getTranslate
Vec3T< T > getTranslate() const
Definition: Matrix4x4.h:656
agx::Frame::removeChild
bool removeChild(agx::Frame *frame)
Remove a specified frame from the list of children.
Definition: Frame.h:670
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
observer_ptr.h
agx::Frame::getRigidBody
agx::RigidBody * getRigidBody()
Definition: Frame.h:680
Serializable.h
agx::EulerAngles
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
agx::Frame::allowTransferDataIntoChildren
bool allowTransferDataIntoChildren() const
Definition: Frame.h:645
agx::Frame::transformVectorToWorld
agx::Vec3 transformVectorToWorld(const agx::Vec3 &vectorLocal) const
Transform vector from this frame to the world frame.
Definition: Frame.h:568
agx::Frame::getParent
agx::Frame * getParent()
Definition: Frame.h:506
agx::QuatT< Real >
agx::Frame::setMatrix
void setMatrix(const agx::AffineMatrix4x4 &matrix)
This method will set the local matrix of this frame to be the matrix m multiplied with the inverse of...
Definition: Frame.h:490
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::Frame::updateLocalMatrix
void updateLocalMatrix()
Internal method.
Definition: Frame.h:500
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agx::Frame::transformPointToWorld
agx::Vec3 transformPointToWorld(const agx::Vec3 &pointLocal) const
Transform point from this frame to the world frame.
Definition: Frame.h:587
agxData::EntityRef< FramePtr >
agx::Frame::setAllowTransferIntoChildren
void setAllowTransferIntoChildren(bool allow)
Specifies whether a transferDataIntoLeaves() operation will go into this frames children (including a...
Definition: Frame.h:650
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::AffineMatrix4x4T::inverse
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
Definition: AffineMatrix4x4.h:461
agx::isFinite
bool isFinite(T v)
Definition: Math.h:309
agx::Vec3T< Real >
agx::Frame::hasParent
bool hasParent() const
Definition: Frame.h:516
agx::AffineMatrix4x4T::setTranslate
AffineMatrix4x4T< T > & setTranslate(const Vec3T< T > &t)
Set the translational part of the matrix using the vector t.
Definition: AffineMatrix4x4.h:619
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agx::observer_ptr::get
T * get() const
Definition: observer_ptr.h:276
agxWire::transformVectorToWorld
static agx::Vec3 transformVectorToWorld(const agx::Vec3 &v, const agxCollide::Geometry *g)
Transforms a vector given in shape coordinates to world coordinates given geometry g.
Definition: WireUtils.h:57
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::AffineMatrix4x4T::postMult
void postMult(const AffineMatrix4x4T< T > &)
Definition: AffineMatrix4x4.h:770
OrthoMatrix3x3.h
agx::Frame::getLocalTranslate
agx::Vec3 getLocalTranslate() const
Definition: Frame.h:552
SetVector.h