00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 LpzRobots development team * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00005 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00006 * Ralf Der <ralfder at mis dot mpg dot de> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 * * 00023 ***************************************************************************/ 00024 #ifndef __HUD_STATISTICS_H 00025 #define __HUD_STATISTICS_H 00026 00027 #include <selforg/statistictools.h> 00028 00029 #include "color.h" 00030 00031 /* forward declaration block */ 00032 namespace osgText { 00033 class Text; 00034 class Font; 00035 } 00036 00037 namespace osg { 00038 class Geode; 00039 } 00040 00041 /* end of forward declaration */ 00042 00043 namespace lpzrobots { 00044 00045 /** 00046 * manages all the stuff displaying statistics on the graphics window. 00047 * This is a experimental version, so do not to be afraid changing this crazy 00048 * code. 00049 * 00050 * This class uses the implementation of the class StatisticTools, which is 00051 * generalized to make nice statistics. Instead of passing the values to the 00052 * guilogger (INSPECTABLE interface), we simply diplay this values on the graphics 00053 * window. 00054 * 00055 * So how it works: 00056 * - overwriting the method getMeasure gives us the ability to create the needed text 00057 * object, then storing it in a class named WindowStatistic 00058 * (which is stored in the windowStatisticList). 00059 */ 00060 class HUDStatisticsManager : public Callbackable { 00061 00062 public: 00063 /** 00064 * Nested class WindowStatistic, which puts the measure and the graphics text together. 00065 */ 00066 class WindowStatistic { 00067 public: 00068 00069 WindowStatistic(AbstractMeasure* measure, osgText::Text* text) : measure(measure), 00070 text(text) {} 00071 00072 virtual ~WindowStatistic() {} 00073 00074 virtual AbstractMeasure* getMeasure() { return measure; } 00075 00076 virtual osgText::Text* getText() { return text; } 00077 00078 private: 00079 AbstractMeasure* measure; 00080 osgText::Text* text; 00081 }; 00082 00083 public: 00084 /** 00085 * creates the HUDStatisticsManager, normally done by class Base. 00086 * @param geode this is the graphical node at wich the text objects are hooked in. 00087 */ 00088 HUDStatisticsManager(osg::Geode* geode, osgText::Font* font); 00089 00090 virtual ~HUDStatisticsManager(); 00091 00092 /** 00093 * adds a variable to observe (on the window) and measure the value 00094 * @param observedValue the value to observe. 00095 * @param measureName the name of the measured value 00096 * @param mode the mode of measure 00097 * @param stepSpan in most cases the stepSpan is important to get 00098 * the measured value of a number of steps, like AVG: 00099 * if stepSpan = 0, AVG is calculated over all steps 00100 * if stepSpan = n, AVG is calculated over the LAST n steps 00101 * The same counts for all the other MeasureModes. 00102 * @param additionalParam is used for example for mode PEAK, the param is the limit value, 00103 * all values minus limit are displayed, values below the limit are set to 0. 00104 * In CONV mode (test the convergence), this value is the epsilon criteria. 00105 * @return the object StatisticMeasure. Use addMeasure(...) instead of getMeasure(...) to 00106 * obtain the value adress of the calculated statistic. 00107 * @see StatisticTools 00108 * @see StatisticMeasure 00109 */ 00110 virtual StatisticMeasure* getMeasure( double& observedValue, const char* measureName, MeasureMode mode, long stepSpan, double additionalParam =0); 00111 00112 /** 00113 * adds a variable to observe (on the window) and measure the value 00114 * @param observedValue the value to observe. 00115 * @param measureName the name of the measured value 00116 * @param mode the mode of measure 00117 * @param stepSpan in most cases the stepSpan is important to get 00118 * the measured value of a number of steps, like AVG: 00119 * if stepSpan = 0, AVG is calculated over all steps 00120 * if stepSpan = n, AVG is calculated over the LAST n steps 00121 * The same counts for all the other MeasureModes. 00122 * @param additionalParam is used for example for mode PEAK, the param is the limit value, 00123 * all values minus limit are displayed, values below the limit are set to 0. 00124 * In CONV mode (test the convergence), this value is the epsilon criteria. 00125 * @return the object StatisticMeasure. Use addMeasure(...) instead of getMeasure(...) to 00126 * obtain the value adress of the calculated statistic. 00127 * @see StatisticTools 00128 * @see StatisticMeasure 00129 */ 00130 virtual double& addMeasure( double& observedValue, const char* measureName, MeasureMode mode, long stepSpan, double additionalParam =0); 00131 00132 /** 00133 * You can add another abstract measure you like. in some cases (e.g. complex 00134 * measures) it is better to let the measure decide how it likes to be initialized 00135 * @param measure the measure to add 00136 */ 00137 virtual double& addMeasure(AbstractMeasure* measure); 00138 00139 /** 00140 * You can add another abstract measure you like. in some cases (e.g. complex 00141 * measures) it is better to let the measure decide how it likes to be initialized 00142 * With this method you can add a list of AbstractMeasures. 00143 * @param measureList the list of measures to add 00144 */ 00145 virtual double& addMeasureList(std::list<AbstractMeasure*> measureList); 00146 00147 /** 00148 * You can add another abstract measure you like. in some cases (e.g. complex 00149 * measures) it is better to let the measure decide how it likes to be initialized 00150 * With this method you can add a list of AbstractMeasures. 00151 * @param measureList the list of measures to add 00152 */ 00153 virtual double& addMeasureList(std::list<ComplexMeasure*> measureList); 00154 00155 00156 /** 00157 * You can add another abstract measure you like. in some cases (e.g. complex 00158 * measures) it is better to let the measure decide how it likes to be initialized 00159 * With this method you can add a list of AbstractMeasures. 00160 * @param measureList the list of measures to add 00161 */ 00162 virtual double& addMeasureList(std::list<StatisticMeasure*> measureList); 00163 00164 00165 /** 00166 * starts the measure at a specific time. This is useful if there are 00167 * values that have to be ignored at simulation start. 00168 * @param step number of steps (normally simsteps) to wait for beginning the measures 00169 */ 00170 virtual void beginMeasureAt(long step) { statTool->beginMeasureAt(step);} 00171 00172 /** 00173 * Tells you wether the measures have already been started. 00174 */ 00175 virtual bool measureStarted() { return statTool->measureStarted(); } 00176 00177 00178 /** 00179 * CALLBACKABLE INTERFACE 00180 * 00181 * this method is invoked when a callback is done from the class where this 00182 * class is for callback registered, it is overwritten 00183 */ 00184 virtual void doOnCallBack(BackCaller* source, BackCaller::CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE); 00185 00186 00187 virtual StatisticTools* getStatisticTools() { return statTool; } 00188 00189 /** searches for the measure with the given name and returns it windowstatistics 00190 (measure and graphics together) 00191 @return 0 if not measure was found 00192 */ 00193 virtual WindowStatistic* getMeasureWS(const std::string& measureName); 00194 00195 00196 virtual void setColor(const Color& color){ textColor = color;} 00197 virtual void setFontsize(int size){fontsize = size;} 00198 00199 protected: 00200 00201 /// the struct list which holds the measures and the appropiate text 00202 std::list<WindowStatistic*> windowStatisticList; 00203 00204 StatisticTools* statTool; 00205 00206 // position of first graphical text 00207 float xInitPosition; 00208 float yInitPosition; 00209 float zInitPosition; 00210 float yOffset; 00211 00212 // graphical node 00213 osg::Geode* geode; 00214 00215 // default text properties 00216 osgText::Font* font; 00217 Color textColor; 00218 int fontsize; 00219 00220 }; 00221 00222 00223 } 00224 00225 #endif