AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
DebugPlot.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
9having been advised so by Algoryx Simulation AB for a time limited evaluation,
10or having purchased a valid 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 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
30namespace agxSDK
31{
32 class Simulation;
33}
34
35
36namespace agxPlot
37{
44 {
45 public:
51 {
54 USE_LAST
55 };
56
57 public:
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:
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 };
136 typedef agx::ref_ptr< TimeCurveData > TimeCurveDataRef;
137
138 struct XYCurveData : public CurveData
139 {
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 };
152 typedef agx::ref_ptr< XYCurveData > XYCurveDataRef;
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 };
169 typedef agx::ref_ptr< YCurveData > YCurveDataRef;
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
#define AGXPHYSICS_EXPORT
"Static" helper class to plot values from where e.g., values aren't exposed.
Definition DebugPlot.h:44
TimeDataBehavior
Behavior when pushing time data values since several calls can be made within same the time step.
Definition DebugPlot.h:51
@ ADD
Add previous and current.
Definition DebugPlot.h:52
@ USE_FIRST
Use first value set - i.e., ignore all the rest of the values during this time step,...
Definition DebugPlot.h:53
static void addTimeData(agx::Real yValue, const agx::String &curve, const agx::String &window="", TimeDataBehavior behavior=USE_LAST)
Add y-value to a curve, named curve, in a window named window, where the x-values are simulation time...
static void add(agx::Real yValue, const agx::String &curve, const agx::String &window="")
Add y-value to a curve, named curve, in a window named window, where the x-values are integers,...
static agx::Bool hasInstance(agxSDK::Simulation *simulation)
static void add(agx::Real xValue, agx::Real yValue, const agx::String &curve, const agx::String &window="")
Add (x, y) to a curve with name curve in a window named window.
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition HashVector.h:41
Base class providing referencing counted objects.
Definition Referenced.h:120
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition Singleton.h:31
Namespace contains functionality related to plotting.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition Integer.h:40
uint64_t UInt64
Definition Integer.h:33
double Real
Definition Real.h:42