AGX Dynamics  2.37.2.0
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
This class is for detecting and handling particle collisions with geometries in the simulation...
A pressure map for a single trimesh.
Definition: PressureAtlas.h:43
Derive from this class to implement a listener for Collision events.
#define AGXOSG_EXPORT
Derive from this class to implement a listener for simulation step events.
Base class for types that want to supply force updates to a PressureAtlas.
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:66
Abstract base class that implements a filter that selects which events should trigger a Listener...
Definition: ExecuteFilter.h:33
A contact between two geometries.
Definition: Contacts.h:270
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
agx::Real TimeStamp
Definition: TimeStamp.h:26
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
ForceType
The type of force to add. Tangential (friction) only, normal only, or both.
const agx::Name & getName() const
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
Generates pressure on a mesh from contacts.
KeepContactPolicy
Defines whether contact should be kept or removed after contact/impact methods returns.
virtual bool match(const agxCollide::GeometryPair &pair) const override
Called once when narrow phase no longer finds overlaps between the two geometries.
virtual bool match(const agxCollide::GeometryContact &contact) const override
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Filter that only accepts contacts where at least on of the bodes in the contact has a particular name...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
A contact point in a contact data.
Definition: Contacts.h:55
agx::Vector< agx::Physics::ParticleGeometryContactInstance > ParticleContactVector
double Real
Definition: Real.h:42
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:42
uint32_t UInt32
Definition: Integer.h:40
agx::RigidBody * getRigidBody()
Definition: Geometry.h:865