AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
SimulationStatisticsListener.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 AGXSDK_SIMULATIONSTATISTICSLISTENER_H
18#define AGXSDK_SIMULATIONSTATISTICSLISTENER_H
19
20#include <agxSDK/agxSDK.h>
21
23#include <agx/RigidBody.h>
24#include <agxCollide/Geometry.h>
25#include <agxCollide/Shape.h>
26#include <agxData/Value.h>
27#include <agx/Vec3.h>
28
29namespace agxStream
30{
31 class InputArchive;
32 class OutputArchive;
33}
34
35namespace agxSDK
36{
37 class StatisticsData;
38
39
41 template<typename T>
43
44 public:
46
49
52
55
58
61
62#ifndef SWIG
63
65 T compareAndStoreMax( agx::Real time, T val, const agx::RigidBody* b1=nullptr, const agx::RigidBody* b2=nullptr);
66
68 T compareAndStoreMin( agx::Real time, T val, const agx::RigidBody* b1, const agx::RigidBody* b2=nullptr);
69
71 T compareAndStoreMax( agx::Real time, T val, const agxCollide::Geometry *geom1, const agxCollide::Geometry *geom2=nullptr);
72
74 T compareAndStoreMin( agx::Real time, T val, const agxCollide::Geometry *geom1, const agxCollide::Geometry *geom2=nullptr);
75#endif
77 T get() const;
78
80 void inc( );
81
83 void set( T val );
84
86 void set( agx::Real time, T val );
87
89 void reset( T val=0 );
90
92 void store( agxStream::OutputArchive& out ) const;
93
96
97 private:
98
99 void initData();
100
101#ifndef SWIG
102 StatisticsData *m_parent;
103 agx::ComponentRef m_group;
104 agx::String m_name;
111
112#endif
113 };
114
117
168
170
171
177 {
178
179 public:
181
187
190
193
196
199
202
205
208
211
214
216
219
222
225
228
231
232
235
238
241
243 void reset();
244
245
248
250
251 protected:
252
254
255 virtual void post(const agx::TimeStamp& ) override;
256 virtual void pre(const agx::TimeStamp& ) override;
257
258 virtual void addNotification() override;
259 virtual void removeNotification() override;
260
263
265 const agxCollide::Shape *shape, const agx::RigidBody *body,
266 agx::Real& smallestFeature, agx::Real& largestFeature,
267 agx::Vec3& largestFeaturePointRelBody, agx::Real& largestDistance);
268
270 const agx::RigidBody* body, agx::Real& smallestFeature, const agxCollide::Geometry*& smallestFeatureGeometry,
271 agx::Real& largestFeature, const agxCollide::Geometry*& largestFeatureGeometry, agx::Vec3& pointRelativeBody);
272
273
283
285 };
286
288
289
290 template<typename T>
292 m_parent(parent), m_name(id)
293 {
294 initData();
295 }
296 template<typename T>
298 {
299 agx::Component *root = m_parent->getDataRoot();
300 m_group = new agx::Component(m_name);
301 root->addObject( m_group );
302
303 m_value = new agxData::ValueT<T>("value");
304 m_group->addObject( m_value );
305
306 m_time = new agxData::ValueT<agx::Real>("time");
307 m_group->addObject( m_time );
308
309 body1 = new agxData::ValueT<agx::UInt64>("body1");
310 m_group->addObject( body1 );
311 body2 = new agxData::ValueT<agx::UInt64>("body2");
312 m_group->addObject( body2 );
313 geometry1 = new agxData::ValueT<agx::UInt64>("geometry1");
314 m_group->addObject( geometry1 );
315 geometry2 = new agxData::ValueT<agx::UInt64>("geometry2");
316 m_group->addObject( geometry2 );
317 }
318
319 template<typename T>
320 agx::Real StatisticsListenerData<T>::getTime() const { return m_time->get(); }
321
322 template<typename T>
323 agx::UInt64 StatisticsListenerData<T>::getGeometry1() const { return geometry1->get(); }
324 template<typename T>
325 agx::UInt64 StatisticsListenerData<T>::getGeometry2() const { return geometry2->get(); }
326 template<typename T>
327 agx::UInt64 StatisticsListenerData<T>::getBody1() const { return body1->get(); }
328 template<typename T>
329 agx::UInt64 StatisticsListenerData<T>::getBody2() const { return body2->get(); }
330
331
332
333 template<typename T>
335 return m_value->get();
336 }
337
339 template<typename T>
341 m_value->set(m_value->get()+1);
342 }
343
344 template<typename T>
346 m_value->set(val);
347 }
348
349 template<typename T>
351 m_value->set(val);
352 m_time->set( time );
353 }
354
355 template<typename T>
357 {
358 body1->set(agx::InvalidIndex);
359 body2->set(agx::InvalidIndex);
360 geometry1->set(agx::InvalidIndex);
361 geometry2->set(agx::InvalidIndex);
362 set(val);
363 }
364
365}
366
367#endif
#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
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
Base class for a shape.
Definition Shape.h:54
Only use as member allocated variable.
Definition Value.h:285
This class will collect statistics and sizes of a simulation.
RealStatisticsListenerData getMaxConstraintViolation() const
void reset()
Reset the statistics.
bool calculateFeatures(const agx::RigidBody *body, agx::Real &smallestFeature, const agxCollide::Geometry *&smallestFeatureGeometry, agx::Real &largestFeature, const agxCollide::Geometry *&largestFeatureGeometry, agx::Vec3 &pointRelativeBody)
RealStatisticsListenerData getMinContactFeature() const
RealStatisticsListenerData getMaxContactSpeed() const
virtual void post(const agx::TimeStamp &) override
Called after a step is taken in the simulation Implement this method in the derived class to get call...
virtual void addNotification() override
Called when this listener is added to the simulation.
agx::String getReport() const
Get a report in string format.
RealStatisticsListenerData getMaxLinearSpeed() const
void updateContactData(agx::Real time)
RealStatisticsListenerData getMinFeature() const
bool calculateShapeFeatures(const agxCollide::Shape *shape, const agx::RigidBody *body, agx::Real &smallestFeature, agx::Real &largestFeature, agx::Vec3 &largestFeaturePointRelBody, agx::Real &largestDistance)
RealStatisticsListenerData getMaxContactSpeedFeatureRatio() const
virtual void pre(const agx::TimeStamp &) override
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
agx::UInt32 getTotalNumContacts() const
RealStatisticsListenerData getMaxAngularSpeed() const
RealStatisticsListenerData getMaxFeatureSpeed() const
agx::UInt32 getMaxNumContactsPerTimeStep() const
RealStatisticsListenerData getMaxPenetrationDepth() const
agx::UInt32 getNumRigidBodies() const
RealStatisticsListenerData getMaxFeature() const
virtual void removeNotification() override
Called when this listener is removed from the simulation.
void collectSystemData(agx::Real time=0)
Method that will given the current Simulation count number of bodies, constraints and collect number ...
agx::UInt32 getNumConstraints() const
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Store all the various statistics of a simulation.
UInt32StatisticsListenerData totalNumContacts
RealStatisticsListenerData minFeature
RealStatisticsListenerData maxContactSpeed
agx::observer_ptr< agxSDK::Simulation > m_simulation
UInt32StatisticsListenerData numShapes
RealStatisticsListenerData maxContactSpeedFeatureRatio
UInt32StatisticsListenerData numContacts
RealStatisticsListenerData maxFeatureSpeed
UInt32StatisticsListenerData numBodies
void setSimulation(agxSDK::Simulation *sim)
RealStatisticsListenerData minContactFeature
RealStatisticsListenerData maxPenetrationDepth
RealStatisticsListenerData maxAngularSpeed
UInt32StatisticsListenerData maxNumContactsPerTimestep
RealStatisticsListenerData maxFeature
StatisticsData()
Constructor.
void store(agxStream::OutputArchive &out) const
Serialization store.
RealStatisticsListenerData maxConstraintViolation
UInt32StatisticsListenerData numConstraints
void restore(agxStream::InputArchive &in)
Serialization restore.
RealStatisticsListenerData maxLinearSpeed
UInt32StatisticsListenerData numTriangles
Class for storing min/max values together with a ID for the associated RigidBody/Geometry.
void reset(T val=0)
reset the value to the given value
void set(T val)
Set the value explicitly without comparison.
T compareAndStoreMin(agx::Real time, T val, const agx::RigidBody *b1, const agx::RigidBody *b2=nullptr)
will compare val with the previous value and store time, value, and bodies if val is lower than the p...
void store(agxStream::OutputArchive &out) const
Serialization store.
StatisticsListenerData(StatisticsData *parent, const agx::String &id)
void restore(agxStream::InputArchive &in)
Serialization restore.
T compareAndStoreMax(agx::Real time, T val, const agxCollide::Geometry *geom1, const agxCollide::Geometry *geom2=nullptr)
will compare val with the previous value and store time, value, and geometries if val is larger than ...
T compareAndStoreMax(agx::Real time, T val, const agx::RigidBody *b1=nullptr, const agx::RigidBody *b2=nullptr)
will compare val with the previous value and store time, value, and bodies if val is larger than the ...
T compareAndStoreMin(agx::Real time, T val, const agxCollide::Geometry *geom1, const agxCollide::Geometry *geom2=nullptr)
will compare val with the previous value and store time, value, and geometries if val is lower than t...
void set(agx::Real time, T val)
Set the value explicitly without comparison including the time.
Derive from this class to implement a listener for simulation step events.
Class for reading a binary stream of serialized data.
Class for writing serialized data in binary format to a stream.
A component is an object containing other objects, enabling hierarchical structuring.
Definition Component.h:39
virtual void addObject(agx::Object *object, bool assignContext=true)
Add an object to the component.
Base class providing referencing counted objects.
Definition Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
agx::ref_ptr< StatisticsData > StatisticsDataRef
agx::ref_ptr< SimulationStatisticsListener > SimulationStatisticsListenerRef
StatisticsListenerData< agx::Real > RealStatisticsListenerData
StatisticsListenerData< agx::UInt32 > UInt32StatisticsListenerData
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
uint32_t UInt32
Definition Integer.h:32
uint64_t UInt64
Definition Integer.h:33
double Real
Definition Real.h:42
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
agx::Real TimeStamp
Definition TimeStamp.h:26