hudstatistics.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *    frankguettler@gmx.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  *  windowstatistics provides cool stuff for displaying statistics on the  *
00025  *  graphics window.                                                       *
00026  *                                                                         *
00027  *   $Log: hudstatistics.h,v $
00028  *   Revision 1.8  2010/03/17 09:33:16  martius
00029  *   removed memory leaks and some small bugs
00030  *   valgrind suppression file is updated
00031  *
00032  *   Revision 1.7  2010/01/27 10:14:46  martius
00033  *   moved WindowStatistics up and added function to obtain it
00034  *
00035  *   Revision 1.6  2009/09/03 11:37:06  martius
00036  *   color and fontsize are setable
00037  *
00038  *   Revision 1.5  2009/08/10 07:45:54  guettler
00039  *   uses new BackCaller implementation
00040  *
00041  *   Revision 1.4  2008/01/17 09:55:55  der
00042  *   methods added for adding std::list<AbstractMeasure*> to the HUD
00043  *
00044  *   Revision 1.3  2007/12/06 10:02:49  der
00045  *   abstractground: returns now cornerpoints
00046  *   abstractobstacle: is now trackable
00047  *   hudstatistics: supports now AbstractmMeasure
00048  *
00049  *   Revision 1.2  2007/09/28 12:31:49  robot3
00050  *   The HUDSM is not anymore deduced from StatisticalTools, so the statistics
00051  *   can be updated independently from the HUD
00052  *   addPhysicsCallbackable and addGraphicsCallbackable now exists in Simulation
00053  *
00054  *   Revision 1.1  2007/09/28 10:24:05  robot3
00055  *   The WindowStatisticsManager is now called HUDStatisticsManager
00056  *
00057  *   Revision 1.4  2007/09/28 10:08:49  robot3
00058  *   fixed memory bugs, statistics are from now on aligned right
00059  *
00060  *   Revision 1.3  2007/09/28 09:15:25  robot3
00061  *   extended comments
00062  *
00063  *   Revision 1.2  2007/09/28 08:47:29  robot3
00064  *   corrected some memory bug (3 still remaining)
00065  *
00066  *   Revision 1.1  2007/09/27 10:48:13  robot3
00067  *   first version of the WSM
00068  *
00069  *                                                                         *
00070  ***************************************************************************/
00071 #ifndef __HUD_STATISTICS_H
00072 #define __HUD_STATISTICS_H
00073 
00074 #import <selforg/statistictools.h>
00075 
00076 #include "color.h"
00077 
00078 /* forward declaration block */
00079 namespace osgText {
00080 class Text;
00081 class Font;
00082 }
00083 
00084 namespace osg {
00085 class Geode;
00086 }
00087 
00088 /* end of forward declaration */
00089 
00090 namespace lpzrobots {
00091 
00092 /**
00093  * manages all the stuff displaying statistics on the graphics window.
00094  * This is a experimental version, so do not to be afraid changing this crazy
00095  * code.
00096  *
00097  * This class uses the implementation of the class StatisticTools, which is
00098  * generalized to make nice statistics. Instead of passing the values to the
00099  * guilogger (INSPECTABLE interface), we simply diplay this values on the graphics
00100  * window.
00101  *
00102  * So how it works:
00103  * - overwriting the method getMeasure gives us the ability to create the needed text
00104  *   object, then storing it in a class named WindowStatistic
00105  *   (which is stored in the windowStatisticList).
00106  */
00107 class HUDStatisticsManager : public Callbackable {
00108 
00109 public:
00110   /**
00111    * Nested class WindowStatistic, which puts the measure and the graphics text together.
00112    */
00113   class WindowStatistic {
00114   public:
00115 
00116     WindowStatistic(AbstractMeasure* measure, osgText::Text* text) : measure(measure),
00117       text(text) {}
00118 
00119     virtual ~WindowStatistic() {}
00120 
00121     virtual AbstractMeasure* getMeasure() { return measure; }
00122 
00123     virtual osgText::Text* getText() { return text; }
00124 
00125   private:
00126     AbstractMeasure* measure;
00127     osgText::Text* text;
00128   };
00129 
00130 public:
00131   /**
00132    * creates the HUDStatisticsManager, normally done by class Base.
00133    * @param geode this is the graphical node at wich the text objects are hooked in.
00134    */
00135   HUDStatisticsManager(osg::Geode* geode, osgText::Font* font);
00136 
00137   virtual ~HUDStatisticsManager();
00138 
00139         /**
00140          * adds a variable to observe (on the window) and measure the value
00141          * @param observedValue    the value to observe.
00142          * @param measureName      the name of the measured value
00143          * @param mode             the mode of measure
00144          * @param stepSpan         in most cases the stepSpan is important to get
00145          * the measured value of a number of steps, like AVG:
00146          * if stepSpan = 0, AVG is calculated over all steps
00147          * if stepSpan = n, AVG is calculated over the LAST n steps
00148          * The same counts for all the other MeasureModes.
00149          * @param additionalParam  is used for example for mode PEAK, the param is the limit value,
00150          * all values minus limit are displayed, values below the limit are set to 0.
00151          * In CONV mode (test the convergence), this value is the epsilon criteria.
00152          * @return the object StatisticMeasure. Use addMeasure(...) instead of getMeasure(...) to
00153          * obtain the value adress of the calculated statistic.
00154          * @see StatisticTools
00155          * @see StatisticMeasure
00156          */
00157   virtual StatisticMeasure* getMeasure( double& observedValue, const char* measureName, MeasureMode mode, long stepSpan, double additionalParam =0);
00158 
00159         /**
00160          * adds a variable to observe (on the window) and measure the value
00161          * @param observedValue    the value to observe.
00162          * @param measureName      the name of the measured value
00163          * @param mode             the mode of measure
00164          * @param stepSpan         in most cases the stepSpan is important to get
00165          * the measured value of a number of steps, like AVG:
00166          * if stepSpan = 0, AVG is calculated over all steps
00167          * if stepSpan = n, AVG is calculated over the LAST n steps
00168          * The same counts for all the other MeasureModes.
00169          * @param additionalParam  is used for example for mode PEAK, the param is the limit value,
00170          * all values minus limit are displayed, values below the limit are set to 0.
00171          * In CONV mode (test the convergence), this value is the epsilon criteria.
00172          * @return the object StatisticMeasure. Use addMeasure(...) instead of getMeasure(...) to
00173          * obtain the value adress of the calculated statistic.
00174          * @see StatisticTools
00175          * @see StatisticMeasure
00176          */
00177   virtual double& addMeasure( double& observedValue, const char* measureName, MeasureMode mode, long stepSpan, double additionalParam =0);
00178   
00179     /**
00180    * You can add another abstract measure you like. in some cases (e.g. complex
00181    * measures) it is better to let the measure decide how it likes to be initialized
00182    * @param measure the measure to add
00183    */
00184   virtual double& addMeasure(AbstractMeasure* measure);
00185   
00186   /**
00187    * You can add another abstract measure you like. in some cases (e.g. complex
00188    * measures) it is better to let the measure decide how it likes to be initialized
00189    * With this method you can add a list of AbstractMeasures.
00190    * @param measureList the list of measures to add
00191    */
00192   virtual double& addMeasureList(std::list<AbstractMeasure*> measureList);
00193 
00194     /**
00195    * You can add another abstract measure you like. in some cases (e.g. complex
00196    * measures) it is better to let the measure decide how it likes to be initialized
00197    * With this method you can add a list of AbstractMeasures.
00198    * @param measureList the list of measures to add
00199    */
00200   virtual double& addMeasureList(std::list<ComplexMeasure*> measureList);
00201   
00202   
00203       /**
00204    * You can add another abstract measure you like. in some cases (e.g. complex
00205    * measures) it is better to let the measure decide how it likes to be initialized
00206    * With this method you can add a list of AbstractMeasures.
00207    * @param measureList the list of measures to add
00208    */
00209   virtual double& addMeasureList(std::list<StatisticMeasure*> measureList);
00210   
00211   
00212         /**
00213          * starts the measure at a specific time. This is useful if there are
00214          * values that have to be ignored at simulation start.
00215          * @param step number of steps (normally simsteps) to wait for beginning the measures
00216          */
00217   virtual void beginMeasureAt(long step) { statTool->beginMeasureAt(step);}
00218 
00219   /**
00220    * Tells you wether the measures have already been started.
00221    */
00222   virtual bool measureStarted() { return statTool->measureStarted(); }
00223 
00224 
00225         /**
00226          * CALLBACKABLE INTERFACE
00227          *
00228          *      this method is invoked when a callback is done from the class where this
00229          * class is for callback registered, it is overwritten
00230          */
00231   virtual void doOnCallBack(BackCaller* source, BackCaller::CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
00232 
00233 
00234   virtual StatisticTools* getStatisticTools() { return statTool; }
00235 
00236   /** searches for the measure with the given name and returns it windowstatistics
00237       (measure and graphics together)
00238       @return 0 if not measure was found 
00239    */
00240   virtual WindowStatistic* getMeasureWS(const std::string& measureName);
00241 
00242 
00243   virtual void setColor(const Color& color){ textColor = color;}
00244   virtual void setFontsize(int size){fontsize = size;}
00245 
00246 protected:
00247 
00248 /// the struct list which holds the measures and the appropiate text
00249   std::list<WindowStatistic*> windowStatisticList;
00250 
00251   StatisticTools* statTool;
00252 
00253   // position of first graphical text
00254   float xInitPosition;
00255   float yInitPosition;
00256   float zInitPosition;
00257   float yOffset;
00258 
00259   // graphical node
00260   osg::Geode* geode;
00261 
00262   // default text properties
00263   osgText::Font* font;
00264   Color textColor;
00265   int fontsize;
00266 
00267 };
00268 
00269 
00270 }
00271 
00272 #endif
Generated on Fri Nov 4 10:59:38 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3