AGX Dynamics  2.35.0.1
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 
48 
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 
206 
210  const Listener *getListener( ) const;
211 
212  bool validate ();
213 
214  protected:
215  friend class agxSDK::Simulation;
217 
219 
220 
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 
242 
244  bool split( const agxCollide::SeparationPairVector& separations );
245 
247  bool performMerge( agx::RigidBody *child, agx::RigidBody *parent );
248 
249  //void transferGeometries( agx::RigidBody *child, const agxCollide::GeometryPtrVector& geometries, agx::RigidBody *parent );
252  //bool verifyStorage();
253 
256 
257  virtual ~MergeSplit();
258 
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_ */
#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
#define AGXPHYSICS_EXPORT
A contact between two geometries.
Definition: Contacts.h:270
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:82
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Book keeping of a body which can be merged with other bodies.
Class for intercepting merge/split events.
Definition: MergeSplit.h:160
virtual bool split(agx::RigidBody *parent, agx::RigidBody *child, agxCollide::GeometryContact *contact)=0
If this method returns true, the split operation will proceed, otherwise it will be canceled.
virtual bool merge(agx::RigidBody *parent, agx::RigidBody *child)=0
If this method returns true, the merge operation will proceed, otherwise it will be canceled.
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:38
bool sleep(agx::RigidBody *body1, agx::RigidBody *body2)
bool wake(agx::RigidBody *body1, agx::RigidBody *body2)
GeometryBodyHashVector m_geometryBodyHash
Definition: MergeSplit.h:265
bool getSplitInPost() const
bool split(const agxCollide::GeometryContactPtrVector &contacts)
void split()
Explicit call to split, will go and ask space for contacts and separations and see if something can b...
size_t m_numSplit
Definition: MergeSplit.h:268
const MergeSplitThreshold * getThreshold() const
void merge()
Explicit call to merge, will go and ask space for contacts and separations and see if something can b...
bool split(agx::RigidBody *bodyToBeSplit, bool forceSplit=false, bool splitImmediately=true)
Take the specified body bodyToBeSplit and if it is merged, then split it from any parents,...
MergeSplitBodyStorageRefVector m_bodyStoragePool
Definition: MergeSplit.h:276
void addNotification()
void setSplitInPost(bool flag)
Specifies whether the split should occur in the pre solver step, or in the post step.
void transferGeometries(agx::RigidBody *child, agxCollide::GeometryRefVector geometries, agx::RigidBody *parent)
void pre(const agx::TimeStamp &t)
void registerGeometriesBodies(agxSDK::Simulation *sim)
MergeSplitBodyStorage * getBodyStorage()
agx::Vector< MergeSplitBodyStorage * > MergeSplitBodyStoragePtrVector
Definition: MergeSplit.h:273
agx::observer_ptr< agxCollide::Space > m_space
Definition: MergeSplit.h:277
MergeSplitThreshold * getThreshold()
void clear()
Split all merged bodies, clear all data structures.
ListenerRef m_listener
Definition: MergeSplit.h:280
void updateContacts(const agxCollide::GeometryContactPtrVector &contacts, bool removeContacts=false) const
bool merge(agx::RigidBody *child, agx::RigidBody *parent)
Explicitly merge two bodies.
agx::Vector< agx::ref_ptr< MergeSplitBodyStorage > > MergeSplitBodyStorageRefVector
Definition: MergeSplit.h:272
static void calculateSeparatingVelocityAcceleration(agx::RigidBody *body1, agx::RigidBody *body2, agx::Real &dVel, agx::Real &dOmega, agx::Real &dAcc, agx::Real &dAngularAcc)
Calculate the relative velocity/acceleration of two rigidbodies center of mass velocities.
agx::ref_ptr< Listener > ListenerRef
Definition: MergeSplit.h:195
bool split(agxCollide::Geometry *geom1, agxCollide::Geometry *geom2, agxCollide::GeometryContact *contact=nullptr)
virtual ~MergeSplit()
void setSpace(agxCollide::Space *space)
Tell MergeSplit which space to use for accessing contacts.
void prepareForMerge(agx::RigidBody *body)
void returnBodyStorage(MergeSplitBodyStorage *bodyStorage)
bool _split(agx::RigidBody *bodyToBeSplit, agxCollide::GeometryContact *contact, bool forceSplit=false, bool splitImmediately=true)
Take the specified body bodyToBeSplit and if it is merged, then split it from any parents,...
MergeSplitBodyStoragePtrVector m_freeBodyStorage
Definition: MergeSplit.h:275
void post(const agx::TimeStamp &t)
const Listener * getListener() const
Listener * getListener()
agx::HashVector< agxCollide::Geometry *, agx::ref_ptr< MergeSplitBodyStorage > > GeometryBodyHashVector
Definition: MergeSplit.h:264
void removeNotification()
MergeSplit(agxCollide::Space *space=nullptr)
Default constructor.
bool merge(const agxCollide::GeometryContactPtrVector &contacts)
bool getEnable() const
bool performMerge(agx::RigidBody *child, agx::RigidBody *parent)
agx::ref_ptr< SleepThreshold > m_threshold
Definition: MergeSplit.h:270
agx::RigidBodyObserverVector m_bodiesToBeSplit
Definition: MergeSplit.h:282
size_t m_numMerge
Definition: MergeSplit.h:267
bool split(const agxCollide::SeparationPairVector &separations)
void setListener(Listener *listener)
Specify a point to a listener that will be called upon merge/split events.
bool isEnabled() const
void setEnable(bool flag)
Enable/disable MergeSplit.
bool split(agxCollide::Geometry *geometry, bool shouldUpdateContacts=true, bool forceSplit=false, bool splitImmediately=true)
Take a specified geometry geometry and locate its ORIGINAL body (which was the original body that thi...
bool shouldMerge(agx::RigidBody *body1, agx::RigidBody *body2, agxCollide::GeometryContact *contact) const
bool removeFromBodyStorage(agx::RigidBody *body)
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::ref_ptr< MergeSplit > MergeSplitRef
Definition: MergeSplit.h:286
double Real
Definition: Real.h:42
agx::Real TimeStamp
Definition: TimeStamp.h:26