AGXDynamics  2.35.0.3
MergeSplit.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_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 
266 
267  size_t m_numMerge;
268  size_t m_numSplit;
269 
271 
274 
278 
279  bool m_enabled;
281 
284  };
285 
287 
288 }
289 
290 #endif /* _AGX_MERGESPLIT_H_ */
agxPhysics_export.h
SleepThreshold.h
agx::Real
double Real
Definition: Real.h:42
agx::MergeSplit::m_threshold
agx::ref_ptr< SleepThreshold > m_threshold
Definition: MergeSplit.h:270
agx::MergeSplit::m_enabled
bool m_enabled
Definition: MergeSplit.h:279
agx::Vector< agx::Physics::GeometryPairPtr, agxData::BufferProxyAllocator >
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::MergeSplit::m_listener
ListenerRef m_listener
Definition: MergeSplit.h:280
agx::MergeSplit::Listener::Listener
Listener()
Definition: MergeSplit.h:162
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::VectorPOD< GeometryContact * >
agx::MergeSplit::m_numSplit
size_t m_numSplit
Definition: MergeSplit.h:268
agx::observer_ptr< agxCollide::Space >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::MergeSplit::m_splitInPost
bool m_splitInPost
Definition: MergeSplit.h:283
Space.h
agx::MergeSplit::m_space
agx::observer_ptr< agxCollide::Space > m_space
Definition: MergeSplit.h:277
agx::MergeSplit::GeometryBodyHashVector
agx::HashVector< agxCollide::Geometry *, agx::ref_ptr< MergeSplitBodyStorage > > GeometryBodyHashVector
Definition: MergeSplit.h:264
agx::ref_ptr< Listener >
agx::MergeSplit::Listener
Class for intercepting merge/split events.
Definition: MergeSplit.h:159
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agx::MergeSplitBodyStorage
Book keeping of a body which can be merged with other bodies.
Definition: MergeSplitBodyStorage.h:35
agx::MergeSplit::ListenerRef
agx::ref_ptr< Listener > ListenerRef
Definition: MergeSplit.h:195
agx::MergeSplit::Listener::~Listener
virtual ~Listener()
Definition: MergeSplit.h:191
agx::MergeSplit::m_numMerge
size_t m_numMerge
Definition: MergeSplit.h:267
agx::MergeSplit::m_bodyStoragePool
MergeSplitBodyStorageRefVector m_bodyStoragePool
Definition: MergeSplit.h:276
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::MergeSplit::m_geometryBodyHash
GeometryBodyHashVector m_geometryBodyHash
Definition: MergeSplit.h:265
agxCollide::Space
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agx::MergeSplit::m_freeBodyStorage
MergeSplitBodyStoragePtrVector m_freeBodyStorage
Definition: MergeSplit.h:275
agx::MergeSplit::MergeSplitBodyStoragePtrVector
agx::Vector< MergeSplitBodyStorage * > MergeSplitBodyStoragePtrVector
Definition: MergeSplit.h:273
agxcollide_hash_types.h
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:269
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agx::MergeSplit::MergeSplitBodyStorageRefVector
agx::Vector< agx::ref_ptr< MergeSplitBodyStorage > > MergeSplitBodyStorageRefVector
Definition: MergeSplit.h:272
agx::SleepThreshold
Definition: SleepThreshold.h:28
MergeSplitBodyStorage.h
agxTerrain::Profiler::clear
AGXTERRAIN_EXPORT void clear()
agx::MergeSplit::m_bodiesToBeSplit
agx::RigidBodyObserverVector m_bodiesToBeSplit
Definition: MergeSplit.h:282
agx::HashVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
TimeStamp.h
agx::MergeSplitRef
agx::ref_ptr< MergeSplit > MergeSplitRef
Definition: MergeSplit.h:286