AGX Dynamics  2.35.0.1
MergedBody.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 #pragma once
18 
19 
20 #include <agx/BitState.h>
23 #include <agx/InternalData.h>
24 
26 
29 
30 #define MERGED_BODY_SERIALIZATION_VERSION_1 49
31 #define MERGED_BODY_SERIALIZATION_VERSION_2 75
32 
33 namespace agxSDK
34 {
35  class Simulation;
36  class MergeSplitHandler;
37 }
38 
39 namespace agxWire
40 {
41  class BodyFixedNode;
42 }
43 
44 namespace agx
45 {
49 
56  {
57  public:
58  // Interactions.
59  AGX_DECLARE_POINTER_TYPES( EdgeInteraction );
60  AGX_DECLARE_POINTER_TYPES( EmptyEdgeInteraction );
61  AGX_DECLARE_POINTER_TYPES( ContactGeneratorEdgeInteraction );
62  AGX_DECLARE_POINTER_TYPES( GeometryContactEdgeInteraction );
63  AGX_DECLARE_POINTER_TYPES( BinaryConstraintEdgeInteraction );
64  AGX_DECLARE_POINTER_TYPES( ParticleParticleInteraction );
65 
69  enum State
70  {
71  INTERACTION_GRAPH_DIRTY = 1 << 0,
72  RESTORED = 1 << 1,
73  READY_FOR_SOLVER = 1 << 2,
74  AUTO_CLEAN_WHEN_EMPTY = 1 << 3
75  };
76 
82  {
86  inline MergedBodyIndex() : index( agx::InvalidIndex ), originalIndex( agx::InvalidIndex ) {}
87 
93  : index( rb ? rb.calculateIndex() : agx::InvalidIndex ), originalIndex( orgRb ? orgRb.calculateIndex() : agx::InvalidIndex ) {}
94 
98  inline agx::Bool isMerged() const { return originalIndex != agx::InvalidIndex && index != originalIndex; }
99 
102  };
103 
104  public:
105  // Listeners and visitors.
107  typedef std::function< void( agx::RigidBody* ) > RigidBodyVisitor;
108  typedef std::function< void( EdgeInteraction* ) > EdgeInteractionVisitor;
109  typedef agx::BitState< State > InternalState;
111 
112  public:
120  static const agx::MergedBody* get( const agx::RigidBody* rb );
121 
129  static agx::MergedBody* get( agx::RigidBody* rb );
130 
136  static const agx::MergedBody* getActive( const agx::RigidBody* rb );
137 
143  static agx::MergedBody* getActive( agx::RigidBody* rb );
144 
149  static agx::Bool isRoot( const agx::RigidBody* rb );
150 
155  static MergedBodyIndex findMergedBodyIndex( agx::Physics::RigidBodyPtr rb );
156 
163  static const agx::RigidBody* filter( const agx::RigidBody* rb );
164  static agx::RigidBody* filter( agx::RigidBody* rb );
165 
171 
179  static agx::MergedBody* get( agx::Constraint* constraint );
180 
188  static const agx::MergedBody* get( const agx::Constraint* constraint );
189 
193  static BinaryConstraintEdgeInteraction* getEdge( const agx::Constraint* constraint );
194 
198  static BinaryConstraintEdgeInteraction* getEdge( const agx::HighLevelConstraintImplementation* constraint );
199 
204  static agx::Bool split( agx::Constraint* constraint );
205 
211 
219 
220  public:
225 
232  virtual MergedBodyRef clone();
233 
237  const agx::Name& getName() const;
238 
243  void setName(const agx::Name& name);
244 
249 
256  agx::Bool add( EdgeInteraction* edge );
257 
264  agx::Bool merge( agx::MergedBody* other, EdgeInteraction* edge );
265 
271  agx::Bool remove( EdgeInteraction* edge );
272 
280 
286  agx::Bool add( Listener* listener );
287 
293  agx::Bool remove( Listener* listener );
294 
301 
305  agx::Bool merged( const agx::RigidBody* rb1, const agx::RigidBody* rb2 ) const;
306 
311 
316 
320  agx::Bool isActive() const;
321 
325  const EdgeInteractionRefContainer* getEdges( const agx::RigidBody* rb1, const agx::RigidBody* rb2 ) const;
326 
331 
343 
348 
349 #ifndef SWIG
356  void traverse( RigidBodyVisitor visitor, agx::Bool includeDisabled = false ) const;
357 
365  void traverse( EdgeInteractionVisitor visitor, agx::Bool includeDisabled = false ) const;
366 
376  void traverse( const agx::RigidBody* rb, EdgeInteractionVisitor visitor, agx::Bool includeDisabled = false ) const;
377 
386  void traverse( const agx::RigidBody* rb, RigidBodyVisitor visitor, agx::Bool includeDisabled = false ) const;
387 #endif
388 
392  const InternalState& getState() const;
393 
397  void debugPrint( const agx::RigidBody* rb ) const;
398 
402  void getDebugRenderColor( agx::Vec3& color ) const;
403 
404  public:
407 
411  virtual void updateVelocities();
412 
417  virtual void storeRelativeTransforms();
418 
422  void postIntegrate();
423 
429  void clearGeneratedInteractions();
431 
432  protected:
436  virtual ~MergedBody() throw();
437 
438  friend class agxSDK::Simulation; // Remove of bodies and constraints.
439  friend class agxCollide::Space; // Remove of geometries from space.
440  friend class agx::RigidBody; // Remove of geometries from bodies.
445  virtual void setSimulation( agxSDK::Simulation* simulation );
446 
450  virtual void onRemove( agx::RigidBody* rb );
451 
455  virtual void onRemove( agx::Constraint* constraint );
456 
460  virtual void onRemove( agxCollide::Geometry* geometry );
461 
465  virtual void preCollide();
466 
470  virtual void preStep();
471 
476  virtual void postStep();
477 
481  virtual void onCleanup();
482 
483  protected:
487  agxSDK::Simulation* getSimulation();
488 
492  const agxSDK::Simulation* getSimulation() const;
493 
498  agx::Bool updateProperties();
499 
500  private:
501  struct PairData : public agx::Referenced
502  {
504 
505  protected:
506  virtual ~PairData() {}
507  };
508  typedef agx::ref_ptr<PairData> PairDataRef;
509 
511  typedef agx::Vector<EdgeInteractionConstRef> EdgeInteractionConstRefContainer;
512  typedef agx::HashVector<Key, PairDataRef> PairInteractionsContainer;
513  typedef PairInteractionsContainer::iterator PairInteractionsIterator;
514  typedef PairInteractionsContainer::const_iterator PairInteractionsConstIterator;
515  typedef agx::Vector<RigidBodyRef> RigidBodyContainer;
516  typedef agx::Vector<ListenerRef> ListenerContainer;
517 
518  private:
520 
524  struct RootBodyData : public agx::Referenced
525  {
526  RootBodyData( agx::MergedBody* mb, agx::StrongInteraction* si ) : rootBody( mb ), strongInteraction( si ) {}
527 
528  MergedBody* rootBody;
529  agx::StrongInteractionRef strongInteraction;
530  };
531  typedef agx::ref_ptr<RootBodyData> RootBodyDataRef;
532 
536  struct AGXPHYSICS_EXPORT MergedData : public agx::Referenced
537  {
538  enum Flag : agx::UInt16
539  {
540  INTEGRATE_POSITIONS = 1 << 0
543  };
544  using Flags = agx::BitState<Flag, agx::UInt16>;
545 
549  MergedData()
550  : otherBodies(), relativeTransform(), mergedBody( nullptr ), id( agx::InvalidIndex ),
551  mergedWithWorldCounter( 0 ), rootBodyData( nullptr ), flags( agx::UInt16( 0 ) )
552  {
553  }
554 
555  agx::RigidBodyPtrVector otherBodies;
556  agx::AffineMatrix4x4 relativeTransform;
557  MergedBody* mergedBody;
558  agx::UInt id;
559  agx::Int32 mergedWithWorldCounter;
560  RootBodyDataRef rootBodyData;
561  Flags flags;
562 
563  protected:
564  virtual ~MergedData() {}
565  };
566  typedef agx::ref_ptr<MergedData> MergedDataRef;
567 
571  struct AGXPHYSICS_EXPORT ConstraintMergedData : public agx::Referenced
572  {
573  ConstraintMergedData()
574  : mergedBody( nullptr ), edge( nullptr ) {}
575 
576  MergedBody* mergedBody;
577  EdgeInteraction* edge;
579  protected:
580  virtual ~ConstraintMergedData() {}
581  };
582  typedef agx::ref_ptr<ConstraintMergedData> ConstraintMergedDataRef;
583 
588  void writeConnectivityGraph( std::ostream& stream ) const;
589 
590  private:
594  template<typename DataT, typename ObjT>
595  static DataT* getMergedData( const ObjT& obj );
596 
600  template<typename DataT, typename ObjT>
601  static DataT* getOrCreateMergedData( ObjT obj );
602 
606  static RootBodyData* getRootBodyData( const agx::RigidBody* rb );
607 
611  static agx::Bool isMerged( const MergedData* data );
612 
613  private:
617  Key createKey( EdgeInteraction* edge ) const;
618 
622  Key createKey( const agx::RigidBody* rb1, const agx::RigidBody* rb2 ) const;
623 
631  MergedData* add( agx::RigidBody* rb, agx::Bool fireOnAddEvent = true );
632 
639  void erase( agx::RigidBody* rb, agx::Bool fireOnRemoveEvent = true );
640 
646  void remove( agx::RigidBody* rb, MergedData* rbData, agx::Bool saveRemovedEdges );
647 
654  agx::Bool remove( EdgeInteraction* edge, agx::Bool saveRemovedEdge );
655 
661  void remove( PairInteractionsIterator it );
662 
666  void fireOnAdd( agx::RigidBody* rb ) const;
667 
671  void fireOnRemove( agx::RigidBody* rb ) const;
672 
676  void handleOnAdd( EdgeInteraction* edge );
677 
681  void handleOnRemove( const EdgeInteractionRefContainer& edges );
682 
686  void handleOnMovedTo( const EdgeInteractionRefContainer& edges, MergedBody* newMergedBody );
687 
691  void updateDynamicsProperties( agx::RigidBody::MotionControl motionControl,
692  const agx::Vec3& centerOfMassPosition,
693  agx::Real totalMass );
694 
699  void commitGeneratedInteractions();
700 
701  private:
702  RigidBodyRef m_rb;
703  PairInteractionsContainer m_pairInteractions;
704  EdgeInteractionRefContainer m_removedEdges;
705  ListenerContainer m_listeners;
706  RigidBodyContainer m_bodies;
707  agxSDK::Simulation* m_simulation;
708  mutable InternalState m_state;
709  agx::Mutex m_mutex;
710  agx::Name m_name;
711  };
712 
716  class AGXPHYSICS_EXPORT MergedBody::Listener : public agx::Referenced
717  {
718  public:
724  virtual ListenerRef clone() = 0;
725 
729  virtual void onAdd( agx::RigidBody* /*rb*/, const agx::MergedBody* /*mergedBody*/ ) const {}
730 
734  virtual void onRemove( agx::RigidBody* /*rb*/, const agx::MergedBody* /*mergedBody*/ ) const {}
735 
739  virtual void onAdded( EdgeInteraction* /*edge*/, const agx::MergedBody* /*mergedBody*/ ) const {}
740 
744  virtual void onRemoved( const MergedBody::EdgeInteractionRefContainer& /*edges*/, const agx::MergedBody* /*mergedBody*/ ) const {}
745 
749  virtual void onMovedFromTo( const MergedBody::EdgeInteractionRefContainer& /*edges*/, const agx::MergedBody* /*fromMergedBody*/, const agx::MergedBody* /*toMergedBody*/ ) const {}
750 
751  protected:
755  virtual ~Listener();
756  };
757 
761  class AGXPHYSICS_EXPORT MergedBody::EdgeInteraction : public agx::Referenced, public agxStream::Serializable
762  {
763  public:
764 #ifndef SWIG
766  {
767  NONE = 0,
768  CONTACT = 1 << 0,
769  CONTACT_GENERATOR = 1 << 1,
770  CONSTRAINT = 1 << 2,
771  BINARY_CONSTRAINT = CONSTRAINT | (1 << 3),
772  PARTICLE_GENERATOR = 1 << 4
773  };
774 #endif
775 
776  public:
781 
786 
791 
796 
797 #ifndef SWIG
802 #endif
803 
804  public:
810 
812 
816  virtual void store( agxStream::OutputArchive& out ) const override;
817 
821  virtual void restore( agxStream::InputArchive& in ) override;
822 
826  virtual void storeLightData( agxStream::StorageStream& str ) const override;
827 
831  virtual void restoreLightData( agxStream::StorageStream& str ) override;
832 
833  protected:
834 #ifndef SWIG
843 #endif
844 
848  virtual ~EdgeInteraction();
849 
854 
855  private:
856  agx::RigidBodyObserver m_bodies[ 2 ];
857  agx::Bool m_hadValidRb[ 2 ];
858  agx::Bool m_valid;
859  agx::Int32 m_tag;
860  };
861 
867  class AGXPHYSICS_EXPORT MergedBody::EmptyEdgeInteraction : public MergedBody::EdgeInteraction
868  {
869  public:
874 
875  public:
877 
881  virtual void storeLightData( agxStream::StorageStream& str ) const override;
882 
886  virtual void restoreLightData( agxStream::StorageStream& str ) override;
887 
888  protected:
893 
898 
902  virtual void generateInteraction( agxSDK::Simulation* /*simulation*/, agxCollide::LocalGeometryContactVector& /*newContacts*/ ) override {}
903  };
904 
909  class AGXPHYSICS_EXPORT MergedBody::ContactGeneratorEdgeInteraction : public MergedBody::EdgeInteraction
910  {
911  public:
916 
917  public:
919 
923  virtual void storeLightData( agxStream::StorageStream& str ) const override;
924 
928  virtual void restoreLightData( agxStream::StorageStream& str ) override;
929 
930  protected:
935 
940 
944  virtual void generateInteraction( agxSDK::Simulation* simulation, agxCollide::LocalGeometryContactVector& newContacts ) override;
945  };
946 
950  class AGXPHYSICS_EXPORT MergedBody::GeometryContactEdgeInteraction : public MergedBody::EdgeInteraction
951  {
952  public:
957  {
958  enum Strength
959  {
962  TANGENT_V_DIRECTION
963  };
964 
965  Point();
967 
974  };
976 
977  public:
983 
993 
998 
1003 
1007  const PointContainer& getPoints() const;
1008 
1009  public:
1011 
1015  virtual void storeLightData( agxStream::StorageStream& str ) const override;
1016 
1020  virtual void restoreLightData( agxStream::StorageStream& str ) override;
1021 
1023 #ifndef SWIG
1028  typedef std::function<agxCollide::Geometry*( agxCollide::Geometry*, agx::RigidBody* )> GeometryUpdateFunction;
1029 
1038  void updateGeometries( GeometryUpdateFunction geometryUpdateFunction );
1039 #endif
1041 
1042  protected:
1046  GeometryContactEdgeInteraction();
1047 
1051  virtual ~GeometryContactEdgeInteraction();
1052 
1056  virtual void generateInteraction( agxSDK::Simulation* simulation, agxCollide::LocalGeometryContactVector& newContacts ) override;
1057 
1058  private:
1059  PointContainer m_points;
1060  agxCollide::GeometryObserver m_geometries[ 2 ];
1061  };
1062 
1066  class AGXPHYSICS_EXPORT MergedBody::BinaryConstraintEdgeInteraction : public MergedBody::EdgeInteraction
1067  {
1068  public:
1074 
1080 
1085 
1090 
1091  public:
1093 
1097  virtual void storeLightData( agxStream::StorageStream& str ) const override;
1098 
1102  virtual void restoreLightData( agxStream::StorageStream& str ) override;
1103 
1104  protected:
1109 
1114 
1118  virtual void generateInteraction( agxSDK::Simulation* simulation, agxCollide::LocalGeometryContactVector& newContacts ) override;
1119 
1120  private:
1122  };
1123 
1127  class AGXPHYSICS_EXPORT MergedBody::ParticleParticleInteraction : public MergedBody::EdgeInteraction
1128  {
1129  public:
1133  ParticleParticleInteraction(agx::RigidBody* substituteBody1, agx::RigidBody* substituteBody2);
1134 
1135  public:
1137 
1141  virtual void storeLightData(agxStream::StorageStream& str) const override;
1142 
1146  virtual void restoreLightData(agxStream::StorageStream& str) override;
1147 
1148  protected:
1153 
1158 
1162  virtual void generateInteraction(agxSDK::Simulation* /*simulation*/, agxCollide::LocalGeometryContactVector& /*newContacts*/) override;
1163  };
1164 
1165  template<typename DataT, typename ObjT>
1166  AGX_FORCE_INLINE DataT* MergedBody::getMergedData( const ObjT& obj )
1167  {
1168  return agx::InternalData::get<DataT>( obj, agx::InternalData::MERGED_BODY );
1169  }
1170 
1171  template<typename DataT, typename ObjT>
1172  AGX_FORCE_INLINE DataT* MergedBody::getOrCreateMergedData( ObjT obj )
1173  {
1174  agxAssert( obj != nullptr );
1175  return agx::InternalData::getOrCreate<DataT>( obj, agx::InternalData::MERGED_BODY );
1176  }
1177 
1179  {
1180  const MergedData* data = getMergedData<MergedData>( rb );
1181  return data != nullptr ? data->mergedBody : nullptr;
1182  }
1183 
1185  {
1186  MergedData* data = getMergedData<MergedData>( rb );
1187  return data != nullptr ? data->mergedBody : nullptr;
1188  }
1189 
1191  {
1192  const MergedBody* mb = MergedBody::get( rb );
1193  return mb != nullptr && mb->isActive() ? mb : nullptr;
1194  }
1195 
1197  {
1198  MergedBody* mb = MergedBody::get( rb );
1199  return mb != nullptr && mb->isActive() ? mb : nullptr;
1200  }
1201 
1202  inline Bool MergedBody::isRoot( const RigidBody* rb )
1203  {
1204  return rb != nullptr &&
1205  rb->getEntity().state().mergedRootBody();
1206  }
1207 
1209  {
1210  if ( !rb )
1211  return MergedBodyIndex();
1212  const MergedBody* root = getActive( rb.model() );
1213  return root != nullptr ? MergedBodyIndex( root->getRigidBody()->getEntity(), rb ) : MergedBodyIndex( rb, rb );
1214  }
1215 
1217  {
1218  const MergedBody* root = getActive( rb );
1219  return root != nullptr ? root->getRigidBody() : rb;
1220  }
1221 
1223  {
1224  MergedBody* root = getActive( rb );
1225  return root != nullptr ? root->getRigidBody() : rb;
1226  }
1227 
1228  AGX_FORCE_INLINE Bool MergedBody::isMerged( const MergedData* data )
1229  {
1230  return data != nullptr && data->mergedBody != nullptr;
1231  }
1232 
1234  {
1235  return m_simulation != nullptr && m_state.Is( READY_FOR_SOLVER );
1236  }
1237 
1238  AGX_FORCE_INLINE MergedBody::RootBodyData* MergedBody::getRootBodyData( const RigidBody* rb )
1239  {
1240  MergedData* data = getMergedData<MergedData>( rb );
1241  return data != nullptr ? data->rootBodyData : nullptr;
1242  }
1243 
1245  inline Bool MergedBody::EdgeInteraction::isTagged(InteractionTag tag) const
1246  {
1247  return ( m_tag & (Int32)tag ) != 0;
1248  }
1250 }
1251 
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Base class for a merge split algorithm handling a set of merged bodies.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:52
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
The body fixed node is attached to a body at a given offset.
The base class for a constraint.
Definition: Constraint.h:89
@ MERGED_BODY
Merged states, neighbors etc.
Definition: InternalData.h:42
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:56
void setEnableAutomaticCleanupWhenEmpty(agx::Bool enable)
If true, this merged body will remove itself from the simulation and clear all internal states when i...
MergedBody()
Construct merged body, default containing a root rigid body.
agx::Bool add(EdgeInteraction *edge)
Add an edge interaction defining a base interaction between one or two rigid bodies that will be cons...
agx::UInt getNumPairs() const
void setName(const agx::Name &name)
Assign new name to this MergedBOdy Default: "".
virtual void generateInteraction(agxSDK::Simulation *, agxCollide::LocalGeometryContactVector &) override
Does nothing.
Definition: MergedBody.h:902
virtual void generateInteraction(agxSDK::Simulation *simulation, agxCollide::LocalGeometryContactVector &newContacts)=0
Generate interaction or do nothing.
virtual ~EmptyEdgeInteraction()
Reference counted object, protected destructor.
agx::Bool remove(Listener *listener)
Remove listener from this merged body.
agx::Bool remove(EdgeInteraction *edge)
Remove an edge interaction from this merged body.
virtual void onAdded(EdgeInteraction *, const agx::MergedBody *) const
Called when an edge is added to the merged body.
Definition: MergedBody.h:739
ContactGeneratorEdgeInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2)
Construct given two rigid bodies.
virtual void storeLightData(agxStream::StorageStream &str) const override
Store non-structural data to stream.
agx::Bool isTagged(InteractionTag tag) const
EmptyEdgeInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2)
Construct given two rigid bodies.
virtual ~ParticleParticleInteraction()
Reference counted object, protected destructor.
static agx::MergedBody * get(agx::Constraint *constraint)
This method returns a merged body if the constraint has been involved in it, e.g.,...
static BinaryConstraintEdgeInteraction * getEdge(const agx::Constraint *constraint)
agx::Bool isActive() const
Definition: MergedBody.h:1233
std::function< void(EdgeInteraction *) > EdgeInteractionVisitor
Definition: MergedBody.h:108
agx::Bool getValid() const
static agx::Bool split(agx::Constraint *constraint)
Removes the edge defined by the constraint from the merged body, if any.
static const agx::MergedBody * getActive(const agx::RigidBody *rb)
This method returns an agx::MergedBody that is active and in a simulation.
Definition: MergedBody.h:1190
agx::Bool add(Listener *listener)
Add listener to receive callbacks during certain events.
virtual ~ContactGeneratorEdgeInteraction()
Reference counted object, protected destructor.
agx::BitState< State > InternalState
Definition: MergedBody.h:109
static agx::Bool split(agx::HighLevelConstraintImplementation *constraint)
Removes the edge defined by the constraint from the merged body, if any.
virtual void onAdd(agx::RigidBody *, const agx::MergedBody *) const
Called when a body is added to the merged body.
Definition: MergedBody.h:729
virtual void store(agxStream::OutputArchive &out) const override
Stores the two bodies and the construction state.
static agx::Bool split(agx::RigidBody *rb)
Split rigid body if merged.
agxCollide::Geometry * getGeometry2() const
static agx::Bool shouldIntegratePosition(const agx::RigidBody *rb)
GeometryContactEdgeInteraction(agx::Physics::GeometryContactPtr gcPtr)
Construct given a geometry contact data.
virtual void restoreLightData(agxStream::StorageStream &str) override
Restore non-structural data from stream.
virtual void onRemove(agx::RigidBody *, const agx::MergedBody *) const
Called when a body is removed from the merged body.
Definition: MergedBody.h:734
virtual void onMovedFromTo(const MergedBody::EdgeInteractionRefContainer &, const agx::MergedBody *, const agx::MergedBody *) const
Called when the edges between two bodies are moved from one merged body to another.
Definition: MergedBody.h:749
std::function< void(agx::RigidBody *) > RigidBodyVisitor
Definition: MergedBody.h:107
static const agx::RigidBody * filter(const agx::RigidBody *rb)
Filters rb and returns the merged rigid body if rb is part of one.
Definition: MergedBody.h:1216
agx::Bool remove(agx::RigidBody *rb)
Split/Remove a rigid body from this merged body.
const agx::HighLevelConstraintImplementation * getConstraint() const
ParticleParticleInteraction()
Default constructor used by serialization.
virtual void generateInteraction(agxSDK::Simulation *simulation, agxCollide::LocalGeometryContactVector &newContacts) override
Checks for contacts between the bodies and adds them.
static agx::Bool isRoot(const agx::RigidBody *rb)
Definition: MergedBody.h:1202
const agx::RigidBodyPtrVector * getNeighbors(const agx::RigidBody *rb) const
const PointContainer & getPoints() const
virtual void onRemoved(const MergedBody::EdgeInteractionRefContainer &, const agx::MergedBody *) const
Called when an edge is removed from the merged body.
Definition: MergedBody.h:744
ContactGeneratorEdgeInteraction()
Default constructor used by serialization.
BinaryConstraintEdgeInteraction(agx::Constraint *constraint)
Construct given a one or two body constraint.
virtual ~BinaryConstraintEdgeInteraction()
Reference counted object, protected destructor.
void traverse(EdgeInteractionVisitor visitor, agx::Bool includeDisabled=false) const
Traverse the internal interaction graph and receive callback for each edge interaction.
agx::HighLevelConstraintImplementation * getConstraint()
void traverse(RigidBodyVisitor visitor, agx::Bool includeDisabled=false) const
Traverse the internal interaction graph and receive callback for all rigid bodies (unique).
static const agx::MergedBody * get(const agx::RigidBody *rb)
This method returns an agx::MergedBody if rb has been added to one.
Definition: MergedBody.h:1178
EdgeInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2, InteractionTag tag, agx::Bool valid=true)
Construct given two rigid bodies and a valid flag.
BinaryConstraintEdgeInteraction()
Default constructor used by serialization.
static MergedBodyIndex findMergedBodyIndex(agx::Physics::RigidBodyPtr rb)
Similar to filter( const agx::RigidBody* rb ).
Definition: MergedBody.h:1208
void setBodies(agx::RigidBody *rb1, agx::RigidBody *rb2)
Assign bodies during restore.
GeometryContactEdgeInteraction()
Default constructor used by serialization.
ParticleParticleInteraction(agx::RigidBody *substituteBody1, agx::RigidBody *substituteBody2)
Construct given two rigid bodies.
agxCollide::Geometry * getGeometry1() const
void debugPrint(const agx::RigidBody *rb) const
Debug prints (cout) interactions to rb.
const InternalState & getState() const
static const agx::MergedBody * get(const agx::Constraint *constraint)
This method returns a merged body if the constraint has been involved in it, e.g.,...
GeometryContactEdgeInteraction(agxCollide::Geometry *geometry1, agx::RigidBody *rb1, agxCollide::Geometry *geometry2, agx::RigidBody *rb2)
Construct given two geometries.
void getDebugRenderColor(agx::Vec3 &color) const
Color of this merged body used for debug rendering.
agx::Bool getEnableAutomaticCleanupWhenEmpty() const
virtual ~EdgeInteraction()
Reference counted object, protected destructor.
State
Internal state of this merged body.
Definition: MergedBody.h:70
virtual void restore(agxStream::InputArchive &in) override
Restores the two bodies and the construction state.
EmptyEdgeInteraction()
Default constructor used by serialization.
agx::Bool containsDeletedBodies() const
static BinaryConstraintEdgeInteraction * getEdge(const agx::HighLevelConstraintImplementation *constraint)
virtual ~Listener()
Reference counted object, protected destructor.
const EdgeInteractionRefContainer * getEdges(const agx::RigidBody *rb1, const agx::RigidBody *rb2) const
agx::Vector< EdgeInteractionRef > EdgeInteractionRefContainer
Definition: MergedBody.h:110
agx::Bool merge(agx::MergedBody *other, EdgeInteraction *edge)
Merges this with other and clears other.
virtual MergedBodyRef clone()
Creates an empty clone of this merged body where each object that supports cloning also are cloned.
agx::RigidBody * getRigidBody2() const
agx::MergedBodyRefVector splitIslands()
Splits into islands.
void traverse(const agx::RigidBody *rb, EdgeInteractionVisitor visitor, agx::Bool includeDisabled=false) const
Traverse the internal interaction graph and receive callback for each edge interaction where rb is pa...
agx::VectorPOD< Point > PointContainer
Definition: MergedBody.h:975
agx::Bool merged(const agx::RigidBody *rb1, const agx::RigidBody *rb2) const
agx::Bool isEmpty() const
agx::RigidBody * getRigidBody() const
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(MergedBody::EdgeInteraction)
BinaryConstraintEdgeInteraction(agx::HighLevelConstraintImplementation *constraint)
Construct given constraint implementation of a binary constraint.
virtual ListenerRef clone()=0
This listener will be cloned when e.g., splitIslands is used.
void traverse(const agx::RigidBody *rb, RigidBodyVisitor visitor, agx::Bool includeDisabled=false) const
Traverse neighboring bodies to rb.
const agx::Name & getName() const
agx::RigidBody * getRigidBody1() const
Representation of a name string.
Definition: Name.h:33
Pointer to a entity instance of type Physics.ContactMaterial.
Pointer to a entity instance of type Physics.ContactPoint.
A geometry contact hold contact information between two geometries.
Pointer to a entity instance of type Physics.RigidBody.
AGXPHYSICS_EXPORT agx::RigidBodyState & state()
AGXPHYSICS_EXPORT agx::RigidBody *& model()
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
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:66
agx::Physics::RigidBodyPtr getEntity() const
Internal method.
Definition: RigidBody.h:1454
Base class for a strong interaction concept where there interaction is defined in the mass matrix par...
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:32
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::observer_ptr< Geometry > GeometryObserver
Definition: Geometry.h:78
agx::Vector< LocalGeometryContact > LocalGeometryContactVector
Flags
Flags for specifying what is enabled in the debug rendering system.
Definition: RenderManager.h:58
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:40
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition: Integer.h:39
int32_t Int32
Definition: Integer.h:45
agx::SetVector< agx::MergedBodyRef > MergedBodyRefSetVector
Definition: MergedBody.h:48
std::mutex Mutex
Definition: Referenced.h:93
bool Bool
Definition: Integer.h:48
agx::ref_ptr< RigidBody > RigidBodyRef
Definition: RigidBody.h:47
AGXCORE_EXPORT Component * root()
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Object with index of merged body and the original index of a merged object.
Definition: MergedBody.h:82
MergedBodyIndex(agx::Physics::RigidBodyPtr rb, agx::Physics::RigidBodyPtr orgRb)
Construct given object associated to index, and an original object associated to originalIndex.
Definition: MergedBody.h:92
agx::Bool isMerged() const
Definition: MergedBody.h:98
MergedBodyIndex()
Default constructor initializes both indices to Invalid Index.
Definition: MergedBody.h:86
Contact point data store in first rigid body local frame.
Definition: MergedBody.h:957
Point(agx::Physics::ContactPointPtr pointPtr, agx::Physics::ContactMaterialPtr contactMaterial, const agx::AffineMatrix4x4 &toLocal, const agx::RigidBody *rb1, const agx::RigidBody *rb2)