AGXDynamics  2.35.0.2
MergeSplitBodyStorage.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
227  inline const agx::Frame *MergeSplitBodyStorage::getFrame() const
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 */
agxPhysics_export.h
agx::sign
T sign(T v)
Definition: Math.h:328
agx::MergeSplitBodyStorage::getParent
MergeSplitBodyStorage * getParent()
Definition: MergeSplitBodyStorage.h:212
Referenced.h
agx::Real
double Real
Definition: Real.h:42
agx::MergeSplitBodyStorage::getFrame
agx::Frame * getFrame()
Definition: MergeSplitBodyStorage.h:222
agx::Vector
Templated vector class.
Definition: Vector.h:52
agx::RigidBody::MotionControl
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:65
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
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::SetVector::size
size_t size() const
Return the number of inserted elements.
Definition: SetVector.h:114
agx::MergeSplitBodyStorage::getNumUpdates
size_t getNumUpdates()
Definition: MergeSplitBodyStorage.h:207
agx::MergeSplitBodyStorage::getTransformRelativeParent
AffineMatrix4x4 getTransformRelativeParent() const
Definition: MergeSplitBodyStorage.h:215
Geometry.h
agx::AffineMatrix4x4T< Real >
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::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::MergeSplitBodyStorage::GeometryObserverVector
agx::Vector< agx::observer_ptr< agxCollide::Geometry > > GeometryObserverVector
Definition: MergeSplitBodyStorage.h:40
agx::MergeSplitBodyStorage::getMotionControl
agx::RigidBody::MotionControl getMotionControl() const
Definition: MergeSplitBodyStorage.h:232
agx::MergeSplitBodyStorage::incrementNumUpdates
void incrementNumUpdates()
Definition: MergeSplitBodyStorage.h:203
agx::ref_ptr< Frame >
agx::MergeSplitBodyStorage::hasChildren
bool hasChildren() const
Definition: MergeSplitBodyStorage.h:237
agx::SetVector< MergeSplitBodyStorage * >
agx::MergeSplitBodyStorage
Book keeping of a body which can be merged with other bodies.
Definition: MergeSplitBodyStorage.h:35
agxUtil::setMotionControl
AGXPHYSICS_EXPORT void setMotionControl(agx::RigidBodyPtrVector &bodies, agx::RigidBody::MotionControl motionControl)
Utility function to set motion control for a vector of rigid bodies.
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::MergeSplit
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:37
agx::SPDMatrix3x3
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
Serializable.h
agx::MergeSplitBodyStorage::getNumChildren
size_t getNumChildren() const
Definition: MergeSplitBodyStorage.h:217
RigidBody.h
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agx::MergeSplitBodyStorage::resetNumUpdates
void resetNumUpdates()
Definition: MergeSplitBodyStorage.h:205
agx::MergeSplitBodyStorage::getRigidBody
agx::RigidBody * getRigidBody()
Definition: MergeSplitBodyStorage.h:209
agxTerrain::Profiler::clear
AGXTERRAIN_EXPORT void clear()
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agx::MergeSplitBodyStorage::isMerged
bool isMerged() const
Definition: MergeSplitBodyStorage.h:201