AGX Dynamics  2.37.3.2
MergeSplit.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_MERGESPLIT_H
18 #define AGX_MERGESPLIT_H
19 
20 #include <agx/TimeStamp.h>
21 #include <agxCollide/Space.h>
22 #include <agx/agxPhysics_export.h>
23 #include <agx/SleepThreshold.h>
26 
27 namespace agx
28 {
38  {
39  public:
40 
42  MergeSplit( agxCollide::Space *space=nullptr );
43 
47  MergeSplitThreshold *getThreshold();
48 
52  const MergeSplitThreshold *getThreshold() const;
53 
58  void setEnable( bool flag );
59 
70  void setSplitInPost( bool flag );
71 
73  bool getSplitInPost() const;
74 
76  bool getEnable( ) const;
77 
79  bool isEnabled( ) const;
80 
84  void clear();
85 
90  void split();
91 
104  bool split( agxCollide::Geometry* geometry, bool shouldUpdateContacts = true, bool forceSplit = false, bool splitImmediately=true );
105 
110  void merge();
111 
113  void setSpace( agxCollide::Space *space );
114 
118  static void calculateSeparatingVelocityAcceleration( agx::RigidBody *body1, agx::RigidBody* body2, agx::Real& dVel, agx::Real& dOmega, agx::Real& dAcc, agx::Real& dAngularAcc );
119 
121 
122  void pre( const agx::TimeStamp& t );
123  void post( const agx::TimeStamp& t );
124 
134  bool split( agx::RigidBody *bodyToBeSplit, bool forceSplit = false, bool splitImmediately=true );
135 
136 
151  bool merge( agx::RigidBody *child, agx::RigidBody *parent );
152 
159  class Listener : public agx::Referenced
160  {
161  public:
162  Listener() {}
163 
173  virtual bool merge( agx::RigidBody *parent, agx::RigidBody *child ) = 0;
174 
187  virtual bool split( agx::RigidBody *parent, agx::RigidBody *child, agxCollide::GeometryContact *contact ) = 0;
188 
189 
190  protected:
191  virtual ~Listener() {}
192  };
193 
194 
196 
200  void setListener( Listener *listener );
201 
205  Listener *getListener( );
206 
210  const Listener *getListener( ) const;
211 
212  bool validate ();
213 
214  protected:
215  friend class agxSDK::Simulation;
216  void registerGeometriesBodies( agxSDK::Simulation *sim );
217 
218  bool removeFromBodyStorage( agx::RigidBody *body );
219 
220 
221  bool shouldMerge( agx::RigidBody *body1, agx::RigidBody *body2, agxCollide::GeometryContact *contact ) const;
222  void updateContacts( const agxCollide::GeometryContactPtrVector& contacts, bool removeContacts = false ) const;
223 
234  bool _split( agx::RigidBody *bodyToBeSplit, agxCollide::GeometryContact *contact, bool forceSplit = false, bool splitImmediately=true );
235 
236 
237  bool sleep( agx::RigidBody *body1, agx::RigidBody *body2 );
238  bool wake( agx::RigidBody *body1, agx::RigidBody *body2 );
239 
240 
241  bool split( const agxCollide::GeometryContactPtrVector& contacts );
242 
243  bool split( agxCollide::Geometry *geom1, agxCollide::Geometry *geom2, agxCollide::GeometryContact *contact=nullptr );
244  bool split( const agxCollide::SeparationPairVector& separations );
245 
246  bool merge( const agxCollide::GeometryContactPtrVector& contacts );
247  bool performMerge( agx::RigidBody *child, agx::RigidBody *parent );
248 
249  //void transferGeometries( agx::RigidBody *child, const agxCollide::GeometryPtrVector& geometries, agx::RigidBody *parent );
250  void transferGeometries( agx::RigidBody *child, agxCollide::GeometryRefVector geometries, agx::RigidBody *parent );
251  void prepareForMerge( agx::RigidBody *body );
252  //bool verifyStorage();
253 
254  void addNotification();
255  void removeNotification();
256 
257  virtual ~MergeSplit();
258 
259  MergeSplitBodyStorage *getBodyStorage();
260  void returnBodyStorage( MergeSplitBodyStorage *bodyStorage );
261 
262  void clearStats();
263 
265  GeometryBodyHashVector m_geometryBodyHash;
266 
267  size_t m_numMerge;
268  size_t m_numSplit;
269 
271 
274 
275  MergeSplitBodyStoragePtrVector m_freeBodyStorage;
276  MergeSplitBodyStorageRefVector m_bodyStoragePool;
278 
279  bool m_enabled;
280  ListenerRef m_listener;
281 
284  };
285 
287 
288 }
289 
290 #endif /* _AGX_MERGESPLIT_H_ */
agx::ref_ptr< SleepThreshold > m_threshold
Definition: MergeSplit.h:270
AGXTERRAIN_EXPORT void clear()
ListenerRef m_listener
Definition: MergeSplit.h:280
size_t m_numSplit
Definition: MergeSplit.h:268
A contact between two geometries.
Definition: Contacts.h:270
#define AGXPHYSICS_EXPORT
agx::Real TimeStamp
Definition: TimeStamp.h:26
agx::observer_ptr< agxCollide::Space > m_space
Definition: MergeSplit.h:277
size_t m_numMerge
Definition: MergeSplit.h:267
Base class providing referencing counted objects.
Definition: Referenced.h:119
MergeSplitBodyStorageRefVector m_bodyStoragePool
Definition: MergeSplit.h:276
agx::ref_ptr< MergeSplit > MergeSplitRef
Definition: MergeSplit.h:286
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:37
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
GeometryBodyHashVector m_geometryBodyHash
Definition: MergeSplit.h:265
agx::HashVector< agxCollide::Geometry *, agx::ref_ptr< MergeSplitBodyStorage > > GeometryBodyHashVector
Definition: MergeSplit.h:264
agx::ref_ptr< Listener > ListenerRef
Definition: MergeSplit.h:195
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Book keeping of a body which can be merged with other bodies.
#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
MergeSplitBodyStoragePtrVector m_freeBodyStorage
Definition: MergeSplit.h:275
agx::Vector< MergeSplitBodyStorage *> MergeSplitBodyStoragePtrVector
Definition: MergeSplit.h:273
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
double Real
Definition: Real.h:42
agx::Vector< agx::ref_ptr< MergeSplitBodyStorage > > MergeSplitBodyStorageRefVector
Definition: MergeSplit.h:272
agx::RigidBodyObserverVector m_bodiesToBeSplit
Definition: MergeSplit.h:282
Class for intercepting merge/split events.
Definition: MergeSplit.h:159