AGX Dynamics  2.37.3.2
MergeSplitBodyStorage.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_MERGESPLITBODYSTORAGE_H
18 #define AGX_MERGESPLITBODYSTORAGE_H
19 
20 #include <agx/agxPhysics_export.h>
21 #include <agx/Referenced.h>
22 #include <agx/RigidBody.h>
23 #include <agxCollide/Geometry.h>
24 #include <agxStream/Serializable.h>
25 
26 namespace agx
27 {
28 
29  class MergeSplit;
30 
36  {
37 
38  public:
39 
41 
44 
49 
51  const agxCollide::GeometryRefVector& getGeometries() const;
52 
54 
55  static void addMassProperties( MergeSplitBodyStorage* targetStorage, const MergeSplitBodyStorage* sourceStorage, Real sign);
56  static void removeMassProperties( MergeSplitBodyStorage* targetStorage, const MergeSplitBodyStorage* sourceStorage, Real sign);
57 
58 
64  static void setRebuildThreshold( size_t numChildren, size_t numUpdates );
65 
66  bool validate() const;
67 
69  agx::RigidBody *getRigidBody();
71  const agx::RigidBody *getRigidBody() const;
72 
73 
75  MergeSplitBodyStorage* getParent( );
76 
78  const MergeSplitBodyStorage* getParent( ) const;
79 
80  AffineMatrix4x4 getTransformRelativeParent() const;
81 
85  bool hasChild( MergeSplitBodyStorage* child ) const;
86 
90  bool hasChildren() const;
91 
95  size_t getNumChildren() const;
96 
100  MergeSplitBodyStorage *getChild( size_t nth );
101 
105  const MergeSplitBodyStorage *getChild( size_t nth ) const;
106 
107 
108  protected:
109 
110  virtual ~MergeSplitBodyStorage();
111 
113  void clear();
114 
118  void setRigidBody( agx::RigidBody* body );
119 
121  bool isMerged() const;
122 
124  void setParent( MergeSplitBodyStorage* parent );
125 
127  void calculateRelativeTransform( const MergeSplitBodyStorage* parentStorage );
128 
132  void addChild( MergeSplitBodyStorage* child );
133 
137  bool removeChild( MergeSplitBodyStorage* child );
138 
142  agx::Frame *getFrame();
143 
144  const agx::Frame *getFrame() const;
145 
146  agx::RigidBody::MotionControl getMotionControl() const;
147 
149 
150  void addGeometry( agxCollide::Geometry *geom );
151 
155  void restore( bool beingErased=false );
156 
160  void followGeometry();
161 
162  void restoreMassProperties();
163 
164  inline void incrementNumUpdates();
165 
166  inline void resetNumUpdates();
167 
168  inline size_t getNumUpdates();
169 
170  private:
171 
172  friend class MergeSplit;
173 
175  agx::observer_ptr<agx::Frame> m_parentFrame;
176 
177  agx::RigidBody::MotionControl m_motionControl;
178  agx::AffineMatrix4x4 m_cmTransform;
179  agx::SPDMatrix3x3 m_tensor;
180  agx::UInt32 m_autoGenerateTensorMask;
181 
182  agx::Real m_mass;
183 
184  agx::FrameRef m_frame;
185 
187  RigidBodyPtrHashVector m_children;
189 
190  agxCollide::GeometryRefVector m_geometries;
191  agx::Vector<AffineMatrix4x4> m_geometryTransforms;
192  agx::AffineMatrix4x4 m_transformRelParent;
193 
194  size_t m_numUpdates;
195 
196  static size_t m_rebuildNumChildren;
197  static size_t m_rebuildNumUpdates;
198 
199  };
200 
201  inline bool MergeSplitBodyStorage::isMerged() const { return m_parentStorage.isValid(); }
202 
203  inline void MergeSplitBodyStorage::incrementNumUpdates() { m_numUpdates++; }
204 
205  inline void MergeSplitBodyStorage::resetNumUpdates() { m_numUpdates = 0; }
206 
207  inline size_t MergeSplitBodyStorage::getNumUpdates() { return m_numUpdates; }
208 
210  inline const agx::RigidBody* MergeSplitBodyStorage::getRigidBody() const { return m_body; }
211 
212  inline MergeSplitBodyStorage* MergeSplitBodyStorage::getParent( ) { return m_parentStorage; }
213  inline const MergeSplitBodyStorage* MergeSplitBodyStorage::getParent( ) const { return m_parentStorage; }
214 
215  inline AffineMatrix4x4 MergeSplitBodyStorage::getTransformRelativeParent() const { return m_transformRelParent; }
216 
218  {
219  return m_children.size();
220  }
221 
223  {
224  return m_frame;
225  }
226 
228  {
229  return m_frame;
230  }
231 
233  {
234  return m_motionControl;
235  }
236 
238  {
239  return m_children.size() > 0;
240  }
241 
242 
243 }
244 
245 #endif /* AGX_MERGESPLITBODYSTORAGE_H */
AGXTERRAIN_EXPORT void clear()
#define AGXPHYSICS_EXPORT
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:37
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
MergeSplitBodyStorage * getParent()
agx::Vector< agx::observer_ptr< agxCollide::Geometry > > GeometryObserverVector
AffineMatrix4x4 getTransformRelativeParent() const
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
AGXPHYSICS_EXPORT void setMotionControl(agx::RigidBodyPtrVector &bodies, agx::RigidBody::MotionControl motionControl)
Utility function to set motion control for a vector of rigid bodies.
Book keeping of a body which can be merged with other bodies.
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
agx::RigidBody::MotionControl getMotionControl() const
double Real
Definition: Real.h:42
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:65
uint32_t UInt32
Definition: Integer.h:40
T sign(T v)
Definition: Math.h:328