AGX Dynamics  2.38.0.2
PressureFromContacts.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 AGXOSG_PRESSURE_FROM_CONTACTS_H
18 #define AGXOSG_PRESSURE_FROM_CONTACTS_H
19 
20 #include <agxCollide/Trimesh.h>
21 
25 
26 #include <agxOSG/export.h>
28 
29 namespace agxOSG
30 {
31 
32  class PressureAtlas;
33 
35 
36 
41  {
42  public:
44  enum ForceType {
47  TOTAL_FORCE
48  };
49 
51 
59  agx::Real rangeFactor = 2.0e-5,
60  ForceType forceType = TOTAL_FORCE);
61 
62  void setRangeFactor(agx::Real rangeFactor);
63  agx::Real getRangeFactor() const;
64 
71  void addFilter(agxSDK::ExecuteFilter* filter);
72 
73  protected:
74  virtual ~PressureFromContacts();
75 
76  private:
77  AGX_DECLARE_POINTER_TYPES(Gatherer);
78  AGX_DECLARE_POINTER_TYPES(ParticleGatherer);
80  AGX_DECLARE_POINTER_TYPES(ContactFilter);
81 
82  ContactFilterRef m_filter;
83  GathererRef m_gatherer;
84  ParticleGathererRef m_particleGatherer;
85  AdderRef m_adder;
86 
87  private:
88  friend class ParticleGatherer;
89  friend class Gatherer;
90  friend class Adder;
92  ParticleContactVector m_particleContacts;
93  agx::Real m_rangeFactor;
94 
95  };
96 
97 
103  class AGXOSG_EXPORT PressureFromContacts::ContactFilter : public agxSDK::ExecuteFilter
104  {
105  public:
106  ContactFilter(const agxCollide::Trimesh* mesh);
107 
108  virtual bool match(const agxCollide::GeometryContact& contact) const override;
109  virtual bool match(const agxCollide::GeometryPair& geometryPair) const override;
111 
112  void addFilter(agxSDK::ExecuteFilter* filter);
113 
114  protected:
115  virtual ~ContactFilter() {}
116 
117  private:
119  };
120 
121 
122 
128  {
129  public:
130  FilterContactByName(const char* name) : m_name(name)
131  {
132  }
133  virtual bool match(const agxCollide::GeometryContact& contact) const override
134  {
135  return this->match(const_cast<agxCollide::GeometryContact&>(contact).getGeometryPair());
136 
137  }
138  virtual bool match(const agxCollide::GeometryPair& pair) const override
139  {
140  return this->checkName(pair.first) || this->checkName(pair.second);
141  }
143  private:
144  bool checkName(const agxCollide::Geometry* geometry) const
145  {
146  return geometry->getRigidBody() && geometry->getRigidBody()->getName() == m_name;
147  }
148 
149  protected:
150  virtual ~FilterContactByName() {}
151 
152  private:
153  agx::Name m_name;
154  };
155 
156  class AGXOSG_EXPORT PressureFromContacts::Gatherer : public agxSDK::ContactEventListener
157  {
158  public:
159  Gatherer(agxOSG::PressureFromContacts* master);
160 
162  impact(const agx::TimeStamp&, agxCollide::GeometryContact* contact) override;
163 
165  contact(const agx::TimeStamp&, agxCollide::GeometryContact* contact) override;
166 
167  protected:
168  virtual ~Gatherer() {};
169 
170  private:
172  };
173 
175  class AGXOSG_EXPORT PressureFromContacts::ParticleGatherer : public agx::ParticleContactSensor
176  {
177  public:
178  ParticleGatherer(agxOSG::PressureFromContacts* master);
179 
181  virtual void contactCallback(agx::Physics::ParticleGeometryContactInstance contact,
182  agx::Physics::ParticleData& particleData, agx::Physics::GeometryData& geometryData) override;
183 
184  protected:
185  virtual ~ParticleGatherer() {};
186 
187  private:
189  };
190 
191  class AGXOSG_EXPORT PressureFromContacts::Adder : public agxSDK::StepEventListener
192  {
193  public:
194 
196 
197  virtual void post(const agx::TimeStamp& time) override;
198 
199  protected:
200  virtual ~Adder() {}
201 
202  private:
203  void applyPressureFromGeometryContact(agxCollide::GeometryContact* contact);
204  void applyPressureFromPoint(const agxCollide::Trimesh* mesh, agx::AffineMatrix4x4 worldToMesh, agxCollide::ContactPoint point);
205  void applyPressureFromGeometryParticleContact(const agxCollide::Trimesh* mesh, agx::AffineMatrix4x4 worldToMesh, agx::Physics::ParticleGeometryContactInstance point);
206  void applyContactForce(const agx::Vec3& point, agx::UInt32 triangleIndex, agx::Real contactForce);
207 
208 
209  private:
211  agxOSG::PressureAtlas* m_atlas;
213  };
214 
215 }
216 
217 
218 #endif
agxOSG::PressureFromContacts::TANGENTIAL_FORCE
@ TANGENTIAL_FORCE
Definition: PressureFromContacts.h:45
Trimesh.h
agx::Real
double Real
Definition: Real.h:42
agxOSG::PressureFromContacts::~Adder
virtual ~Adder()
Definition: PressureFromContacts.h:200
agxSDK::ExecuteFilter::match
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Definition: ExecuteFilter.h:109
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
agxData::GeometryPair
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:65
ParticleContactSensor.h
agxOSG::FilterContactByName::FilterContactByName
FilterContactByName(const char *name)
Definition: PressureFromContacts.h:130
agx::Vector< agx::Physics::ParticleGeometryContactInstance >
agxOSG::PressureGenerator
Base class for types that want to supply force updates to a PressureAtlas.
Definition: PressureGenerator.h:38
agxOSG::PressureFromContacts::~Gatherer
virtual ~Gatherer()
Definition: PressureFromContacts.h:168
PressureGenerator.h
agx::AffineMatrix4x4T
Matrix class for rigid transformations (translation, rotation).
Definition: AffineMatrix4x4.h:52
agxOSG::FilterContactByName::match
virtual bool match(const agxCollide::GeometryPair &pair) const override
Called once when narrow phase no longer finds overlaps between the two geometries.
Definition: PressureFromContacts.h:138
agxSDK::ExecuteFilter
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:33
agxCollide::ContactPoint
A contact point in a contact data.
Definition: Contacts.h:55
StepEventListener.h
agx::VectorPOD< GeometryContact * >
agx::ParticleContactSensor
This class is for detecting and handling particle collisions with geometries in the simulation.
Definition: ParticleContactSensor.h:42
agxOSG::PressureAtlas
A pressure map for a single trimesh.
Definition: PressureAtlas.h:43
agxOSG::FilterContactByName
Filter that only accepts contacts where at least on of the bodes in the contact has a particular name...
Definition: PressureFromContacts.h:127
agxOSG::FilterContactByName::match
virtual bool match(const agxCollide::GeometryContact &contact) const override
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Definition: PressureFromContacts.h:133
agxOSG::PressureFromContacts::~ParticleGatherer
virtual ~ParticleGatherer()
Definition: PressureFromContacts.h:185
agx::ref_ptr< ContactFilter >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
agxSDK::ContactEventListener::KeepContactPolicy
KeepContactPolicy
Defines whether contact should be kept or removed after contact/impact methods returns.
Definition: ContactEventListener.h:59
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
agxOSG::PressureFromContacts
Generates pressure on a mesh from contacts.
Definition: PressureFromContacts.h:40
agx::Name
Representation of a name string.
Definition: Name.h:32
agxOSG::PressureFromContacts::ParticleContactVector
agx::Vector< agx::Physics::ParticleGeometryContactInstance > ParticleContactVector
Definition: PressureFromContacts.h:50
agxOSG::PressureFromContacts::ForceType
ForceType
The type of force to add. Tangential (friction) only, normal only, or both.
Definition: PressureFromContacts.h:44
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
ContactEventListener.h
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:270
agx::RigidBody::getName
const agx::Name & getName() const
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
export.h
agxCollide::Geometry::getRigidBody
agx::RigidBody * getRigidBody()
Definition: Geometry.h:790
agxOSG::FilterContactByName::~FilterContactByName
virtual ~FilterContactByName()
Definition: PressureFromContacts.h:150
agx::Vec3T< Real >
agxCollide::Trimesh
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:42
agxOSG::PressureFromContacts::~ContactFilter
virtual ~ContactFilter()
Definition: PressureFromContacts.h:115
agxOSG::PressureFromContacts::NORMAL_FORCE
@ NORMAL_FORCE
Definition: PressureFromContacts.h:46
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
AGXOSG_EXPORT
#define AGXOSG_EXPORT
agxSDK::ContactEventListener
Derive from this class to implement a listener for Collision events.
Definition: ContactEventListener.h:44