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

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7