AGX Dynamics 2.40.1.2
Loading...
Searching...
No Matches
Graph.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. 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#pragma once
18
19
20#include <agx/Vector.h>
21#include <agx/Vec3.h>
22#include <agx/Vec4.h>
23#include <agx/List.h>
24
25namespace agxRender
26{
27
28
30
33 {
34 public:
35
37
39
45 {
46 public:
48
54 virtual void drawText( const agx::Vec2& pos, const agx::String& str ) = 0;
55
60 virtual void setColor( const agx::Vec4& color ) = 0;
61
65 virtual void drawLine( const agx::Vec2& p1, const agx::Vec2& p2 ) const = 0;
66
71 virtual void preDraw() = 0;
72
77 virtual void postDraw() = 0;
78
82 virtual void clear() = 0;
83
88 virtual void setEnable( bool flag ) = 0;
89
93 virtual void addChannel() = 0;
94
96 virtual size_t getNumChannels() const = 0;
97
101 virtual void removeChannel() = 0;
102
106 virtual void drawData( size_t channelIndex, const Graph::DataVector& data ) = 0;
107
108
109 protected:
110
111 friend class Graph;
113 virtual ~GraphRenderer() {}
114 };
115
116
119 {
120 public:
121
122 Channel( const agx::String& title , const agx::Vec4& color,
123 float minVal, float maxVal,
124 float scaleX = 1.0f, float scaleY = 1.0f );
125
126 void setResolution( size_t r ) {
127 m_cacheSize = r;
128 }
129 void update( float data );
130
131 void setEnableMA( bool flag ) {
132 m_maEnabled = flag;
133 }
134 bool getEnableMA( ) const {
135 return m_maEnabled;
136 }
137
138 const agx::Vec4& getColor() const {
139 return m_color;
140 }
141 protected:
142
143 float mapToLimits( float val ) const;
144
146
147 void drawTitle( const agx::Vec2& pos );
148 void drawData() ;
150
151 friend class Graph;
152
153 virtual ~Channel() {}
154
155 private:
156
158
159 bool m_maEnabled;
160 float m_scaleX;
161 float m_scaleY;
162
163 agx::Vec4 m_color;
164
165 float m_limits[2];
166
167 size_t m_cacheSize;
168
169 agx::List<float> m_data;
170 agx::List<float> m_movingAverage;
171 };
172
173 Graph( float width = float( 0.9 ), float height = float( 0.2 ), const agx::Vec2& offset = agx::Vec2( agx::Real( 0.01 ), agx::Real( 0.01 ) ) );
174 void setSize( float width, float height ) {
175 m_width = width;
176 m_height = height;
177 }
178 void setOffset( const agx::Vec2& offset ) {
179 m_offset = offset;
180 }
181
185 bool validate() const;
186
187 void addChannel( Channel *channel );
188 size_t numChannels() const {
189 return m_channels.size();
190 }
192
193 void setEnable( bool flag );
194 bool getEnable( ) const {
195 return m_enable;
196 }
197
198 Channel *getChannel( size_t idx ) {
199 if ( idx >= m_channels.size() ) return nullptr;
200 return m_channels[idx];
201 }
202
203 void setRenderer( GraphRenderer *renderer ) {
204 m_renderer = renderer;
205 renderer->m_graph = this;
206 }
208 return m_renderer;
209 }
210 const GraphRenderer *getRenderer( ) const {
211 return m_renderer;
212 }
213
214 const agx::Vec2& getOffset() const {
215 return m_offset;
216 }
217
218 float getWidth() {
219 return m_width;
220 }
221 float getHeight() {
222 return m_height;
223 }
224 void draw();
225
226 void clearPoints() {
227 m_dataVector.clear();
228 }
229 void reserve( size_t size ) {
230 m_dataVector.reserve( size );
231 }
232 void addPoint( const agx::Vec2& point );
233 void addText( const agx::Vec2& point, const agx::String& str );
234
235 void preDraw();
236 void postDraw();
237
238 protected:
239
240 void drawData( size_t channelIndex ) const;
241
242 virtual ~Graph();
243
244 private:
245
247 ChannelVector m_channels;
248
250
251
252 float m_width, m_height;
253 agx::Vec2 m_offset;
254 DataVector m_dataVector;
255
256 bool m_enable;
257 };
258
259}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXPHYSICS_EXPORT
Internal class for handling data for a channel.
Definition: Graph.h:119
float mapToLimits(float val) const
const agx::Vec4 & getColor() const
Definition: Graph.h:138
void setResolution(size_t r)
Definition: Graph.h:126
bool getEnableMA() const
Definition: Graph.h:134
Channel(const agx::String &title, const agx::Vec4 &color, float minVal, float maxVal, float scaleX=1.0f, float scaleY=1.0f)
void setEnableMA(bool flag)
Definition: Graph.h:131
void drawTitle(const agx::Vec2 &pos)
void update(float data)
agx::String m_title
Definition: Graph.h:145
Abstract base class that acts as an interface and can render the data from a Graph.
Definition: Graph.h:45
virtual void setColor(const agx::Vec4 &color)=0
virtual void clear()=0
Destruction of any data for this graph.
virtual void addChannel()=0
Setup structures/data for another data channel.
virtual void drawLine(const agx::Vec2 &p1, const agx::Vec2 &p2) const =0
Draw a line from p1 to p2.
virtual void removeChannel()=0
Tear down data for the last added channel.
virtual void postDraw()=0
If the rendering of this graph requires some cleanup to be done it can be done in this method.
virtual void drawText(const agx::Vec2 &pos, const agx::String &str)=0
virtual void preDraw()=0
If the rendering of this graph requires some pre-state to be set (orthographic projection etc) this c...
agx::observer_ptr< Graph > m_graph
Definition: Graph.h:112
virtual void setEnable(bool flag)=0
Implement functionality for enabling/disabling the rendering of this graph.
virtual size_t getNumChannels() const =0
virtual void drawData(size_t channelIndex, const Graph::DataVector &data)=0
Update the line geometry for a specified channel given the data (points)
Class that implements a simple graph for plotting scalar values.
Definition: Graph.h:33
void addPoint(const agx::Vec2 &point)
void setEnable(bool flag)
void addText(const agx::Vec2 &point, const agx::String &str)
Channel * getChannel(size_t idx)
Definition: Graph.h:198
const agx::Vec2 & getOffset() const
Definition: Graph.h:214
bool getEnable() const
Definition: Graph.h:194
void setSize(float width, float height)
Definition: Graph.h:174
GraphRenderer * getRenderer()
Definition: Graph.h:207
void setOffset(const agx::Vec2 &offset)
Definition: Graph.h:178
void addChannel(Channel *channel)
virtual ~Graph()
agx::Vector< agx::Vec2 > DataVector
Definition: Graph.h:36
float getWidth()
Definition: Graph.h:218
void setRenderer(GraphRenderer *renderer)
Definition: Graph.h:203
bool validate() const
Will check so that the number of channels for the associated GraphRenderer has equal # channels as th...
size_t numChannels() const
Definition: Graph.h:188
const GraphRenderer * getRenderer() const
Definition: Graph.h:210
float getHeight()
Definition: Graph.h:221
void drawData(size_t channelIndex) const
void clearPoints()
Definition: Graph.h:226
void reserve(size_t size)
Definition: Graph.h:229
Graph(float width=float(0.9), float height=float(0.2), const agx::Vec2 &offset=agx::Vec2(agx::Real(0.01), agx::Real(0.01)))
Base class providing referencing counted objects.
Definition: Referenced.h:120
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
Templated vector class.
Definition: agx/Vector.h:53
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:61
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
Namespace containing classes for handling debug rendering of collision geometries,...
Definition: Constraint.h:36
double Real
Definition: Real.h:42