AGX Dynamics  2.35.0.1
agx::MergeSplit Class Reference

Class which will go through contacting/separating bodies and determine if the bodies can be merged (geometries from bodyA can go into bodyB and bodyB will now move as one rigid body) or split (the original geometries of bodyA can be transferred back so BodyA can move as a separate body). More...

#include <MergeSplit.h>

+ Inheritance diagram for agx::MergeSplit:

Classes

class  Listener
 Class for intercepting merge/split events. More...
 

Public Types

typedef agx::ref_ptr< Listener > ListenerRef
 

Public Member Functions

 MergeSplit (agxCollide::Space *space=nullptr)
 Default constructor. More...
 
void clear ()
 Split all merged bodies, clear all data structures. More...
 
const char * getClassName () const override
 
bool getEnable () const
 
Listener * getListener ()
 
const Listener * getListener () const
 
bool getSplitInPost () const
 
agxStream::StorageAgent * getStorageAgent () const override
 
MergeSplitThreshold * getThreshold ()
 
const MergeSplitThreshold * getThreshold () const
 
bool isEnabled () const
 
void merge ()
 Explicit call to merge, will go and ask space for contacts and separations and see if something can be merged based on those contacts. More...
 
bool merge (agx::RigidBody *child, agx::RigidBody *parent)
 Explicitly merge two bodies. More...
 
void post (const agx::TimeStamp &t)
 
void pre (const agx::TimeStamp &t)
 
virtual void restore (agxStream::InputArchive &in) override
 
void setEnable (bool flag)
 Enable/disable MergeSplit. More...
 
void setListener (Listener *listener)
 Specify a point to a listener that will be called upon merge/split events. More...
 
void setSpace (agxCollide::Space *space)
 Tell MergeSplit which space to use for accessing contacts. More...
 
void setSplitInPost (bool flag)
 Specifies whether the split should occur in the pre solver step, or in the post step. More...
 
void split ()
 Explicit call to split, will go and ask space for contacts and separations and see if something can be split based on those contacts. More...
 
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, make it a free non-merged body. More...
 
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 this geometry belonged to) and split that. More...
 
virtual void store (agxStream::OutputArchive &out) const override
 
bool validate ()
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor. More...
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object. More...
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
- Public Member Functions inherited from agxStream::Serializable
virtual ~Serializable ()
 Destructor for normal C++ use but hidden from SWIG bindings. More...
 
bool getEnableSerialization () const
 
bool getEnableUuidGeneration ()
 
agx::UInt32 getIndex () const
 This index is given at creation of this object. More...
 
agx::Uuid getUuid () const
 
bool isFinished () const
 
void setEnableSerialization (bool flag)
 Set to false to disable serialization of this object. More...
 
void setFinished ()
 Tells this class that it is restored correctly and should not be deleted during destruction of an Archive. More...
 
void setUuid (const agx::Uuid &uuid)
 Explicitly set a Uuid on a serializable object. More...
 

Static Public Member Functions

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. More...
 
static agxStream::Serializable * create ()
 
static agxStream::Serializable * create (agxStream::InputArchive &)
 
static const char * getConstructClassId ()
 
- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- Static Public Member Functions inherited from agxStream::Serializable
static void setEnableUuidGeneration (bool flag)
 Specify if there should be UUID:s generated for each new Serializable object. By default it is enabled. More...
 

Protected Types

typedef agx::HashVector< agxCollide::Geometry *, agx::ref_ptr< MergeSplitBodyStorage > > GeometryBodyHashVector
 
typedef agx::Vector< MergeSplitBodyStorage * > MergeSplitBodyStoragePtrVector
 
typedef agx::Vector< agx::ref_ptr< MergeSplitBodyStorage > > MergeSplitBodyStorageRefVector
 

Protected Member Functions

virtual ~MergeSplit ()
 
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, make it a free non-merged body. More...
 
void addNotification ()
 
void clearStats ()
 
MergeSplitBodyStorage * getBodyStorage ()
 
bool merge (const agxCollide::GeometryContactPtrVector &contacts)
 
bool performMerge (agx::RigidBody *child, agx::RigidBody *parent)
 
void prepareForMerge (agx::RigidBody *body)
 
void registerGeometriesBodies (agxSDK::Simulation *sim)
 
bool removeFromBodyStorage (agx::RigidBody *body)
 
void removeNotification ()
 
void returnBodyStorage (MergeSplitBodyStorage *bodyStorage)
 
bool shouldMerge (agx::RigidBody *body1, agx::RigidBody *body2, agxCollide::GeometryContact *contact) const
 
bool sleep (agx::RigidBody *body1, agx::RigidBody *body2)
 
bool split (agxCollide::Geometry *geom1, agxCollide::Geometry *geom2, agxCollide::GeometryContact *contact=nullptr)
 
bool split (const agxCollide::GeometryContactPtrVector &contacts)
 
bool split (const agxCollide::SeparationPairVector &separations)
 
void transferGeometries (agx::RigidBody *child, agxCollide::GeometryRefVector geometries, agx::RigidBody *parent)
 
void updateContacts (const agxCollide::GeometryContactPtrVector &contacts, bool removeContacts=false) const
 
bool wake (agx::RigidBody *body1, agx::RigidBody *body2)
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor. More...
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
- Protected Member Functions inherited from agxStream::Serializable
 Serializable ()
 Default constructor. More...
 
 Serializable (const Serializable &other)
 Copy constructor. More...
 
void generateUuid ()
 

Protected Attributes

agx::RigidBodyObserverVector m_bodiesToBeSplit
 
MergeSplitBodyStorageRefVector m_bodyStoragePool
 
bool m_enabled
 
MergeSplitBodyStoragePtrVector m_freeBodyStorage
 
GeometryBodyHashVector m_geometryBodyHash
 
ListenerRef m_listener
 
size_t m_numMerge
 
size_t m_numSplit
 
agx::observer_ptr< agxCollide::Space > m_space
 
bool m_splitInPost
 
agx::ref_ptr< SleepThreshold > m_threshold
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Additional Inherited Members

- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Detailed Description

Class which will go through contacting/separating bodies and determine if the bodies can be merged (geometries from bodyA can go into bodyB and bodyB will now move as one rigid body) or split (the original geometries of bodyA can be transferred back so BodyA can move as a separate body).

Default is splitting bodies due to contacts in a PRE step, that is after contacts are generated and before solver.

Deprecated:
Instead we recommend using AMOR/MergeSplitHandler

Definition at line 37 of file MergeSplit.h.

Member Typedef Documentation

◆ GeometryBodyHashVector

◆ ListenerRef

Definition at line 195 of file MergeSplit.h.

◆ MergeSplitBodyStoragePtrVector

◆ MergeSplitBodyStorageRefVector

Constructor & Destructor Documentation

◆ MergeSplit()

agx::MergeSplit::MergeSplit ( agxCollide::Space *  space = nullptr)

Default constructor.

◆ ~MergeSplit()

virtual agx::MergeSplit::~MergeSplit ( )
protectedvirtual

Member Function Documentation

◆ _split()

bool agx::MergeSplit::_split ( agx::RigidBody *  bodyToBeSplit,
agxCollide::GeometryContact *  contact,
bool  forceSplit = false,
bool  splitImmediately = true 
)
protected

Take the specified body bodyToBeSplit and if it is merged, then split it from any parents, make it a free non-merged body.

Parameters
bodyToBeSplit- The body that should be split from any merged bodies
contact- set to the GeometryContact if it was a contact/impacting resulting in the split, otherwise nullptr.
forceSplit- if true, body will be split, even if it has properties stating it should not.
splitImmediately- Split now not later in a batch with other bodies that are going to be split
Returns
true if body was successfully split, false if body was not merged, hence split failed

◆ addNotification()

void agx::MergeSplit::addNotification ( )
protected

◆ calculateSeparatingVelocityAcceleration()

static void agx::MergeSplit::calculateSeparatingVelocityAcceleration ( agx::RigidBody *  body1,
agx::RigidBody *  body2,
agx::Real &  dVel,
agx::Real &  dOmega,
agx::Real &  dAcc,
agx::Real &  dAngularAcc 
)
static

Calculate the relative velocity/acceleration of two rigidbodies center of mass velocities.

◆ clear()

void agx::MergeSplit::clear ( )

Split all merged bodies, clear all data structures.

◆ clearStats()

void agx::MergeSplit::clearStats ( )
protected

◆ create() [1/2]

static agxStream::Serializable* agx::MergeSplit::create ( )
inlinestatic

Definition at line 120 of file MergeSplit.h.

◆ create() [2/2]

static agxStream::Serializable* agx::MergeSplit::create ( agxStream::InputArchive &  )
inlinestatic

Definition at line 120 of file MergeSplit.h.

◆ getBodyStorage()

MergeSplitBodyStorage* agx::MergeSplit::getBodyStorage ( )
protected

◆ getClassName()

const char* agx::MergeSplit::getClassName ( ) const
inlineoverridevirtual
Returns
the class name of this class.

Reimplemented from agxStream::Serializable.

Definition at line 120 of file MergeSplit.h.

◆ getConstructClassId()

static const char* agx::MergeSplit::getConstructClassId ( )
inlinestatic

Definition at line 120 of file MergeSplit.h.

◆ getEnable()

bool agx::MergeSplit::getEnable ( ) const
Returns
true if MergeSplit is enabled

◆ getListener() [1/2]

Listener* agx::MergeSplit::getListener ( )
Returns
pointer to a registered listener

◆ getListener() [2/2]

const Listener* agx::MergeSplit::getListener ( ) const
Returns
a const pointer to a registered listener

◆ getSplitInPost()

bool agx::MergeSplit::getSplitInPost ( ) const
Returns
true if split is enabled to occur in post solver step.

◆ getStorageAgent()

agxStream::StorageAgent* agx::MergeSplit::getStorageAgent ( ) const
inlineoverridevirtual
Returns
the storage agent

Implements agxStream::Serializable.

Definition at line 120 of file MergeSplit.h.

◆ getThreshold() [1/2]

MergeSplitThreshold* agx::MergeSplit::getThreshold ( )
Returns
a pointer to a MergeSplitThreshold object which holds the acceleration/velocity threshold settings

◆ getThreshold() [2/2]

const MergeSplitThreshold* agx::MergeSplit::getThreshold ( ) const
Returns
a const pointer to a MergeSplitThreshold object which holds the acceleration/velocity threshold settings

◆ isEnabled()

bool agx::MergeSplit::isEnabled ( ) const
Returns
true if MergeSplit is enabled

◆ merge() [1/3]

void agx::MergeSplit::merge ( )

Explicit call to merge, will go and ask space for contacts and separations and see if something can be merged based on those contacts.

Requires that Space::update() has been called prior to this.

◆ merge() [2/3]

bool agx::MergeSplit::merge ( agx::RigidBody *  child,
agx::RigidBody *  parent 
)

Explicitly merge two bodies.

parent will be parent if the following is true:

parent is static, child is not parent has a constraint attached to itself, child has not

If the above rules fails, the two bodies will be swapped and child will be parent. If merge cannot proceed (if both bodies are static or both have constraints, the method will return false).

There is currently no test if any of the two bodies are already merged. If so, the result will be unpredicted.

Parameters
child- The body that will be the child unless above rule fails
parent- The body that will be the parent unless above rule fails
Returns
true if merge was done, false if something went wrong.

◆ merge() [3/3]

bool agx::MergeSplit::merge ( const agxCollide::GeometryContactPtrVector &  contacts)
protected

◆ performMerge()

bool agx::MergeSplit::performMerge ( agx::RigidBody *  child,
agx::RigidBody *  parent 
)
protected

◆ post()

void agx::MergeSplit::post ( const agx::TimeStamp &  t)

◆ pre()

void agx::MergeSplit::pre ( const agx::TimeStamp &  t)

◆ prepareForMerge()

void agx::MergeSplit::prepareForMerge ( agx::RigidBody *  body)
protected

◆ registerGeometriesBodies()

void agx::MergeSplit::registerGeometriesBodies ( agxSDK::Simulation *  sim)
protected

◆ removeFromBodyStorage()

bool agx::MergeSplit::removeFromBodyStorage ( agx::RigidBody *  body)
protected

◆ removeNotification()

void agx::MergeSplit::removeNotification ( )
protected

◆ restore()

virtual void agx::MergeSplit::restore ( agxStream::InputArchive &  in)
overridevirtual

◆ returnBodyStorage()

void agx::MergeSplit::returnBodyStorage ( MergeSplitBodyStorage *  bodyStorage)
protected

◆ setEnable()

void agx::MergeSplit::setEnable ( bool  flag)

Enable/disable MergeSplit.

Parameters
flag- If true, MergeSplit will be enabled, if false, all merged bodies will be split,

◆ setListener()

void agx::MergeSplit::setListener ( Listener *  listener)

Specify a point to a listener that will be called upon merge/split events.

◆ setSpace()

void agx::MergeSplit::setSpace ( agxCollide::Space *  space)

Tell MergeSplit which space to use for accessing contacts.

◆ setSplitInPost()

void agx::MergeSplit::setSplitInPost ( bool  flag)

Specifies whether the split should occur in the pre solver step, or in the post step.

A system where split occurs in pre will appear more dynamic and realistic, however, it will probably result in a more overall dynamic system with somewhat lower performance. Splitting in pre might also cause jitter in large piles, due to that when splitting in pre, no contacts are created until next time step. Meaning that gravity will pull the split body, let it fall during one time step, and at the next contacts will be created and it will be stabilized. So for single objects on merged ground split in pre will work just fine, for larger piles, some jitter might be noticed.

Parameters
flagif true, the split will occur in post, otherwise in pre (default)

◆ shouldMerge()

bool agx::MergeSplit::shouldMerge ( agx::RigidBody *  body1,
agx::RigidBody *  body2,
agxCollide::GeometryContact *  contact 
) const
protected

◆ sleep()

bool agx::MergeSplit::sleep ( agx::RigidBody *  body1,
agx::RigidBody *  body2 
)
protected

◆ split() [1/6]

void agx::MergeSplit::split ( )

Explicit call to split, will go and ask space for contacts and separations and see if something can be split based on those contacts.

Requires that Space::update() has been called prior to this.

◆ split() [2/6]

bool agx::MergeSplit::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, make it a free non-merged body.

Parameters
bodyToBeSplit- The body that should be split from any merged bodies
forceSplit- if true, body will be split, even if it has properties stating it should not.
splitImmediately- Split now not later in a batch with other bodies that are going to be split
Returns
true if body was successfully split, false if body was not merged, hence split failed

◆ split() [3/6]

bool agx::MergeSplit::split ( agxCollide::Geometry *  geom1,
agxCollide::Geometry *  geom2,
agxCollide::GeometryContact *  contact = nullptr 
)
protected

◆ split() [4/6]

bool agx::MergeSplit::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 this geometry belonged to) and split that.

This will also mean that additional geometry (belonging to this Body) will be taken out of a merged body.

Parameters
geometry- The geometry which has an original owner body that will be split
shouldUpdateContacts- If true, and IF the split succeeded, all contacts will be investigated and updated to get correct body/geometry pointers.
forceSplit- if true, body will be split, even if it has properties stating it should not. Geometry will be split even if it has property stating it should not.
splitImmediately- If true the geometry will be split now and not later in a batch with other splitted geometries
Returns
true if body was successfully split, false if body was not merged, hence split failed.

◆ split() [5/6]

bool agx::MergeSplit::split ( const agxCollide::GeometryContactPtrVector &  contacts)
protected

◆ split() [6/6]

bool agx::MergeSplit::split ( const agxCollide::SeparationPairVector &  separations)
protected

◆ store()

virtual void agx::MergeSplit::store ( agxStream::OutputArchive &  out) const
overridevirtual

◆ transferGeometries()

void agx::MergeSplit::transferGeometries ( agx::RigidBody *  child,
agxCollide::GeometryRefVector  geometries,
agx::RigidBody *  parent 
)
protected

◆ updateContacts()

void agx::MergeSplit::updateContacts ( const agxCollide::GeometryContactPtrVector &  contacts,
bool  removeContacts = false 
) const
protected

◆ validate()

bool agx::MergeSplit::validate ( )

◆ wake()

bool agx::MergeSplit::wake ( agx::RigidBody *  body1,
agx::RigidBody *  body2 
)
protected

Member Data Documentation

◆ m_bodiesToBeSplit

agx::RigidBodyObserverVector agx::MergeSplit::m_bodiesToBeSplit
protected

Definition at line 282 of file MergeSplit.h.

◆ m_bodyStoragePool

MergeSplitBodyStorageRefVector agx::MergeSplit::m_bodyStoragePool
protected

Definition at line 276 of file MergeSplit.h.

◆ m_enabled

bool agx::MergeSplit::m_enabled
protected

Definition at line 279 of file MergeSplit.h.

◆ m_freeBodyStorage

MergeSplitBodyStoragePtrVector agx::MergeSplit::m_freeBodyStorage
protected

Definition at line 275 of file MergeSplit.h.

◆ m_geometryBodyHash

GeometryBodyHashVector agx::MergeSplit::m_geometryBodyHash
protected

Definition at line 265 of file MergeSplit.h.

◆ m_listener

ListenerRef agx::MergeSplit::m_listener
protected

Definition at line 280 of file MergeSplit.h.

◆ m_numMerge

size_t agx::MergeSplit::m_numMerge
protected

Definition at line 267 of file MergeSplit.h.

◆ m_numSplit

size_t agx::MergeSplit::m_numSplit
protected

Definition at line 268 of file MergeSplit.h.

◆ m_space

agx::observer_ptr<agxCollide::Space> agx::MergeSplit::m_space
protected

Definition at line 277 of file MergeSplit.h.

◆ m_splitInPost

bool agx::MergeSplit::m_splitInPost
protected

Definition at line 283 of file MergeSplit.h.

◆ m_threshold

agx::ref_ptr<SleepThreshold> agx::MergeSplit::m_threshold
protected

Definition at line 270 of file MergeSplit.h.


The documentation for this class was generated from the following file: