AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
EventSensor.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXCONTROL_EVENTSENSOR_H
18#define AGXCONTROL_EVENTSENSOR_H
19#include <agx/config.h>
20
23#include <agx/TimeStamp.h>
24#include <agxCollide/Geometry.h>
27#include <agx/HashSet.h>
29#include <map>
32
33namespace agxControl
34{
35
36 class SensorEvent;
37
40
48 {
49 public:
50 typedef agx::Vector < agx::Physics::ParticlePairContactPtr > ParticlePairContactVector;
51 typedef agx::Vector < agxControl::SensorEvent * > SensorEventVector;
52
53 protected:
54 // This is a static list that contains forbidden geometries. And exclusive sensor can mark
55 // geometries as forbidden after they have been handled, which prevents other sensors form detecting them.
56 // The same goes for particles.
59
60 public:
63 {
65 SENSOR_POST_STEP
66 };
67
68 protected:
69
72 /*
73 * This is an internal class handling the geometry contact triggers of the simulation
74 */
92
95
96 /*
97 * This is an internal class handling the geometry contact triggers of the simulation
98 */
100 {
101 public:
102
104
106
109
110 virtual void contactCallback(agx::Physics::ParticleGeometryContactInstance contact,
111 agx::Physics::ParticleData& particleData,
112 agx::Physics::GeometryData& geometryData);
113
114 friend class EventSensor;
115
116 protected:
118
119 protected:
122 };
123
124 public:
125
128
133 EventSensor(int priority);
134
140
146 EventSensor(agxCollide::Geometry* geometry, int priority);
147
151 void addGroup(const agx::Name& group);
153 void removeGroup(const agx::Name& group);
156 bool hasGroup(const agx::Name& group);
158
164 bool addSensorEvent(SensorEvent* sEvent, int priority = 0);
165
171
177
183
188
194
198 void setTriggerFlag(int flag);
199
204
208 void setCollisionMask(int mask);
209
214
219
224
229
234
240 void setEnableBlocker(bool isBlocker);
241
246
252 virtual void preCollide(const agx::TimeStamp& time) override;
253
259 virtual void pre(const agx::TimeStamp& time) override;
260
266 virtual void post(const agx::TimeStamp& time) override;
267
272 virtual void addNotification() override;
273
278 virtual void removeNotification() override;
279
284
285 /*
286 * Returns the particle id:s currently in contact with the sensor geometry
287 */
289
290 /*
291 * Returns the particle id:s whose midpoint is currently _inside_ the sensor geometry
292 */
294
299
300 /*
301 * Returns a vector containing RigidBodies inside the sensor volume
302 */
304
305 /*
306 * Returns the number of particles currently contacting the sensor
307 */
309
310 /*
311 * Returns the number of particle-particle contacts in the sensor
312 */
314
319
324
329
334
339
344
347
349
351
352
356 void registerRemovedParticle( agx::Physics::ParticlePtr particle );
357
358 void registerRemovedBody( agx::RigidBody* body );
359
360 // Dummy method to allow EventSensor to pass makeCallable compilation.
361 void setRealDummyMethod(agx::Real /*inVal*/) { }
363
364 public:
365
366 template <typename T>
368 {
369 public:
370 EventPrioHolder( ): m_priority( 0 ) {}
371 EventPrioHolder( T obj, int priority ) : m_obj( obj ), m_priority( priority ) {}
372 inline int priority() const {
373 return m_priority;
374 }
375 inline operator T () {
376 return m_obj;
377 }
378 inline operator const T () const {
379 return m_obj;
380 }
381 inline operator int () const {
382 return m_priority;
383 }
384 inline T sensorEvent() {
385 return m_obj;
386 }
387 inline const T sensorEvent() const {
388 return m_obj;
389 }
390
391
392 protected:
395 };
396
397 typedef std::map<agx::Uuid, EventPrioHolder<SensorEventRef> > SensorEvents;
399
402
403 protected:
404
405 /*
406 * Placeholder for information regarding the geometry contacts
407 */
409 {
411 :t(tin),cd(cdin)
412 {
413 }
414
417 private:
418 ContactInformation& operator=(const ContactInformation&);
419 };
420
425 {
427 agx::Physics::ParticleGeometryContactInstance contactIn,
428 agx::Physics::ParticleData& particleDataIn,
429 agx::Physics::GeometryData& geometryDataIn)
430 :t(tIn),contact(contactIn), particleData(particleDataIn), geometryData(geometryDataIn)
431 {
432 }
434 agx::Physics::ParticleGeometryContactInstance contact;
435 agx::Physics::ParticleData& particleData;
436 agx::Physics::GeometryData& geometryData;
437 private:
439 };
440
443
444 protected:
445
446 void init();
447
449
451
453
455
457
459
461
463
465
467
469
471
473
476 agx::Physics::ParticleGeometryContactInstance contact,
477 agx::Physics::ParticleData& particleData,
478 agx::Physics::GeometryData& geometryData);
479
481
484 agx::Physics::ParticleGeometryContactInstance contact,
485 agx::Physics::ParticleData& particleData,
486 agx::Physics::GeometryData& geometryData);
487
490 agx::Physics::ParticleGeometryContactInstance contact,
491 agx::Physics::ParticleData& particleData,
492 agx::Physics::GeometryData& geometryData);
493
495 agx::Physics::ParticleGeometryContactInstance contact,
496 agx::Physics::ParticleData& particleData,
497 agx::Physics::GeometryData& geometryData);
498
499 protected:
500
502 virtual ~EventSensor();
503
506
509
512
515
518
522
526
529
532
535
538
546
549
553
557 };
558}
559
560#endif /*AGXMODEL_EVENTSENSOR_H*/
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
A contact between two geometries.
Definition Contacts.h:271
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
virtual KeepContactPolicy impact(const agx::TimeStamp &, agxCollide::GeometryContact *)
Called upon impact event if getFilter() contain IMPACT.
virtual KeepContactPolicy contact(const agx::TimeStamp &, agxCollide::GeometryContact *)
Called upon contact event if getFilter() contain CONTACT.
virtual void separation(const agx::TimeStamp &, agxCollide::GeometryPair &)
Called upon separation event if getFilter() contain SEPARATION.
void setFilter(agxSDK::CollisionGroupFilter *filter)
virtual void contactCallback(agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData)
agxSDK::CollisionGroupFilter * m_filter
const agxSDK::CollisionGroupFilter * getFilter() const
agxSDK::CollisionGroupFilter * getFilter()
This is a sensor class that can be attached to an geometry in the simulation.
Definition EventSensor.h:48
SensorEventVector getSensorEvents()
Returns the SensorEvents currently active in the Sensor in the order of execution priority.
agx::Vector< ParticleContactInformation > ParticleContactQueue
bool contactIsValid(agxCollide::GeometryContact *cd)
void setTriggerFlag(int flag)
Set/get the trigger flag to control when the events will be executed during the time-step of contact ...
agxCollide::Geometry * m_geometry
The coupled geometry of the sensor.
bool addSensorEvent(SensorEvent *sEvent, int priority=0)
Sets a sensor event to the sensor with a priority.
virtual void pre(const agx::TimeStamp &time) override
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
void removeGroup(agx::UInt32 group)
agx::HashSet< agx::UInt32 > m_particlesInsideSensor
Holds a set of the current particle id:s whose midpoint is inside the sensor.
bool wasParticleRemovedBySensor(agx::UInt32 particle)
Check if the particle has been marked as removed by any of the sensor's operations.
agx::UInt32Vector getRemovedParticles()
Get the particles removed by this sensor during the last timestep.
void tryTriggerParticleEventsOnContact(const agx::TimeStamp &t, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData)
GeometryContactQueue m_geomContactQueue
Queues for the contacts.
SensorEvent * getSensorEventFromName(const agx::Name &name)
int m_triggerFlag
Flag for when the events are supposed to be executed during the time-step.
agx::List< EventPrioHolder< SensorEventRef > > SensorEventList
agx::HashSet< agx::UInt32 > m_removedBodies
Holds a set of the current particles and bodies that have been marked as removed by an Operation duri...
void tryTriggerEventsOnContact(const agx::TimeStamp &t, agxCollide::GeometryContact *cd)
bool hasGroup(agx::UInt32 group)
void refreshParticlesInsideSensorData()
void triggerEventsOnContact(const agx::TimeStamp &t, agxCollide::GeometryContact *cd)
void removeGroup(const agx::Name &group)
bool hasOnlyReference()
Checks if the sensor keeps the only reference to its internal contact listener. Used in unittest.
agx::UInt32Vector getContactingParticleIds()
agxCollide::Geometry * getGeometry()
Get the geometry of the sensor.
agx::HashSet< agx::UInt32 > m_particlesInSensor
Holds a set of the current particle id:s that are present in the sensor.
agx::UInt m_numRemovedParticles
virtual void removeNotification() override
This function will execute when the sensor is removed form the simulation.
agx::HashSet< agx::RigidBody * > m_rigidBodiesContactingSensor
Holds pointers to the current rigid bodies (DEM Objects) in the sensor.
void setCollisionMask(int mask)
Set/get the collision mask for the sensor.
virtual void preCollide(const agx::TimeStamp &time) override
Called before collision detection is performed in the simulation Implement this method in the derived...
agx::UInt getNumRemovedBodies() const
std::map< agx::Uuid, EventPrioHolder< SensorEventRef > > SensorEvents
bool particleContactIsValid(const agx::TimeStamp &t, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData)
void executeSensorEvents(const agx::TimeStamp &t)
static agxCollide::GeometryPtrVector g_forbiddenGeometries
Definition EventSensor.h:57
GeometryContactEventListenerRef m_contactListener
Listeners that are coupled with the sensor.
agx::RigidBodyPtrVector getRigidBodiesInsideSensor(bool onlyRigidBodyDEM=false)
virtual void post(const agx::TimeStamp &time) override
Called after a step is taken in the simulation Implement this method in the derived class to get call...
agx::Vector< agx::Physics::ParticlePairContactPtr > ParticlePairContactVector
Definition EventSensor.h:50
ParticleContactQueue m_particleContactQueue
ParticleContactListenerRef m_particleContactListener
agx::Real getNumParticleParticleContactsInSensor()
SensorEvent * getSensorEvent(const agx::Uuid &uuid)
Returns a sensor event with the given uuid if there exists one in the sensor.
void refreshRigidBodiesInsideSensorData()
EventSensor(agxCollide::Geometry *geometry, int priority)
Constructor that takes the geometry to couple the sensor too.
EventSensor(agxCollide::Geometry *geometry)
Constructor that takes the geometry to couple the sensor too.
agx::Real getRemovedBodyMass() const
SensorEventList m_sensorEventList
bool m_isBlocker
True if the sensor should block the contact from other sensors in the scene under the same timestep.
bool containsSensorEvent(SensorEvent *sEvent)
Checks if a sensor event already exists in the sensor.
void triggerParticleEventsOnContact(const agx::TimeStamp &t, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData)
agx::UInt32Vector getParticlesInsideSensor()
bool wasRigidBodyRemovedBySensor(agx::UInt32 rigidBody)
Check if the particle has been marked as removed by any of the sensor's operations.
EventSensor()
Default constructor.
bool m_particleCollision
Flags for doing when there is a collision for a particle or geometry.
agx::HashSet< agx::UInt32 > m_removedParticles
void setGeometry(agxCollide::Geometry *geometry)
Sets the geometry of the sensor.
agx::UInt getNumRemovedParticles() const
void setEnableBlocker(bool isBlocker)
Set the sensor to block the contact from other sensors.
TriggerEventStages
Defines the event execution states when the SensorEvents are executed during the timestep of the dete...
Definition EventSensor.h:63
@ SENSOR_PRE_STEP
Triggered in a PRE solve/integration step.
Definition EventSensor.h:64
EventSensor(int priority)
This constructor takes the priority of the internal contact sensors.
bool hasComputedParticlePairContactsInSensor
Vector that stores particle pair contacts. Will only be computed if the user asks for it (getParticle...
agxCollide::Geometry * getGeometry() const
agx::Real getNumParticlesInSensor() const
bool removeSensorEvent(SensorEvent *sEvent)
Removes a sensor event in the sensor.
int m_collisionMask
Get the collision mask for the sensor.
agx::Vector< ContactInformation > GeometryContactQueue
agx::Vector< agxControl::SensorEvent * > SensorEventVector
Definition EventSensor.h:51
agx::Real getRemovedParticleMass() const
virtual void addNotification() override
This will execute when the sensor is inserted in the simulation.
bool isForbiddenGeometry(agxCollide::Geometry *geom)
Check if the geometry is marked as forbidden by a sensor in this time step.
agx::HashSet< agx::RigidBody * > m_rigidBodiesInsideSensor
Holds pointers to the current rigid bodies (DEM Objects) where the midpoint is INSIDE the sensor.
void updateSensorEvents(const agx::TimeStamp &t)
void addGroup(agx::UInt32 group)
agxSDK::CollisionGroupFilterRef m_filter
The collision group filter coupled with the ContactEventListener.
void signalGeometryContact(const agx::TimeStamp &t, agxCollide::GeometryContact *cd)
bool hasGroup(const agx::Name &group)
agx::Real m_removedParticleMass
void addGroup(const agx::Name &group)
Functions for adding and removing collision groups.
SensorEvents m_sensorEvents
bool isForbiddenParticle(agx::UInt32 particle)
Check if the particle is marked as forbidden by a sensor in this time step.
void signalParticleContact(const agx::TimeStamp &t, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData)
static agx::UInt32Vector g_forbiddenParticles
Definition EventSensor.h:58
agx::Real getTotalRemovedMass() const
ParticlePairContactVector m_particlePairContacts
int m_priority
Priority of the sensor over all the other sensors.
agx::RigidBody * getContactingRigidBody(agxCollide::GeometryContact *cd) const
const ParticlePairContactVector & getParticlePairContactsInSensor()
Returns the current particle-particle contacts in the sensor geometry.
virtual ~EventSensor()
Destructor.
A sensor event is an event triggered when the sensor is activated by a contact.
Definition SensorEvent.h:49
An ExecuteFilter that is used to filter out contacts matching a specified criteria based on Collision...
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.
Derive from this class to implement a listener for simulation step events.
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Definition Name.h:33
This class is for detecting and handling particle collisions with geometries in the simulation.
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition Uuid.h:42
Vector containing 'raw' data.
Definition agx/Vector.h:246
Templated vector class.
Definition agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define CALLABLE
Definition macros.h:72
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
This namespace contains general operation and action classes which can be used to control a agxSDK::S...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition Integer.h:32
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
agx::Real TimeStamp
Definition TimeStamp.h:26
ContactInformation(const agx::TimeStamp tin, agxCollide::GeometryContact *cdin)
agxCollide::GeometryContact * cd
Placeholder for information regarding the particle contacts.
agx::Physics::ParticleGeometryContactInstance contact
ParticleContactInformation(const agx::TimeStamp tIn, agx::Physics::ParticleGeometryContactInstance contactIn, agx::Physics::ParticleData &particleDataIn, agx::Physics::GeometryData &geometryDataIn)