AGXDynamics  2.31.1.0
SensorOperations.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 AGXCONTROL_SENSOROPERATIONS_H
18 #define AGXCONTROL_SENSOROPERATIONS_H
19 
20 #include <fstream>
21 #include <agx/Date.h>
22 #include <agx/String.h>
23 #include <agxData/Track.h>
24 #include <agxControl/SensorEvent.h>
25 #include <agxControl/EventSensor.h>
27 #include <agx/Journal.h>
28 
29 /*
30 This file defines some example sensor operations
31 */
32 namespace agxControl
33 {
36  {
37  public:
38  RemoveRigidBody(const agx::Name& name = agx::Name(), bool onlyRemoveEmittedBodies = false);
39 
40  void triggerEvent(const agx::TimeStamp& /*t*/, agxSDK::Simulation * simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor * sensor) override;
41 
43 
44  protected:
45  virtual ~RemoveRigidBody();
46 
47  protected:
49  };
50 
53  {
54  public:
55  RemoveParticles(const agx::Name& name = agx::Name());
56 
57  void triggerParticleEvent(const agx::TimeStamp& /*t*/,
58  agxSDK::Simulation* /*simulation*/,
59  agx::Physics::ParticleGeometryContactInstance contact,
60  agx::Physics::ParticleData& particleData,
61  agx::Physics::GeometryData& /*geometryData*/,
62  agxControl::EventSensor* /*sensor*/) override;
63 
65 
66  protected:
67  virtual ~RemoveParticles();
68 
69  };
70 
73  {
74  public:
75  TagOperation(const agx::Name& name = agx::Name());
76 
77 
78  virtual void triggerEvent(const agx::TimeStamp& /*t*/, agxSDK::Simulation * /*simulation*/, agxCollide::GeometryContact * /*cd*/, agxControl::EventSensor* /*sensor*/) override
79  {
80  // Tag this operation as executed
81  m_isExecuted = true;
82  }
83 
84  virtual void triggerParticleEvent(const agx::TimeStamp& /*t*/,
85  agxSDK::Simulation* /*simulation*/,
86  agx::Physics::ParticleGeometryContactInstance /*contact*/,
87  agx::Physics::ParticleData& /*particleData*/,
88  agx::Physics::GeometryData& /*geometryData*/,
89  agxControl::EventSensor* /*sensor*/) override
90  {
91  m_isExecuted = true;
92  }
93 
95 
96  public:
97  bool isExecuted() { return m_isExecuted; }
98 
99  void setIsExecuted(bool executed) { m_isExecuted = executed; }
100 
101  protected:
103 
104  protected:
105  virtual ~TagOperation();
106 
107  };
108 
111  {
112  private:
113 
114  static agx::HashSet<agx::UInt32> s_coloredParticles;
115  static agx::TimeStamp s_lastTimeStep;
116 
117  public:
118  ColorParticles(const agx::Name& name = agx::Name(), const agx::Vec3& color = agx::Vec3(0.5, 0.5, 0.5), bool mixColors = false);
119 
120  virtual void triggerParticleEvent(const agx::TimeStamp& t,
121  agxSDK::Simulation* simulation,
122  agx::Physics::ParticleGeometryContactInstance contact,
123  agx::Physics::ParticleData& particleData,
124  agx::Physics::GeometryData& geometryData,
125  agxControl::EventSensor* sensor) override;
126 
127  bool getEnableMixColors(){ return m_mixColors; }
128  void setEnableMixColors(bool mixColors){ m_mixColors = mixColors; }
129 
131 
132  public:
133  agx::Vec3& getColor(){ return m_color; }
134 
135  protected:
138 
139  protected:
140  virtual ~ColorParticles();
141 
142  };
143 
146  {
147  public:
148 
149  ParticleContactDumper(const agx::Name& name = agx::Name());
150  ParticleContactDumper(const agx::Name& name, const agx::Name& filepath, agx::UInt32 samplingStride = 1, bool exportOnce = false);
151 
152  void createFileName(const agx::Name& filePath);
153 
154  // This function appends a date stamp at the end of the filename
155  agx::String generateDateStamp();
156 
157  virtual void triggerParticleEvent(const agx::TimeStamp& t,
158  agxSDK::Simulation* /*simulation*/,
159  agx::Physics::ParticleGeometryContactInstance contact,
160  agx::Physics::ParticleData& particleData,
161  agx::Physics::GeometryData& /*geometryData*/,
162  agxControl::EventSensor* /*sensor*/) override;
163 
164  agx::Name& getFilePath(){ return m_filepath; }
165 
166  virtual void update(const agx::TimeStamp& t) override;
167 
168  void postContactHandling(agxSDK::Simulation* simulation, EventSensor* sensor) override;
169 
171 
172  protected:
174  std::ofstream m_outStream;
182 
183  protected:
184  virtual ~ParticleContactDumper();
185 
186  };
187 
188  // Switches the material of the particle in the supplied contact
190  {
191  public:
192 
194  ReplaceParticleMaterialOperation(const agx::Name& name, const agx::Name& materialName);
195 
196  virtual void triggerParticleEvent(const agx::TimeStamp& t,
197  agxSDK::Simulation* simulation,
198  agx::Physics::ParticleGeometryContactInstance contact,
199  agx::Physics::ParticleData& particleData,
200  agx::Physics::GeometryData& geometryData,
201  agxControl::EventSensor* sensor) override;
202 
204 
205  void setMaterialName(const agx::String& material);
206  agx::Name getMaterialName();
207 
209  // Variables
211  protected:
213 
214  protected:
216 
217  };
218 
220  {
221  m_materialName = material;
222  }
223 
225  {
226  return m_materialName;
227  }
228 
229 
234  {
236  friend class RemoveParticles;
237  public:
238 
241  {
243  UNFREEZE_PARTICLES
244  };
245 
246  MakeParticleKinematicOperation(const agx::Name& name = agx::Name(), ParticleFreezeMode mode = FREEZE_PARTILCES);
247 
248  virtual void triggerParticleEvent(const agx::TimeStamp& t,
249  agxSDK::Simulation* simulation,
250  agx::Physics::ParticleGeometryContactInstance contact,
251  agx::Physics::ParticleData& particleData,
252  agx::Physics::GeometryData& geometryData,
253  agxControl::EventSensor* sensor) override;
254 
256 
257  protected:
259 
261  // Variables
263  int m_mode;
264  };
265 
270  {
271  public:
272 
273  SetVelocityOperation(const agx::Name& name = agx::Name());
274  SetVelocityOperation(const agx::Name& name, const agx::Vec3& velocity, const agx::Vec3& angularVelocity, bool setInLocalFrame = false);
275 
276  virtual void triggerParticleEvent(const agx::TimeStamp& t,
277  agxSDK::Simulation* simulation,
278  agx::Physics::ParticleGeometryContactInstance contact,
279  agx::Physics::ParticleData& particleData,
280  agx::Physics::GeometryData& geometryData,
281  agxControl::EventSensor* sensor) override;
282 
283  virtual void triggerEvent(const agx::TimeStamp& t,
284  agxSDK::Simulation * simulation,
286  agxControl::EventSensor* sensor) override;
287 
288  void setVelocity(const agx::Vec3& velocity);
289  const agx::Vec3& getVelocity() const;
290 
291  void setAngularVelocity(const agx::Vec3& angularVelocity);
292  const agx::Vec3& getAngularVelocity() const;
293 
295 
296  protected:
297  virtual ~SetVelocityOperation();
298 
300  // Variables
302  protected:
307  };
308 
310  {
311  m_velocity = velocity;
312  }
313 
315  {
316  return m_velocity;
317  }
318 
320  {
321  m_angularVelocity = angularVelocity;
322  }
323 
325  {
326  return m_angularVelocity;
327  }
328 
333  {
334  public:
335 
337 
338  virtual void triggerParticleEvent(const agx::TimeStamp& t,
339  agxSDK::Simulation* simulation,
340  agx::Physics::ParticleGeometryContactInstance contact,
341  agx::Physics::ParticleData& particleData,
342  agx::Physics::GeometryData& geometryData,
343  agxControl::EventSensor* sensor) override;
344 
345  virtual void triggerEvent(const agx::TimeStamp& t,
346  agxSDK::Simulation * simulation,
348  agxControl::EventSensor* sensor) override;
349 
350  virtual void update(const agx::TimeStamp& t) override;
351 
352  agx::Physics::ParticlePtrVector getParticlesInContact() const;
353 
355 
356  protected:
357  virtual ~StoreParticlesOperation();
358 
359  protected:
361  };
362 
364 
369  {
370  public:
371 
372  typedef std::pair<agx::TimeStamp, agx::Index> TimeParticleIdPair;
374 
375  TeleportToSensorOperation(const agx::Name& name, EventSensor * target, agx::Real teleportTimeDilation = 0, bool cloneTeleportation = false, agx::Frame * sourceoffset = nullptr, agx::Frame * targetoffset = nullptr);
376 
377  void addNotification(EventSensor * sensor) override;
378 
379  void triggerEvent(const agx::TimeStamp& t,
380  agxSDK::Simulation * simulation,
382  agxControl::EventSensor* sensor) override;
383 
384  void triggerParticleEvent(const agx::TimeStamp& t,
385  agxSDK::Simulation* /*simulation*/,
386  agx::Physics::ParticleGeometryContactInstance contact,
387  agx::Physics::ParticleData& particleData,
388  agx::Physics::GeometryData& /*geometryData*/,
389  agxControl::EventSensor* sensor) override;
390 
391  void postContactHandling(agxSDK::Simulation *simulation, EventSensor * sensor) override;
392 
394 
395  protected:
397  void init();
398 
399  void teleportParticles(const agx::TimeStamp& t, agxControl::EventSensor * sensor, agx::Physics::GranularBodySystem * system);
400 
402  // Variables
404  protected:
407  ParticleTeleportQueue m_particleSpawnQueue;
413  };
414 }
415 
416 #endif
agx::Physics::ParticlePtrVector getParticlesInContact() const
void AGXPHYSICS_EXPORT init()
Initialize agx.
This operation can be used to know when a sensor has been activated by a contact. ...
This operations removes all the particles in the contact supplied by the sensor.
agx::HashTable< agx::Index, agx::Bool > m_handledParticleIds
const agx::Vec3 & getAngularVelocity() const
This operation applies a "kinematic state" to particles that collide with the sensor.
A contact between two geometries.
Definition: Contacts.h:270
#define AGXPHYSICS_EXPORT
agx::Physics::ParticlePtrVector m_particlesInContact
virtual void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *, agxCollide::GeometryContact *, agxControl::EventSensor *) override
Triggers the sensor event by passing contact information.
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:63
void setIsExecuted(bool executed)
agx::Real TimeStamp
Definition: TimeStamp.h:26
This is a sensor class that can be attached to an geometry in the simulation.
Definition: EventSensor.h:47
This sensor operation class sets a speed to the object that collides with the sensor, in both linear and angular direction.
const agx::Vec3 & getVelocity() const
This sensor operation class store particle id&#39;s of particles that are in contact with the sensor...
void setMaterialName(const agx::String &material)
agxData::EntityStorageRef m_particleTeleportStorage
ParticleTeleportQueue m_particleSpawnQueue
This sensor operation can teleport contacting particles to a target sensor geometry with arbitrary ti...
void setAngularVelocity(const agx::Vec3 &angularVelocity)
ParticleFreezeMode
Enum describing what mode the operation should be in. If it should freeze or unfreeze particles...
agxControl::EventSensor * m_targetSensor
This file defines a set of operations used internally by the measurement sensor to calculate differen...
Definition: EventSensor.h:33
This operation dumps particle contact information to a file.
#define CALLABLE
Definition: Object.h:77
std::pair< agx::TimeStamp, agx::Index > TimeParticleIdPair
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
#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:206
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
This operation removes the rigid body given by the geometry in the contact supplied by the sensor...
void setEnableMixColors(bool mixColors)
void setVelocity(const agx::Vec3 &velocity)
double Real
Definition: Real.h:42
virtual void triggerParticleEvent(const agx::TimeStamp &, agxSDK::Simulation *, agx::Physics::ParticleGeometryContactInstance, agx::Physics::ParticleData &, agx::Physics::GeometryData &, agxControl::EventSensor *) override
Triggers the sensor event by passing particle contact information.
A specific type of sensor event that triggers a change in the simulation when activated by a contact...
Definition: SensorEvent.h:117
agx::List< TimeParticleIdPair > ParticleTeleportQueue
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::HashSet< agx::UInt32 > m_previousContactingParticleIds
uint32_t UInt32
Definition: Integer.h:40
This operation changes the color of the particles given in the contact.