AGX Dynamics  2.38.0.2
RecordParticlesOperations.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 AGXCONTROL_RECORDPARTICLESOPERATIONS_H
18 #define AGXCONTROL_RECORDPARTICLESOPERATIONS_H
19 
20 #include <agx/String.h>
21 #include <agxControl/EventSensor.h>
22 #include <agx/Journal.h>
23 
24 #ifndef SWIG
25 namespace agx
26 {
27  class Uuid;
28 }
29 #endif
30 
31 /*
32 This file contains SensorOperation classes that gives the sensor functionality to record colliding particles to separate journals.
33 The operations can be used for recording continuous flow of particles in a sensor or store single frame snapshots/states. The
34 created journals can later be loaded into the simulation by other operations.
35 This creates an easy way to create and load different types of precomputed particle states into other simulations.
36 */
37 namespace agxControl
38 {
39 
46  {
47  public:
48  BaseRecordParticleJournalOperation(const agx::Name& name, const agx::String& journalPath, agx::Frame * sourceOffset = nullptr);
49 
50  virtual void update(const agx::TimeStamp&) override;
51 
52  virtual void addNotification(EventSensor * sensor) override;
53 
54  virtual void triggerEvent(const agx::TimeStamp&,
57  agxControl::EventSensor*) override {}
58 
59  virtual void triggerParticleEvent(const agx::TimeStamp& ,
61  agx::Physics::ParticleGeometryContactInstance ,
62  agx::Physics::ParticleData& ,
63  agx::Physics::GeometryData& ,
64  agxControl::EventSensor*) override {}
65 
66  virtual void postContactHandling(agxSDK::Simulation *, EventSensor *) override {}
67 
69 
70  protected:
73 
74  void attachJournal(agxSDK::Simulation *simulation);
75 
76  void detachJournal();
77 
78  void initDataStructure(agxSDK::Simulation * simulation);
79 
80  void copyContactingParticlesToStorage(EventSensor * sensor);
81 
83  // Variables
85  protected:
92  };
93 
94 
95 
100  {
101  public:
102  RecordParticleJournalOperation(const agx::Name& name, const agx::String& journalPath, bool shouldAttachJournalOnContact = true, agx::Frame * sourceOffset = nullptr);
103 
104  void addNotification(EventSensor * sensor) override;
105 
106  void triggerEvent(const agx::TimeStamp& /*t*/,
107  agxSDK::Simulation * /*simulation*/,
109  agxControl::EventSensor* /*sensor*/) override;
110 
111  void triggerParticleEvent(const agx::TimeStamp& /*t*/,
112  agxSDK::Simulation* simulation,
113  agx::Physics::ParticleGeometryContactInstance /*contact*/,
114  agx::Physics::ParticleData& /*particleData*/,
115  agx::Physics::GeometryData& /*geometryData*/,
116  agxControl::EventSensor* /*sensor*/) override;
117 
118  void postContactHandling(agxSDK::Simulation *simulation, EventSensor * sensor) override;
119 
121 
122  protected:
125 
127  // Variables
129  protected:
131  };
132 
133 
134 
139  {
140  public:
141  RecordParticleShapshotJournalOperation(const agx::Name& name, const agx::String& journalPath, agx::Real snapShotTime = 0, agx::Frame * sourceOffset = nullptr);
142 
143  virtual void update(const agx::TimeStamp& /*t*/) override;
144 
145  virtual void addNotification(EventSensor * sensor) override;
146 
147  void triggerEvent(const agx::TimeStamp& /*t*/,
148  agxSDK::Simulation * /*simulation*/,
150  agxControl::EventSensor* /*sensor*/) override;
151 
152  void triggerParticleEvent(const agx::TimeStamp& /*t*/,
153  agxSDK::Simulation* simulation,
154  agx::Physics::ParticleGeometryContactInstance /*contact*/,
155  agx::Physics::ParticleData& /*particleData*/,
156  agx::Physics::GeometryData& /*geometryData*/,
157  agxControl::EventSensor* /*sensor*/) override;
158 
159  void postContactHandling(agxSDK::Simulation *simulation, EventSensor * sensor) override;
160 
162 
163  protected:
166 
168  // Variables
170  protected:
173  };
174 
175 
176 
182  {
183  public:
185  const agx::String& journalPath,
186  agx::Real startAfter = 0,
187  agx::Material* startMaterial = nullptr,
188  agx::Frame * targetOffsetFrame = nullptr);
189 
190  void addNotification(EventSensor * sensor) override;
191 
192  void triggerEvent(const agx::TimeStamp& /*t*/,
193  agxSDK::Simulation * /*simulation*/,
195  agxControl::EventSensor* /*sensor*/) override;
196 
197  void triggerParticleEvent(const agx::TimeStamp& /*t*/,
198  agxSDK::Simulation* /*simulation*/,
199  agx::Physics::ParticleGeometryContactInstance /*contact*/,
200  agx::Physics::ParticleData& /*particleData*/,
201  agx::Physics::GeometryData& /*geometryData*/,
202  agxControl::EventSensor* /*sensor*/) override;
203 
204  void postContactHandling(agxSDK::Simulation * simulation, agxControl::EventSensor *sensor) override;
205 
207 
208  protected:
210  virtual ~LoadParticleJournalOperation();
211 
212  void loadAndAttachJournal(EventSensor * sensor);
213 
214  bool loadParticleStorageFromSimulation(EventSensor * sensor);
215 
216  void loadParticlesFromStorage(EventSensor * sensor);
217 
219  // Variables
221  protected:
229  };
230 
231 
232 
237  {
238  public:
240  const agx::String& filepath,
241  agx::Real snapShotTime,
242  agx::Frame * sourceOffset = nullptr );
243 
244  virtual void update( const agx::TimeStamp& ) override;
245 
246  virtual void addNotification( EventSensor * sensor ) override;
247 
248  virtual void triggerEvent( const agx::TimeStamp&,
251  agxControl::EventSensor* ) override {}
252 
253  virtual void triggerParticleEvent( const agx::TimeStamp&,
255  agx::Physics::ParticleGeometryContactInstance,
256  agx::Physics::ParticleData&,
257  agx::Physics::GeometryData&,
258  agxControl::EventSensor* ) override {}
259 
260  void writeParticlesToFile( EventSensor * sensor );
261 
262  virtual void postContactHandling( agxSDK::Simulation *, EventSensor * ) override;
263 
265 
266  protected:
269 
271  // Variables
273  protected:
278  };
279 
280 
281 
286  {
287  public:
289  const agx::String& filePath,
290  agx::Real startAfter = 0,
291  agx::Material* startMaterial = nullptr,
292  agx::Frame * targetOffsetFrame = nullptr );
293 
294  void addNotification( EventSensor * sensor ) override;
295 
296  void triggerEvent( const agx::TimeStamp& /*t*/,
297  agxSDK::Simulation * /*simulation*/,
299  agxControl::EventSensor* /*sensor*/ ) override {}
300 
302  agxSDK::Simulation* /*simulation*/,
303  agx::Physics::ParticleGeometryContactInstance /*contact*/,
304  agx::Physics::ParticleData& /*particleData*/,
305  agx::Physics::GeometryData& /*geometryData*/,
306  agxControl::EventSensor* /*sensor*/ ) override {}
307 
308  void postContactHandling( agxSDK::Simulation * simulation, agxControl::EventSensor *sensor ) override;
309 
311 
312  protected:
314  virtual ~LoadParticleAGXFileOperation();
315 
316  void loadParticlesFromFile( EventSensor * sensor );
317 
319  // Variables
321  protected:
327  };
328 
329 }
330 #endif /*SENSOROPERATIONS_H_*/
agxControl::LoadParticleAGXFileOperation::m_targetOffsetFrame
agx::FrameRef m_targetOffsetFrame
Definition: RecordParticlesOperations.h:325
agxControl::RecordParticleJournalOperation::m_shouldAttachJournalOnContact
bool m_shouldAttachJournalOnContact
Definition: RecordParticlesOperations.h:130
agxControl::LoadParticleAGXFileOperation::m_startAfter
agx::Real m_startAfter
Definition: RecordParticlesOperations.h:323
agxControl::LoadParticleJournalOperation
Loads particle data from an external journal file into a simulation relative to the coupled sensor ob...
Definition: RecordParticlesOperations.h:181
agx::Real
double Real
Definition: Real.h:42
agxControl::LoadParticleAGXFileOperation::m_hasLoadedJournal
bool m_hasLoadedJournal
Definition: RecordParticlesOperations.h:326
agxControl::WriteParticleDataToAGXOperation::m_snapShotTime
agx::Real m_snapShotTime
Definition: RecordParticlesOperations.h:275
agxControl
This namespace contains general operation and action classes which can be used to control a agxSDK::S...
agxControl::BaseRecordParticleJournalOperation::triggerParticleEvent
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.
Definition: RecordParticlesOperations.h:59
agxControl::SensorOperation
A specific type of sensor event that triggers a change in the simulation when activated by a contact.
Definition: SensorEvent.h:117
agxControl::BaseRecordParticleJournalOperation::postContactHandling
virtual void postContactHandling(agxSDK::Simulation *, EventSensor *) override
Post function that will be triggered for the event after all the contacts have handled in the operati...
Definition: RecordParticlesOperations.h:66
agxControl::BaseRecordParticleJournalOperation::m_particleStorage
agxData::EntityStorageRef m_particleStorage
Definition: RecordParticlesOperations.h:89
agxControl::WriteParticleDataToAGXOperation::m_hasTakenSnapshot
bool m_hasTakenSnapshot
Definition: RecordParticlesOperations.h:277
agxControl::WriteParticleDataToAGXOperation::m_filePath
agx::String m_filePath
Definition: RecordParticlesOperations.h:274
agxControl::LoadParticleJournalOperation::m_journal
agx::JournalRef m_journal
Definition: RecordParticlesOperations.h:222
agxControl::LoadParticleJournalOperation::m_journalPath
agx::String m_journalPath
Definition: RecordParticlesOperations.h:223
agxControl::LoadParticleJournalOperation::m_particleStorage
agxData::EntityStorageRef m_particleStorage
Definition: RecordParticlesOperations.h:224
AGXSTREAM_DECLARE_SERIALIZABLE
#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:207
agxControl::RecordParticleShapshotJournalOperation::m_hasTakenSnapshot
bool m_hasTakenSnapshot
Definition: RecordParticlesOperations.h:172
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxControl::LoadParticleAGXFileOperation::m_startMaterial
agx::Material * m_startMaterial
Definition: RecordParticlesOperations.h:324
agxControl::RecordParticleShapshotJournalOperation::m_snapShotTime
agx::Real m_snapShotTime
Definition: RecordParticlesOperations.h:171
agxControl::LoadParticleAGXFileOperation::m_filePath
agx::String m_filePath
Definition: RecordParticlesOperations.h:322
agxControl::EventSensor
This is a sensor class that can be attached to an geometry in the simulation.
Definition: EventSensor.h:47
agx::ref_ptr< Journal >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxControl::BaseRecordParticleJournalOperation::m_journal
agx::JournalRef m_journal
Definition: RecordParticlesOperations.h:87
Journal.h
agxControl::BaseRecordParticleJournalOperation::triggerEvent
virtual void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *, agxCollide::GeometryContact *, agxControl::EventSensor *) override
Triggers the sensor event by passing contact information.
Definition: RecordParticlesOperations.h:54
agxControl::RecordParticleJournalOperation
Class that stores particle data from a continuous flow in the coupled sensor to a separate specified ...
Definition: RecordParticlesOperations.h:99
agxControl::WriteParticleDataToAGXOperation::triggerParticleEvent
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.
Definition: RecordParticlesOperations.h:253
agxControl::LoadParticleAGXFileOperation::triggerParticleEvent
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.
Definition: RecordParticlesOperations.h:301
agxControl::LoadParticleAGXFileOperation
Loads particle data from an external agx file into a simulation relative to the coupled sensor object...
Definition: RecordParticlesOperations.h:285
agxControl::WriteParticleDataToAGXOperation
Class that stores particles in contact with the sensor to an binary .agx file.
Definition: RecordParticlesOperations.h:236
agx::Name
Representation of a name string.
Definition: Name.h:32
agxControl::RecordParticleShapshotJournalOperation
Class that stores a single frame of the current particle configuration in the coupled sensor.
Definition: RecordParticlesOperations.h:138
agx::HashSet< agx::UInt32 >
agxControl::BaseRecordParticleJournalOperation
Base virtual class for storing particle states to an external journal file.
Definition: RecordParticlesOperations.h:45
agxControl::BaseRecordParticleJournalOperation::m_journalUuid
agx::Uuid m_journalUuid
Definition: RecordParticlesOperations.h:86
agxControl::LoadParticleJournalOperation::m_hasLoadedJournal
bool m_hasLoadedJournal
Definition: RecordParticlesOperations.h:225
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:270
agxControl::BaseRecordParticleJournalOperation::m_journalPath
agx::String m_journalPath
Definition: RecordParticlesOperations.h:88
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agxControl::WriteParticleDataToAGXOperation::m_sourceOffsetFrame
agx::FrameRef m_sourceOffsetFrame
Definition: RecordParticlesOperations.h:276
String.h
agx::AgXString< std::string >
agxControl::LoadParticleJournalOperation::m_startAfter
agx::Real m_startAfter
Definition: RecordParticlesOperations.h:226
agxControl::WriteParticleDataToAGXOperation::triggerEvent
virtual void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *, agxCollide::GeometryContact *, agxControl::EventSensor *) override
Triggers the sensor event by passing contact information.
Definition: RecordParticlesOperations.h:248
agx::Material
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
agxControl::BaseRecordParticleJournalOperation::m_previousContactingParticleIds
agx::HashSet< agx::UInt32 > m_previousContactingParticleIds
Definition: RecordParticlesOperations.h:90
agx::Uuid
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
agxControl::BaseRecordParticleJournalOperation::m_sourceOffsetFrame
agx::FrameRef m_sourceOffsetFrame
Definition: RecordParticlesOperations.h:91
EventSensor.h
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agxControl::LoadParticleAGXFileOperation::triggerEvent
void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *, agxCollide::GeometryContact *, agxControl::EventSensor *) override
Triggers the sensor event by passing contact information.
Definition: RecordParticlesOperations.h:296
agxControl::LoadParticleJournalOperation::m_startMaterial
agx::Material * m_startMaterial
Definition: RecordParticlesOperations.h:227
agxControl::LoadParticleJournalOperation::m_targetOffsetFrame
agx::FrameRef m_targetOffsetFrame
Definition: RecordParticlesOperations.h:228