462 T* getAlgorithm()
const;
467 static
void storePersistentData( const
agx::RigidBody* rb,
agxStream::OutputArchive& out );
468 static
void storePersistentData( const
agxCollide::Geometry* geometry,
agxStream::OutputArchive& out );
469 static
void storePersistentData( const
agx::HighLevelConstraintImplementation* constraint,
agxStream::OutputArchive& out );
470 static
void storePersistentData( const
agxWire::Wire* wire,
agxStream::OutputArchive& out );
472 static
void restorePersistentData(
agx::RigidBody* rb,
agxStream::InputArchive& in );
473 static
void restorePersistentData(
agxCollide::Geometry* geometry,
agxStream::InputArchive& in );
474 static
void restorePersistentData(
agx::HighLevelConstraintImplementation* constraint,
agxStream::InputArchive& in );
475 static
void restorePersistentData(
agxWire::Wire* wire,
agxStream::InputArchive& in );
477 template< typename T >
478 static T* getOrCreateCustomData(
agx::HighLevelConstraintImplementation* constraint );
480 template< typename T >
481 static T* getCustomData( const
agx::HighLevelConstraintImplementation* constraint );
483 static
agx::Bool isMergedGranulate( const
agx::RigidBody* rb );
484 static
void setIsMergedGranulate(
agx::RigidBody* rb,
agx::Bool flag );
492 virtual
void postIntegrate();
505 template<typename T, typename ObjT>
529 virtual
void preCollide();
535 virtual
void separations(const
agxCollide::SeparationPairVector& separations);
540 virtual
void preStep();
545 virtual
void postStep();
551 virtual
void reset(
agx::Bool resetState = true );
556 virtual
void mergeSplitBegin();
561 virtual
void mergeSplitEnd();
566 virtual
void store(
agxStream::OutputArchive& out ) const;
580 GLOBAL_MERGE_ENABLED = 1 << 1,
581 GLOBAL_SPLIT_ENABLED = 1 << 2,
582 SERIALIZATION_ENABLED = 1 << 3,
583 SPLIT_ON_SEPARATION = 1 << 4,
584 IN_POST_SOLVE = 1 << 5
586 typedef agx::BitState< EState, agx::Int32 > State;
602 struct MergeableHandlerData :
public HandlerData
606 MERGED_BY_HANDLER = 1 << 0,
607 MERGED_GRANULATE = 1 << 1
609 typedef agx::BitState< EState, agx::Int32 >
State;
612 MergeSplitHandler* handler;
615 MergeableHandlerData() : state(), handler( nullptr ) {}
616 virtual ~MergeableHandlerData() {}
631 struct BodyHandlerData :
public MergeableHandlerData
634 virtual ~BodyHandlerData() {}
640 struct GeometryHandlerData :
public MergeableHandlerData
643 virtual ~GeometryHandlerData() {}
649 struct ConstraintHandlerData :
public MergeableHandlerData
654 virtual ~ConstraintHandlerData() {}
661 struct WireHandlerData :
public HandlerData
665 if ( child ==
nullptr )
666 child =
new WireHandlerData();
668 child->
as<WireHandlerData>()->properties = properties->clone()->as<MergeSplitProperties>();
681 template<
typename DataT,
typename ObjT>
682 static DataT* getHandlerData(
const ObjT& obj );
687 template<
typename DataT,
typename ObjT>
688 static DataT* getOrCreateHandlerData( ObjT obj );
693 template<
typename DataT,
typename SourceT,
typename DestT>
694 static void _transferProperties(
const SourceT* source, DestT* destination );
699 static void setDefaultState( State& state );
714 friend class MergeSplitMergedBodyListener;
744 void clearAndAddDefaultAlgorithms();
749 void handlePossibleGranulateBodies(
bool updateSpace);
762 void updateMergedBodiesSimulationState(
agx::Bool commitGeneratedInteractions );
767 void performIslandSplitting();
799 const HandlerData* data = getHandlerData<HandlerData>( rb );
800 return data !=
nullptr ? data->properties :
nullptr;
805 HandlerData* data = getHandlerData<HandlerData>(rb);
806 return data !=
nullptr ? data->properties :
nullptr;
811 const HandlerData* data = getHandlerData<HandlerData>( geometry );
812 if ( data !=
nullptr && data->properties !=
nullptr )
813 return data->properties;
819 const HandlerData* data = getHandlerData<HandlerData>( geometry );
820 if ( data !=
nullptr && data->properties !=
nullptr )
821 return data->properties;
840 const HandlerData* data = getHandlerData<HandlerData>( constraint );
841 return data !=
nullptr ? data->properties :
nullptr;
846 const HandlerData* data = getHandlerData<HandlerData>( constraint );
847 return data !=
nullptr ? data->properties :
nullptr;
852 const MergeableHandlerData* handlerData = getHandlerData<MergeableHandlerData>( rb );
853 return handlerData !=
nullptr && handlerData->state.Is( MergeableHandlerData::MERGED_BY_HANDLER ) && handlerData->handler ==
this;
856 template<
typename DataT,
typename ObjT>
857 inline DataT* MergeSplitHandler::getHandlerData(
const ObjT& obj )
862 template<
typename DataT,
typename ObjT>
863 inline DataT* MergeSplitHandler::getOrCreateHandlerData( ObjT obj )
869 template<
typename DataT,
typename SourceT,
typename DestT>
870 void MergeSplitHandler::_transferProperties(
const SourceT* source, DestT* destination )
872 if (
static_cast<const void*
>( source ) ==
static_cast<void*
>( destination ) ||
874 destination ==
nullptr )
877 const auto sourceData = MergeSplitHandler::getHandlerData<HandlerData>( source );
878 if ( sourceData ==
nullptr )
881 auto destinationData = MergeSplitHandler::getOrCreateHandlerData<DataT>( destination );
882 destinationData->properties = sourceData->properties;
885 template<
typename T >
888 ConstraintHandlerData* data = MergeSplitHandler::getOrCreateHandlerData<ConstraintHandlerData>( constraint );
889 if ( data->customData ==
nullptr )
890 data->customData =
new T();
892 return data->customData->as<T>();
895 template<
typename T >
898 const ConstraintHandlerData* data = MergeSplitHandler::getHandlerData<ConstraintHandlerData>( constraint );
899 return data !=
nullptr && data->customData !=
nullptr ? data->customData->as<T>() :
nullptr;
904 const BodyHandlerData* data = getHandlerData<BodyHandlerData>( rb );
905 return data !=
nullptr && data->state.Is( MergeableHandlerData::MERGED_GRANULATE );
910 BodyHandlerData* data = getOrCreateHandlerData<BodyHandlerData>( rb );
911 data->state.update( MergeableHandlerData::MERGED_GRANULATE, flag );
917 for (
const auto& algorithm : m_mergeSplitAlgorithms )
918 if ( algorithm->template is<T>() )
919 return algorithm->template as<T>();
923 template<
typename T,
typename ObjT>
926 return getThresholdsFromProperties<T>(
getProperties( obj ), callback );
930 const T* MergeSplitHandler::getThresholdsFromProperties(
const MergeSplitProperties* properties,
933 const T* thresholds =
nullptr;
935 if ( properties ==
nullptr || (thresholds = properties->getMergeSplitThresholds<T>( callbackIndex )) ==
nullptr )
936 thresholds = (T*)m_globalThresholds[ callbackIndex ].get();
948 return ( properties !=
nullptr && properties->
getEnableMerge() ) ||
949 ( properties ==
nullptr && m_state.Is( GLOBAL_MERGE_ENABLED ) );
955 return ( properties !=
nullptr && properties->
getEnableSplit() ) ||
956 ( properties ==
nullptr && m_state.Is( GLOBAL_SPLIT_ENABLED ) );
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
agx::RigidBody * getRigidBody()
Specific thresholds used to split and merge objects given constraints.
A collection of merge ignore group ID pairs for which merge should be rejected.
Object containing merge-split actions to be processed by the agxSDK::MergeSplitHandler.
Data for merge or split actions created in an implementation of an agxSDK::MergeSplitAlgorithm.
Stateless base class for merge and split of interactions.
Base class for a merge split algorithm handling a set of merged bodies.
void setEnableMergePair(agx::UInt32 group1, agx::UInt32 group2, agx::Bool enable)
If enable is false, from now on reject merges between bodies in the two groups even when the MergeSpl...
agx::Bool maySplitProperties(const agxSDK::MergeSplitProperties *properties) const
static agxSDK::MergeSplitProperties * getOrCreateProperties(agx::RigidBody *rb)
Creates (or returns already present) merge-split parameters given a rigid body.
static agxSDK::MergeSplitProperties * getProperties(agxWire::Wire *wire)
agx::Bool merge(agx::MergedBody::EdgeInteraction *edgeInteraction)
Merge bodies given an edge interaction.
static const agxSDK::MergeSplitProperties * getProperties(const agxWire::Wire *wire)
const agxSDK::Simulation * getSimulation() const
agx::Bool getEnableMergePair(agx::UInt32 group1, agx::UInt32 group2)
agx::Bool mayMerge(const agx::RigidBody *rb1, const agx::RigidBody *rb2) const
static agxSDK::MergeSplitProperties * getOrCreateProperties(agx::ConstraintImplementation *constraint)
Creates (or returns already present) merge-split parameters given a constraint implementation.
agx::Bool getEnableGlobalMergeSplit() const
void setEnableMergePair(const agx::Name &group1, const agx::Name &group2, agx::Bool enable)
If enable is false, from now on reject merges between bodies in the two groups even when the MergeSpl...
agx::Bool mayMergeProperties(const agxSDK::MergeSplitProperties *properties) const
static const agxSDK::MergeSplitProperties * getProperties(const agx::RigidBody *rb)
agx::Bool maySplit(const agx::RigidBody *rb, const agxSDK::MergeSplitProperties *properties) const
void setEnable(agx::Bool enable)
Enable/disable merge split.
agx::Bool remove(agxSDK::MergeSplitAlgorithm *mergeSplitAlgorithm)
Remove split algorithm.
agx::Bool getEnableGlobalSplit() const
static agxSDK::MergeSplitProperties * getOrCreateProperties(agxWire::Wire *wire)
Creates (or returns already present) merge-split parameters given a wire.
void setEnableSerialization(agx::Bool enable)
Enable/disable serialization of this object.
agx::Vector< agx::MergedBodyRef > MergedBodyRefContainer
void traverse(agx::MergedBody::EdgeInteractionVisitor visitor) const
Traverse all edges currently active in all merged bodies handled by this handler.
static void transferProperties(const agxWire::Wire *wire, agx::Constraint *constraint)
Transfers merge-split properties from the wire to the constraint.
agxSDK::GeometryContactMergeSplitThresholds * getGlobalContactThresholds() const
Global thresholds for contacts.
agxSDK::WireMergeSplitThresholds * getGlobalWireThresholds() const
Global thresholds for wires.
static agx::Bool isMergedByHandler(const agx::RigidBody *rb)
Determine if a body is merged explicitly (added to an agx::MergedBody by the user) or merged by an ag...
const MergedBodyRefContainer & getMergedBodies() const
void setEnableGlobalSplit(agx::Bool enable)
Enable/disable global split for all objects not having their MergeSplitProperties set.
agx::Bool getEnableMergePair(const agx::Name &group1, const agx::Name &group2)
static agxSDK::MergeSplitProperties * getOrCreateProperties(agx::Constraint *constraint)
Creates (or returns already present) merge-split parameters given a constraint.
agx::Bool getEnableGlobalMerge() const
agx::Bool mayMerge(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2) const
void registerMergedBody(agx::MergedBody *mergedBody)
Register merged body to this merge-split handler.
agx::Bool getEnableSerialization() const
agx::Bool getEnableMergePair(const agx::Name &group1, agx::UInt32 group2)
MergeSplitAlgorithmContainer getAlgorithms() const
agx::Bool mayMerge(const agx::RigidBody *rb1, const agxSDK::MergeSplitProperties *p1, const agx::RigidBody *rb2, const agxSDK::MergeSplitProperties *p2) const
void setEnableGlobalMerge(agx::Bool enable)
Enable/disable global merge for all objects not having their MergeSplitProperties set.
static void transferProperties(const agx::RigidBody *source, agx::RigidBody *destination)
Transfers merge-split properties from source rigid body to another rigid body instance.
agx::Vector< agxSDK::MergeSplitAlgorithmRef > MergeSplitAlgorithmContainer
static void transferProperties(const agxWire::Wire *wire, agx::RigidBody *rb)
Transfers merge-split properties from the wire to the rigid body.
agx::Bool getEnableSplitOnSeparation() const
void setEnableMergePair(const agx::Name &group1, agx::UInt32 group2, agx::Bool enable)
If enable is false, from now on reject merges between bodies in the two groups even when the MergeSpl...
agx::Bool add(agxSDK::MergeSplitAlgorithm *mergeSplitAlgorithm)
Add new merge-split algorithm.
void setEnableMergePair(agx::UInt32 group1, const agx::Name &group2, agx::Bool enable)
If enable is false, from now on reject merges between bodies in the two groups even when the MergeSpl...
agxSDK::ConstraintMergeSplitThresholds * getGlobalConstraintThresholds() const
Global thresholds for constraints.
bool writeConnectivityGraph(const char *filename) const
Write the MergedBody graph as a .dot file to disk.
void setEnableGlobalMergeSplit(agx::Bool enable)
Enable/disable global merge and split for all objects not having their MergeSplitProperties set.
agx::MergedBodyRef createMergedBody() const
Creates a new, empty, merged body object associated to this merge split handler.
static agxSDK::MergeSplitProperties * getOrCreateProperties(agxCollide::Geometry *geometry)
Creates (or returns already present) merge-split parameters given a geometry.
agx::Bool getEnableMergePair(agx::UInt32 group1, const agx::Name &group2)
static void transferProperties(const agxCollide::Geometry *source, agxCollide::Geometry *destination)
Transfers merge-split properties from source geometry to another geometry instance.
static agx::Bool split(agx::RigidBody *rb)
Split a rigid body that has been merged by a merge split handler.
agx::Bool getEnable() const
void setEnableSplitOnSeparation(agx::Bool enable)
Enable/disable split on separation events from Space.
agx::Bool maySplit(const agx::RigidBody *rb) const
agx::Bool getEnableMerge() const
static agx::UInt findCallbackIndex(agxSDK::MergeSplitAlgorithm::Callback callback)
Maps given callback to an index (0, 1, 2, ...).
agx::Bool getEnableSplit() const
Base class for thresholds/constants/values used in agxSDK::MergeSplitAlgorithm.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Specific thresholds used to split and merge objects given wires.
Interface and placeholder of controllers/helpers for wires.
The base class for a constraint.
agx::ConstraintImplementation * getRep()
Interface class for a cloneable reference counted object.
@ MERGE_SPLIT
AMOR related data.
Structure holding several "normal" rigid bodies.
std::function< void(EdgeInteraction *) > EdgeInteractionVisitor
EdgeInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2, InteractionTag tag, agx::Bool valid=true)
Construct given two rigid bodies and a valid flag.
Representation of a name string.
Base class providing referencing counted objects.
T * as()
Subclass casting.
The rigid body class, combining a geometric model and a frame of reference.
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Implements a Wire model with adaptive resolution.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::ref_ptr< ICloneable > ICloneableRef