AGX Dynamics  2.37.3.2
Graph.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 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 
26 namespace 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() ;
150  void drawMovingAverage() ;
151 
152  friend class Graph;
153 
154  virtual ~Channel() {}
155 
156  private:
157 
158  agx::observer_ptr<Graph> m_parent;
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  }
192  void clearChannels();
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 
250  agx::ref_ptr<GraphRenderer> m_renderer;
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
GraphRenderer * getRenderer()
Definition: Graph.h:208
AGXTERRAIN_EXPORT void clear()
Class that implements a simple graph for plotting scalar values.
Definition: Graph.h:33
float getWidth()
Definition: Graph.h:219
agx::observer_ptr< Graph > m_graph
Definition: Graph.h:113
Internal class for handling data for a channel.
Definition: Graph.h:119
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:60
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
float getHeight()
Definition: Graph.h:222
void setResolution(size_t r)
Definition: Graph.h:127
const GraphRenderer * getRenderer() const
Definition: Graph.h:211
void setEnableMA(bool flag)
Definition: Graph.h:132
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Namespace containing classes for handling debug rendering of collision geometries, constraints, contacts and rigid bodies.
Definition: Constraint.h:35
Base class providing referencing counted objects.
Definition: Referenced.h:119
const agx::Vec2 & getOffset() const
Definition: Graph.h:215
void setRenderer(GraphRenderer *renderer)
Definition: Graph.h:204
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
const agx::Vec4 & getColor() const
Definition: Graph.h:139
Channel * getChannel(size_t idx)
Definition: Graph.h:199
void setSize(float width, float height)
Definition: Graph.h:175
void clearPoints()
Definition: Graph.h:227
bool getEnable() const
Definition: Graph.h:195
void setOffset(const agx::Vec2 &offset)
Definition: Graph.h:179
agx::Vector< agx::Vec2 > DataVector
Definition: Graph.h:37
Abstract base class that acts as an interface and can render the data from a Graph.
Definition: Graph.h:45
void reserve(size_t size)
Definition: Graph.h:230
agx::String m_title
Definition: Graph.h:146
size_t numChannels() const
Definition: Graph.h:189
double Real
Definition: Real.h:42
AGXOSG_EXPORT bool addText(const agxCollide::Geometry *geometry, osg::Group *root, const std::string &text, const agx::Vec3 &relPosition=agx::Vec3(0, 0, 0), const agx::Vec4f &color=agxRender::Color::Yellow(), agx::Real size=0.2)
Add text relative to an geometry.
bool getEnableMA() const
Definition: Graph.h:135