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

Generated on Tue Sep 16 22:00:22 2008 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7