AGX Dynamics  2.35.0.1
PressureFromContacts.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, is 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);
64 
72 
73  protected:
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:
107 
108  virtual bool match(const agxCollide::GeometryContact& contact) const override;
109  virtual bool match(const agxCollide::GeometryPair& geometryPair) const override;
111 
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:
160 
163 
166 
167  protected:
168  virtual ~Gatherer() {};
169 
170  private:
172  };
173 
175  class AGXOSG_EXPORT PressureFromContacts::ParticleGatherer : public agx::ParticleContactSensor
176  {
177  public:
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
A contact point in a contact data.
Definition: Contacts.h:56
A contact between two geometries.
Definition: Contacts.h:270
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
agx::RigidBody * getRigidBody()
Definition: Geometry.h:850
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:43
Filter that only accepts contacts where at least on of the bodes in the contact has a particular name...
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...
A pressure map for a single trimesh.
Definition: PressureAtlas.h:44
Generates pressure on a mesh from contacts.
void setRangeFactor(agx::Real rangeFactor)
ContactFilter(const agxCollide::Trimesh *mesh)
agx::Real getRangeFactor() const
virtual agxSDK::ContactEventListener::KeepContactPolicy impact(const agx::TimeStamp &, agxCollide::GeometryContact *contact) override
Gatherer(agxOSG::PressureFromContacts *master)
ParticleGatherer(agxOSG::PressureFromContacts *master)
virtual bool match(const agxCollide::GeometryContact &contact) const override
virtual void post(const agx::TimeStamp &time) override
PressureFromContacts(agxSDK::Simulation *simulation, agxOSG::PressureAtlas *atlas, agx::Real rangeFactor=2.0e-5, ForceType forceType=TOTAL_FORCE)
virtual void contactCallback(agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData) override
Not working right now.
agx::Vector< agx::Physics::ParticleGeometryContactInstance > ParticleContactVector
ForceType
The type of force to add. Tangential (friction) only, normal only, or both.
virtual bool match(const agxCollide::GeometryPair &geometryPair) const override
virtual agxSDK::ContactEventListener::KeepContactPolicy contact(const agx::TimeStamp &, agxCollide::GeometryContact *contact) override
void addFilter(agxSDK::ExecuteFilter *filter)
Add a contact filter.
Adder(agxOSG::PressureFromContacts *master, agxOSG::PressureAtlas *atlas, PressureFromContacts::ForceType forceType)
Base class for types that want to supply force updates to a PressureAtlas.
Derive from this class to implement a listener for Collision events.
KeepContactPolicy
Defines whether contact should be kept or removed after contact/impact methods returns.
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:35
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Derive from this class to implement a listener for simulation step events.
Representation of a name string.
Definition: Name.h:33
This class is for detecting and handling particle collisions with geometries in the simulation.
const agx::Name & getName() const
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:66
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
uint32_t UInt32
Definition: Integer.h:40
double Real
Definition: Real.h:42
agx::Real TimeStamp
Definition: TimeStamp.h:26