AGX Dynamics  2.37.2.0
DebugPlot.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 AGXPLOT_DEBUGPLOT_H
18 #define AGXPLOT_DEBUGPLOT_H
19 
20 #include <agx/config/AGX_USE_WEBPLOT.h>
21 
22 #include <agx/Singleton.h>
23 
24 #include <agxPlot/Curve.h>
25 #if AGX_USE_WEBPLOT()
26 #include <agxPlot/WebPlot.h>
27 #endif
28 
29 
30 namespace agxSDK
31 {
32  class Simulation;
33 }
34 
35 
36 namespace agxPlot
37 {
44  {
45  public:
51  {
52  ADD,
54  USE_LAST
55  };
56 
57  public:
61  static agx::Bool hasInstance( agxSDK::Simulation* simulation );
62 
70  static void addTimeData( agx::Real yValue, const agx::String& curve, const agx::String& window = "", TimeDataBehavior behavior = USE_LAST );
71 
79  static void add( agx::Real yValue, const agx::String& curve, const agx::String& window = "" );
80 
88  static void add( agx::Real xValue, agx::Real yValue, const agx::String& curve, const agx::String& window = "" );
89 
90  public:
91  SINGLETON_CLASSNAME_METHOD();
92 
93  protected:
94  ~DebugPlot();
95 
96  virtual void shutdown() override;
97 
98  private:
99  struct CurveData : public agx::Referenced
100  {
101  agxPlot::CurveRef curve;
102 
103  protected:
104  virtual ~CurveData() {}
105  };
106 
107  struct TimeCurveData : public CurveData
108  {
109  TimeCurveData() : m_written( true ), m_value( agx::Real( 0 ) ) {}
110 
111  agx::Real getValue() const { m_written = true; return m_value; }
112 
113  void set( agx::Real val, TimeDataBehavior behavior )
114  {
115  if ( !m_written ) {
116  if ( behavior == TimeDataBehavior::ADD )
117  m_value += val;
118  else if ( behavior == TimeDataBehavior::USE_FIRST )
119  ;
120  else if ( behavior == TimeDataBehavior::USE_LAST )
121  m_value = val;
122  }
123  else {
124  m_value = val;
125  m_written = false;
126  }
127  }
128 
129  protected:
130  virtual ~TimeCurveData() {}
131 
132  private:
133  mutable agx::Bool m_written;
134  agx::Real m_value;
135  };
137 
138  struct XYCurveData : public CurveData
139  {
140  agxPlot::DataSeriesRef xValues;
141  agxPlot::DataSeriesRef yValues;
142 
143  void add( agx::Real x, agx::Real y )
144  {
145  xValues->push( x );
146  yValues->push( y );
147  }
148 
149  protected:
150  virtual ~XYCurveData() {}
151  };
153 
154  struct YCurveData : public XYCurveData
155  {
156  YCurveData() : m_counter(0) {}
157 
158  void add( agx::Real y )
159  {
160  XYCurveData::add( (agx::Real)m_counter++, y );
161  }
162 
163  protected:
164  virtual ~YCurveData() {}
165 
166  private:
167  agx::UInt64 m_counter;
168  };
170 
171  private:
178 
179  private:
180  friend class agxSDK::Simulation;
181  static DebugPlot* instance( agxSDK::Simulation* simulation );
182  static agx::Bool tryInitialize();
183 
184  private:
185  DebugPlot( agxSDK::Simulation* simulation );
186  void clear( agx::Bool removeRefToSimulation );
187 
188  TimeCurveData* getOrCreateTimeCurveData( const agx::String& windowName, const agx::String& curveName );
189  XYCurveData* getOrCreateXYCurveData( const agx::String& windowName, const agx::String& curveName );
190  YCurveData* getOrCreateYCurveData( const agx::String& windowName, const agx::String& curveName );
191 
192  private:
193 #if AGX_USE_WEBPLOT()
194  agxPlot::WebPlotRef m_webPlot;
195 #endif
196  TimeWindowTable m_timeCurveWindows;
197  XYWindowTable m_xyCurveWindows;
198  YWindowTable m_yCurveWindows;
199  agxSDK::Simulation* m_simulation;
200 
201  private:
202  static DebugPlot* s_instance;
203  };
204 }
205 
206 #endif
AGXTERRAIN_EXPORT void clear()
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
Use first value set - i.e., ignore all the rest of the values during this time step, to this curve.
Definition: DebugPlot.h:53
bool Bool
Definition: Integer.h:48
Add previous and current.
Definition: DebugPlot.h:52
Namespace contains functionality related to plotting.
#define AGXPHYSICS_EXPORT
Base class providing referencing counted objects.
Definition: Referenced.h:119
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
"Static" helper class to plot values from where e.g., values aren&#39;t exposed.
Definition: DebugPlot.h:43
TimeDataBehavior
Behavior when pushing time data values since several calls can be made within same the time step...
Definition: DebugPlot.h:50
uint64_t UInt64
Definition: Integer.h:41
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
double Real
Definition: Real.h:42
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:30