AGX Dynamics  2.37.3.2
SimulationStatisticsListener.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 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 
95  void restore( agxStream::InputArchive& in );
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 
144  UInt32StatisticsListenerData numShapes;
145  UInt32StatisticsListenerData numBodies;
146  UInt32StatisticsListenerData numConstraints;
147  UInt32StatisticsListenerData maxNumContactsPerTimestep;
148  UInt32StatisticsListenerData numContacts;
149  UInt32StatisticsListenerData totalNumContacts;
150  UInt32StatisticsListenerData numTriangles;
151 
152  RealStatisticsListenerData maxLinearSpeed;
153  RealStatisticsListenerData maxAngularSpeed;
154  RealStatisticsListenerData maxContactSpeed;
155  RealStatisticsListenerData maxPenetrationDepth;
156  RealStatisticsListenerData minContactFeature;
157  RealStatisticsListenerData maxContactSpeedFeatureRatio;
158  RealStatisticsListenerData maxConstraintViolation;
159 
160  RealStatisticsListenerData maxFeatureSpeed;
161  RealStatisticsListenerData maxFeature;
162  RealStatisticsListenerData minFeature;
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 
284  StatisticsDataRef m_statisticsData;
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
agx::ref_ptr< StatisticsData > StatisticsDataRef
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
RealStatisticsListenerData maxFeatureSpeed
Derive from this class to implement a listener for simulation step events.
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...
Base class for a shape.
Definition: Shape.h:53
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
Store all the various statistics of a simulation.
UInt32StatisticsListenerData numShapes
RealStatisticsListenerData maxLinearSpeed
RealStatisticsListenerData maxContactSpeedFeatureRatio
StatisticsListenerData< agx::UInt32 > UInt32StatisticsListenerData
void set(T val)
Set the value explicitly without comparison.
#define AGXPHYSICS_EXPORT
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
UInt32StatisticsListenerData numContacts
StatisticsListenerData< agx::Real > RealStatisticsListenerData
RealStatisticsListenerData maxConstraintViolation
agx::Real TimeStamp
Definition: TimeStamp.h:26
UInt32StatisticsListenerData numConstraints
This class will collect statistics and sizes of a simulation.
Base class providing referencing counted objects.
Definition: Referenced.h:119
agx::observer_ptr< agxSDK::Simulation > m_simulation
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
RealStatisticsListenerData maxFeature
agxSDK::Simulation * getSimulation()
RealStatisticsListenerData minContactFeature
RealStatisticsListenerData maxContactSpeed
agx::ref_ptr< SimulationStatisticsListener > SimulationStatisticsListenerRef
RealStatisticsListenerData minFeature
UInt32StatisticsListenerData totalNumContacts
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
RealStatisticsListenerData maxPenetrationDepth
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
RealStatisticsListenerData maxAngularSpeed
#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
uint64_t UInt64
Definition: Integer.h:41
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
UInt32StatisticsListenerData maxNumContactsPerTimestep
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
Class for storing min/max values together with a ID for the associated RigidBody/Geometry.
virtual void addObject(agx::Object *object, bool assignContext=true)
Add an object to the component.
UInt32StatisticsListenerData numBodies
double Real
Definition: Real.h:42
UInt32StatisticsListenerData numTriangles
AGXCORE_EXPORT Component * root()
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
uint32_t UInt32
Definition: Integer.h:40
Templated value.
Definition: Value.h:236