AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Graph.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 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#ifndef AGXRENDER_GRAPH_H
18#define AGXRENDER_GRAPH_H
19
20
21#include <agx/Vector.h>
22#include <agx/Vec3.h>
23#include <agx/Vec4.h>
24#include <agx/List.h>
25
26namespace agxRender
27{
28
29
31
34 {
35 public:
36
38
40
46 {
47 public:
49
55 virtual void drawText( const agx::Vec2& pos, const agx::String& str ) = 0;
56
61 virtual void setColor( const agx::Vec4& color ) = 0;
62
66 virtual void drawLine( const agx::Vec2& p1, const agx::Vec2& p2 ) const = 0;
67
72 virtual void preDraw() = 0;
73
78 virtual void postDraw() = 0;
79
83 virtual void clear() = 0;
84
89 virtual void setEnable( bool flag ) = 0;
90
94 virtual void addChannel() = 0;
95
97 virtual size_t getNumChannels() const = 0;
98
102 virtual void removeChannel() = 0;
103
107 virtual void drawData( size_t channelIndex, const Graph::DataVector& data ) = 0;
108
109
110 protected:
111
112 friend class Graph;
114 virtual ~GraphRenderer() {}
115 };
116
117
120 {
121 public:
122
123 Channel( const agx::String& title , const agx::Vec4& color,
124 float minVal, float maxVal,
125 float scaleX = 1.0f, float scaleY = 1.0f );
126
127 void setResolution( size_t r ) {
128 m_cacheSize = r;
129 }
130 void update( float data );
131
132 void setEnableMA( bool flag ) {
133 m_maEnabled = flag;
134 }
135 bool getEnableMA( ) const {
136 return m_maEnabled;
137 }
138
139 const agx::Vec4& getColor() const {
140 return m_color;
141 }
142 protected:
143
144 float mapToLimits( float val ) const;
145
147
148 void drawTitle( const agx::Vec2& pos );
149 void drawData() ;
151
152 friend class Graph;
153
154 virtual ~Channel() {}
155
156 private:
157
159
160 bool m_maEnabled;
161 float m_scaleX;
162 float m_scaleY;
163
164 agx::Vec4 m_color;
165
166 float m_limits[2];
167
168 size_t m_cacheSize;
169
170 agx::List<float> m_data;
171 agx::List<float> m_movingAverage;
172 };
173
174 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 ) ) );
175 void setSize( float width, float height ) {
176 m_width = width;
177 m_height = height;
178 }
179 void setOffset( const agx::Vec2& offset ) {
180 m_offset = offset;
181 }
182
186 bool validate() const;
187
188 void addChannel( Channel *channel );
189 size_t numChannels() const {
190 return m_channels.size();
191 }
193
194 void setEnable( bool flag );
195 bool getEnable( ) const {
196 return m_enable;
197 }
198
199 Channel *getChannel( size_t idx ) {
200 if ( idx >= m_channels.size() ) return nullptr;
201 return m_channels[idx];
202 }
203
204 void setRenderer( GraphRenderer *renderer ) {
205 m_renderer = renderer;
206 renderer->m_graph = this;
207 }
209 return m_renderer;
210 }
211 const GraphRenderer *getRenderer( ) const {
212 return m_renderer;
213 }
214
215 const agx::Vec2& getOffset() const {
216 return m_offset;
217 }
218
219 float getWidth() {
220 return m_width;
221 }
222 float getHeight() {
223 return m_height;
224 }
225 void draw();
226
227 void clearPoints() {
228 m_dataVector.clear();
229 }
230 void reserve( size_t size ) {
231 m_dataVector.reserve( size );
232 }
233 void addPoint( const agx::Vec2& point );
234 void addText( const agx::Vec2& point, const agx::String& str );
235
236 void preDraw();
237 void postDraw();
238
239 protected:
240
241 void drawData( size_t channelIndex ) const;
242
243 virtual ~Graph();
244
245 private:
246
248 ChannelVector m_channels;
249
251
252
253 float m_width, m_height;
254 agx::Vec2 m_offset;
255 DataVector m_dataVector;
256
257 bool m_enable;
258 };
259
260}
261
262#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXPHYSICS_EXPORT
Internal class for handling data for a channel.
Definition Graph.h:120
float mapToLimits(float val) const
const agx::Vec4 & getColor() const
Definition Graph.h:139
void setResolution(size_t r)
Definition Graph.h:127
bool getEnableMA() const
Definition Graph.h:135
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:132
void drawTitle(const agx::Vec2 &pos)
void update(float data)
agx::String m_title
Definition Graph.h:146
Abstract base class that acts as an interface and can render the data from a Graph.
Definition Graph.h:46
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:113
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:34
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:199
const agx::Vec2 & getOffset() const
Definition Graph.h:215
bool getEnable() const
Definition Graph.h:195
void setSize(float width, float height)
Definition Graph.h:175
GraphRenderer * getRenderer()
Definition Graph.h:208
void setOffset(const agx::Vec2 &offset)
Definition Graph.h:179
void addChannel(Channel *channel)
virtual ~Graph()
agx::Vector< agx::Vec2 > DataVector
Definition Graph.h:37
float getWidth()
Definition Graph.h:219
void setRenderer(GraphRenderer *renderer)
Definition Graph.h:204
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:189
const GraphRenderer * getRenderer() const
Definition Graph.h:211
float getHeight()
Definition Graph.h:222
void drawData(size_t channelIndex) const
void clearPoints()
Definition Graph.h:227
void reserve(size_t size)
Definition Graph.h:230
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.
Templated vector class.
Definition agx/Vector.h:53
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
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