AGXDynamics  2.35.0.3
SimulationStatisticsListener.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, 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 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 
29 namespace agxStream
30 {
31  class InputArchive;
32  class OutputArchive;
33 }
34 
35 namespace agxSDK
36 {
37  class StatisticsData;
38 
39 
41  template<typename T>
43 
44  public:
46 
48  agx::Real getTime() const;
49 
51  agx::UInt64 getGeometry1() const;
52 
54  agx::UInt64 getGeometry2() const;
55 
57  agx::UInt64 getBody1() const;
58 
60  agx::UInt64 getBody2() const;
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
76  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 
120  {
121  protected:
124 
125  public:
126 
128  StatisticsData( );
129 
130 
132  void store( agxStream::OutputArchive& out ) const;
133 
135  void restore( agxStream::InputArchive& in );
136 
137  void reset();
138 
139  void setSimulation( agxSDK::Simulation *sim );
140  agxSDK::Simulation *getSimulation() { return m_simulation; }
141 
142  agx::Component *getDataRoot() {return m_dataRoot;}
143 
151 
159 
163 
164 
165  protected:
166  virtual ~StatisticsData();
167  };
168 
170 
171 
177  {
178 
179  public:
181 
186  void collectSystemData( agx::Real time = 0);
187 
189  agx::Real getDuration() const;
190 
192  agx::UInt32 getNumRigidBodies() const;
193 
195  agx::UInt32 getNumConstraints() const;
196 
198  agx::UInt32 getMaxNumContactsPerTimeStep() const;
199 
201  agx::UInt32 getNumContacts() const;
202 
204  RealStatisticsListenerData getMaxLinearSpeed() const;
205 
207  RealStatisticsListenerData getMaxAngularSpeed() const;
208 
210  RealStatisticsListenerData getMaxContactSpeed() const;
211 
213  RealStatisticsListenerData getMaxPenetrationDepth() const;
214 
215  RealStatisticsListenerData getMaxConstraintViolation() const;
216 
218  RealStatisticsListenerData getMinFeature() const;
219 
221  RealStatisticsListenerData getMinContactFeature() const;
222 
224  RealStatisticsListenerData getMaxContactSpeedFeatureRatio() const;
225 
227  RealStatisticsListenerData getMaxFeature() const;
228 
230  RealStatisticsListenerData getMaxFeatureSpeed() const;
231 
232 
234  agx::UInt32 getTotalNumContacts() const;
235 
237  agx::UInt32 getNumTriangles() const;
238 
240  agx::UInt32 getNumShapes() const;
241 
243  void reset();
244 
245 
247  agx::String getReport() const;
248 
250 
251  protected:
252 
253  void updateContactData( agx::Real time );
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 
264  bool calculateShapeFeatures(
265  const agxCollide::Shape *shape, const agx::RigidBody *body,
266  agx::Real& smallestFeature, agx::Real& largestFeature,
267  agx::Vec3& largestFeaturePointRelBody, agx::Real& largestDistance);
268 
269  bool calculateFeatures(
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>
328  template<typename T>
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
agxSDK::StatisticsListenerData::getBody2
agx::UInt64 getBody2() const
Definition: SimulationStatisticsListener.h:329
agx::UInt64
uint64_t UInt64
Definition: Integer.h:41
agxSDK::StatisticsData::totalNumContacts
UInt32StatisticsListenerData totalNumContacts
Definition: SimulationStatisticsListener.h:149
Shape.h
agxSDK::StatisticsListenerData::store
void store(agxStream::OutputArchive &out) const
Serialization store.
agxSDK::StatisticsDataRef
agx::ref_ptr< StatisticsData > StatisticsDataRef
Definition: SimulationStatisticsListener.h:169
agxSDK::StatisticsData::getSimulation
agxSDK::Simulation * getSimulation()
Definition: SimulationStatisticsListener.h:140
agx::Real
double Real
Definition: Real.h:42
agxSDK::StatisticsListenerData::compareAndStoreMin
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...
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
agxStream::out
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
Definition: OutputArchive.h:412
agxSDK::StatisticsListenerData::getTime
agx::Real getTime() const
Definition: SimulationStatisticsListener.h:320
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agxData::ValueT
Templated value.
Definition: Value.h:230
agxSDK::SimulationStatisticsListener::m_numTimeSteps
agx::UInt32 m_numTimeSteps
Definition: SimulationStatisticsListener.h:282
agxSDK::StatisticsData::numTriangles
UInt32StatisticsListenerData numTriangles
Definition: SimulationStatisticsListener.h:150
agxSDK::StatisticsData::minFeature
RealStatisticsListenerData minFeature
Definition: SimulationStatisticsListener.h:162
Geometry.h
agxSDK::StatisticsData::numShapes
UInt32StatisticsListenerData numShapes
Definition: SimulationStatisticsListener.h:144
agxSDK::UInt32StatisticsListenerData
StatisticsListenerData< agx::UInt32 > UInt32StatisticsListenerData
Definition: SimulationStatisticsListener.h:116
agxSDK::SimulationStatisticsListener::m_statisticsData
StatisticsDataRef m_statisticsData
Definition: SimulationStatisticsListener.h:284
StepEventListener.h
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
agxSDK::RealStatisticsListenerData
StatisticsListenerData< agx::Real > RealStatisticsListenerData
Definition: SimulationStatisticsListener.h:115
agx::observer_ptr< agxSDK::Simulation >
agxSDK::SimulationStatisticsListenerRef
agx::ref_ptr< SimulationStatisticsListener > SimulationStatisticsListenerRef
Definition: SimulationStatisticsListener.h:287
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxStream::in
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
agxSDK::SimulationStatisticsListener::m_minTimeStep
agx::Real m_minTimeStep
Definition: SimulationStatisticsListener.h:279
agxSDK::StatisticsListenerData::getGeometry1
agx::UInt64 getGeometry1() const
Definition: SimulationStatisticsListener.h:323
Vec3.h
agx::ref_ptr< Component >
agxSDK::StatisticsData::m_dataRoot
agx::ComponentRef m_dataRoot
Definition: SimulationStatisticsListener.h:123
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agxSDK::SimulationStatisticsListener::m_sumTimeStep
agx::Real m_sumTimeStep
Definition: SimulationStatisticsListener.h:281
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
agxSDK::StatisticsData::numConstraints
UInt32StatisticsListenerData numConstraints
Definition: SimulationStatisticsListener.h:146
agxSDK::SimulationStatisticsListener::m_avgTimeStep
agx::Real m_avgTimeStep
Definition: SimulationStatisticsListener.h:278
agxSDK::StatisticsData::maxContactSpeedFeatureRatio
RealStatisticsListenerData maxContactSpeedFeatureRatio
Definition: SimulationStatisticsListener.h:157
agxSDK::SimulationStatisticsListener::m_startTime
agx::Real m_startTime
Definition: SimulationStatisticsListener.h:275
agx::Component::addObject
virtual void addObject(agx::Object *object, bool assignContext=true)
Add an object to the component.
agxSDK::StatisticsData::maxFeatureSpeed
RealStatisticsListenerData maxFeatureSpeed
Definition: SimulationStatisticsListener.h:160
agxSDK::StatisticsListenerData::StatisticsListenerData
StatisticsListenerData(StatisticsData *parent, const agx::String &id)
Definition: SimulationStatisticsListener.h:291
agxSDK::SimulationStatisticsListener::m_gravity
agx::Real m_gravity
Definition: SimulationStatisticsListener.h:277
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agxSDK::StatisticsData::minContactFeature
RealStatisticsListenerData minContactFeature
Definition: SimulationStatisticsListener.h:156
agxSDK::StatisticsData::maxFeature
RealStatisticsListenerData maxFeature
Definition: SimulationStatisticsListener.h:161
agxSDK::StatisticsListenerData::set
void set(T val)
Set the value explicitly without comparison.
Definition: SimulationStatisticsListener.h:345
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agxSDK::StatisticsData::maxAngularSpeed
RealStatisticsListenerData maxAngularSpeed
Definition: SimulationStatisticsListener.h:153
agx::Component
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
agx::root
AGXCORE_EXPORT Component * root()
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
RigidBody.h
agxSDK::StatisticsData::maxLinearSpeed
RealStatisticsListenerData maxLinearSpeed
Definition: SimulationStatisticsListener.h:152
agxSDK::StatisticsData::maxContactSpeed
RealStatisticsListenerData maxContactSpeed
Definition: SimulationStatisticsListener.h:154
agxSDK::StatisticsData::maxNumContactsPerTimestep
UInt32StatisticsListenerData maxNumContactsPerTimestep
Definition: SimulationStatisticsListener.h:147
agxSDK::StatisticsListenerData
Class for storing min/max values together with a ID for the associated RigidBody/Geometry.
Definition: SimulationStatisticsListener.h:42
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agxSDK::StatisticsData::maxPenetrationDepth
RealStatisticsListenerData maxPenetrationDepth
Definition: SimulationStatisticsListener.h:155
agxSDK::SimulationStatisticsListener::m_maxTimeStep
agx::Real m_maxTimeStep
Definition: SimulationStatisticsListener.h:280
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agxSDK::SimulationStatisticsListener::m_firstPreCall
bool m_firstPreCall
Definition: SimulationStatisticsListener.h:274
agxSDK::StatisticsData
Store all the various statistics of a simulation.
Definition: SimulationStatisticsListener.h:119
agxSDK::SimulationStatisticsListener::m_lastTime
agx::Real m_lastTime
Definition: SimulationStatisticsListener.h:276
agxSDK::StatisticsData::m_simulation
agx::observer_ptr< agxSDK::Simulation > m_simulation
Definition: SimulationStatisticsListener.h:122
agxStream
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Definition: ElementaryConstraint.h:31
agx::AgXString< std::string >
agxSDK::StatisticsListenerData::restore
void restore(agxStream::InputArchive &in)
Serialization restore.
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxSDK::StatisticsListenerData::reset
void reset(T val=0)
reset the value to the given value
Definition: SimulationStatisticsListener.h:356
agx::Vec3T< Real >
agxSDK::StatisticsListenerData::compareAndStoreMax
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 ...
agx::InvalidIndex
const AGXCORE_EXPORT InvalidIndexStruct InvalidIndex
agxSDK::StatisticsData::maxConstraintViolation
RealStatisticsListenerData maxConstraintViolation
Definition: SimulationStatisticsListener.h:158
agxSDK::StatisticsListenerData::getGeometry2
agx::UInt64 getGeometry2() const
Definition: SimulationStatisticsListener.h:325
agxSDK::StatisticsData::getDataRoot
agx::Component * getDataRoot()
Definition: SimulationStatisticsListener.h:142
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxSDK::StatisticsListenerData::get
T get() const
Definition: SimulationStatisticsListener.h:334
agxSDK::StatisticsData::numContacts
UInt32StatisticsListenerData numContacts
Definition: SimulationStatisticsListener.h:148
agxSDK::SimulationStatisticsListener
This class will collect statistics and sizes of a simulation.
Definition: SimulationStatisticsListener.h:176
agxSDK::StatisticsListenerData::inc
void inc()
Increment by one.
Definition: SimulationStatisticsListener.h:340
agxSDK::StatisticsListenerData::getBody1
agx::UInt64 getBody1() const
Definition: SimulationStatisticsListener.h:327
Value.h
agxSDK::StatisticsData::numBodies
UInt32StatisticsListenerData numBodies
Definition: SimulationStatisticsListener.h:145
agxSDK::SimulationStatisticsListener::~SimulationStatisticsListener
virtual ~SimulationStatisticsListener()
Destructor.
Definition: SimulationStatisticsListener.h:262
agxSDK.h