Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hudstatistics.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __HUD_STATISTICS_H
25 #define __HUD_STATISTICS_H
26 
27 #include <selforg/statistictools.h>
28 
29 #include "color.h"
30 
31 /* forward declaration block */
32 namespace osgText {
33 class Text;
34 class Font;
35 }
36 
37 namespace osg {
38 class Geode;
39 }
40 
41 /* end of forward declaration */
42 
43 namespace lpzrobots {
44 
45 /**
46  * manages all the stuff displaying statistics on the graphics window.
47  * This is a experimental version, so do not to be afraid changing this crazy
48  * code.
49  *
50  * This class uses the implementation of the class StatisticTools, which is
51  * generalized to make nice statistics. Instead of passing the values to the
52  * guilogger (INSPECTABLE interface), we simply diplay this values on the graphics
53  * window.
54  *
55  * So how it works:
56  * - overwriting the method getMeasure gives us the ability to create the needed text
57  * object, then storing it in a class named WindowStatistic
58  * (which is stored in the windowStatisticList).
59  */
61 
62 public:
63  /**
64  * Nested class WindowStatistic, which puts the measure and the graphics text together.
65  */
67  public:
68 
69  WindowStatistic(AbstractMeasure* measure, osgText::Text* text) : measure(measure),
70  text(text) {}
71 
72  virtual ~WindowStatistic() {}
73 
74  virtual AbstractMeasure* getMeasure() { return measure; }
75 
76  virtual osgText::Text* getText() { return text; }
77 
78  private:
79  AbstractMeasure* measure;
80  osgText::Text* text;
81  };
82 
83 public:
84  /**
85  * creates the HUDStatisticsManager, normally done by class Base.
86  * @param geode this is the graphical node at wich the text objects are hooked in.
87  */
88  HUDStatisticsManager(osg::Geode* geode, osgText::Font* font, int ypos);
89 
90  virtual ~HUDStatisticsManager();
91 
92  /**
93  * adds a variable to observe (on the window) and measure the value
94  * @param observedValue the value to observe.
95  * @param measureName the name of the measured value
96  * @param mode the mode of measure
97  * @param stepSpan in most cases the stepSpan is important to get
98  * the measured value of a number of steps, like AVG:
99  * if stepSpan = 0, AVG is calculated over all steps
100  * if stepSpan = n, AVG is calculated over the LAST n steps
101  * The same counts for all the other MeasureModes.
102  * @param additionalParam is used for example for mode PEAK, the param is the limit value,
103  * all values minus limit are displayed, values below the limit are set to 0.
104  * In CONV mode (test the convergence), this value is the epsilon criteria.
105  * @return the object StatisticMeasure. Use addMeasure(...) instead of getMeasure(...) to
106  * obtain the value adress of the calculated statistic.
107  * @see StatisticTools
108  * @see StatisticMeasure
109  */
110  virtual StatisticMeasure* getMeasure( double& observedValue, const char* measureName, MeasureMode mode, long stepSpan, double additionalParam =0);
111 
112  /**
113  * adds a variable to observe (on the window) and measure the value
114  * @param observedValue the value to observe.
115  * @param measureName the name of the measured value
116  * @param mode the mode of measure
117  * @param stepSpan in most cases the stepSpan is important to get
118  * the measured value of a number of steps, like AVG:
119  * if stepSpan = 0, AVG is calculated over all steps
120  * if stepSpan = n, AVG is calculated over the LAST n steps
121  * The same counts for all the other MeasureModes.
122  * @param additionalParam is used for example for mode PEAK, the param is the limit value,
123  * all values minus limit are displayed, values below the limit are set to 0.
124  * In CONV mode (test the convergence), this value is the epsilon criteria.
125  * @return the object StatisticMeasure. Use addMeasure(...) instead of getMeasure(...) to
126  * obtain the value adress of the calculated statistic.
127  * @see StatisticTools
128  * @see StatisticMeasure
129  */
130  virtual double& addMeasure( double& observedValue, const char* measureName, MeasureMode mode, long stepSpan, double additionalParam =0);
131 
132  /**
133  * You can add another abstract measure you like. in some cases (e.g. complex
134  * measures) it is better to let the measure decide how it likes to be initialized
135  * @param measure the measure to add
136  */
137  virtual double& addMeasure(AbstractMeasure* measure);
138 
139  /**
140  * You can add another abstract measure you like. in some cases (e.g. complex
141  * measures) it is better to let the measure decide how it likes to be initialized
142  * With this method you can add a list of AbstractMeasures.
143  * @param measureList the list of measures to add
144  */
145  virtual double& addMeasureList(std::list<AbstractMeasure*> measureList);
146 
147  /**
148  * You can add another abstract measure you like. in some cases (e.g. complex
149  * measures) it is better to let the measure decide how it likes to be initialized
150  * With this method you can add a list of AbstractMeasures.
151  * @param measureList the list of measures to add
152  */
153  virtual double& addMeasureList(std::list<ComplexMeasure*> measureList);
154 
155 
156  /**
157  * You can add another abstract measure you like. in some cases (e.g. complex
158  * measures) it is better to let the measure decide how it likes to be initialized
159  * With this method you can add a list of AbstractMeasures.
160  * @param measureList the list of measures to add
161  */
162  virtual double& addMeasureList(std::list<StatisticMeasure*> measureList);
163 
164 
165  /**
166  * starts the measure at a specific time. This is useful if there are
167  * values that have to be ignored at simulation start.
168  * @param step number of steps (normally simsteps) to wait for beginning the measures
169  */
170  virtual void beginMeasureAt(long step) { statTool->beginMeasureAt(step);}
171 
172  /**
173  * Tells you wether the measures have already been started.
174  */
175  virtual bool measureStarted() { return statTool->measureStarted(); }
176 
177 
178  /**
179  * CALLBACKABLE INTERFACE
180  *
181  * this method is invoked when a callback is done from the class where this
182  * class is for callback registered, it is overwritten
183  */
185 
186 
188 
189  /** searches for the measure with the given name and returns it windowstatistics
190  (measure and graphics together)
191  @return 0 if not measure was found
192  */
193  virtual WindowStatistic* getMeasureWS(const std::string& measureName);
194 
195 
196  virtual void setColor(const Color& color){ textColor = color;}
197  virtual void setFontsize(int size){fontsize = size, yOffset = 1.2*size;}
198 
199 protected:
200 
201 /// the struct list which holds the measures and the appropiate text
202  std::list<WindowStatistic*> windowStatisticList;
203 
205 
206  // position of first graphical text
210  float yOffset;
211 
212  // graphical node
213  osg::Geode* geode;
214 
215  // default text properties
216  osgText::Font* font;
218  int fontsize;
219 
220 };
221 
222 
223 }
224 
225 #endif
virtual double & addMeasure(double &observedValue, const char *measureName, MeasureMode mode, long stepSpan, double additionalParam=0)
adds a variable to observe (on the window) and measure the value
Definition: hudstatistics.cpp:86
std::list< WindowStatistic * > windowStatisticList
the struct list which holds the measures and the appropiate text
Definition: hudstatistics.h:202
virtual bool measureStarted()
Tells you wether the measures have already been started.
Definition: statistictools.h:126
Interface class for a class which wants to be callback on a certain action.
Definition: callbackable.h:39
MeasureMode
usage of the statistictools with different measure modes (examples):
Definition: measuremodes.h:53
virtual StatisticTools * getStatisticTools()
Definition: hudstatistics.h:187
virtual void doOnCallBack(BackCaller *source, BackCaller::CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
CALLBACKABLE INTERFACE.
Definition: hudstatistics.cpp:147
virtual void beginMeasureAt(long step)
starts the measure at a specific time.
Definition: hudstatistics.h:170
virtual ~HUDStatisticsManager()
Definition: hudstatistics.cpp:56
osgText::Font * font
Definition: hudstatistics.h:216
float zInitPosition
Definition: hudstatistics.h:209
manages all the stuff displaying statistics on the graphics window.
Definition: hudstatistics.h:60
virtual WindowStatistic * getMeasureWS(const std::string &measureName)
searches for the measure with the given name and returns it windowstatistics (measure and graphics to...
Definition: hudstatistics.cpp:137
Class used by StatisticTools.
Definition: statisticmeasure.h:34
virtual AbstractMeasure * getMeasure()
Definition: hudstatistics.h:74
static const CallbackableType DEFAULT_CALLBACKABLE_TYPE
This is the default Callbackable type.
Definition: backcaller.h:51
unsigned long CallbackableType
Definition: backcaller.h:45
virtual double & addMeasureList(std::list< AbstractMeasure * > measureList)
You can add another abstract measure you like.
Definition: hudstatistics.cpp:116
float yOffset
Definition: hudstatistics.h:210
virtual StatisticMeasure * getMeasure(double &observedValue, const char *measureName, MeasureMode mode, long stepSpan, double additionalParam=0)
adds a variable to observe (on the window) and measure the value
Definition: hudstatistics.cpp:61
int fontsize
Definition: hudstatistics.h:218
WindowStatistic(AbstractMeasure *measure, osgText::Text *text)
Definition: hudstatistics.h:69
virtual ~WindowStatistic()
Definition: hudstatistics.h:72
virtual osgText::Text * getText()
Definition: hudstatistics.h:76
Definition: color.h:32
virtual bool measureStarted()
Tells you wether the measures have already been started.
Definition: hudstatistics.h:175
virtual void setColor(const Color &color)
Definition: hudstatistics.h:196
osg::Geode * geode
Definition: hudstatistics.h:213
Nested class WindowStatistic, which puts the measure and the graphics text together.
Definition: hudstatistics.h:66
float yInitPosition
Definition: hudstatistics.h:208
TODO: add possibility to pass description of a measure.
Definition: statistictools.h:45
float xInitPosition
Definition: hudstatistics.h:207
Class prototype which provides functions to handle callbackable classes.
Definition: backcaller.h:42
virtual void beginMeasureAt(long step)
starts the measure at a specific time.
Definition: statistictools.cpp:90
HUDStatisticsManager(osg::Geode *geode, osgText::Font *font, int ypos)
creates the HUDStatisticsManager, normally done by class Base.
Definition: hudstatistics.cpp:46
Color textColor
Definition: hudstatistics.h:217
StatisticTools * statTool
Definition: hudstatistics.h:204
virtual void setFontsize(int size)
Definition: hudstatistics.h:197
Class used by StatisticTools.
Definition: abstractmeasure.h:38