Robot Simulator of the Robotics Group for Self-Organization of Control: base.h Source File

# base.h

Go to the documentation of this file.

    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 __BASE_H
    00025 #define __BASE_H
    00026
    00027 #include <ode-dbl/ode.h>
    00028 #include <osg/Transform>
    00029 #include <osgText/Text>
    00030
    00031 #include "osghandle.h"
    00032 #include "odehandle.h"
    00033
    00034 #include "hudstatistics.h"
    00035 #include <selforg/configurable.h>
    00036
    00037 namespace osgShadow
    00038 {
    00039   class ShadowedScene;
    00040 }
    00041
    00042 namespace lpzrobots
    00043 {
    00044
    00045   class MoveEarthySkyWithEyePointTransform : public osg::Transform
    00046   {
    00047     public:
    00048       /** Get the transformation matrix which moves from local coords to world coords.*/
    00049       virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
    00050
    00051       /** Get the transformation matrix which moves from world coords to local coords.*/
    00052       virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
    00053   };
    00054
    00055   class Base : public Configurable
    00056   {
    00057   public:
    00058     Base(const std::string& caption="LpzRobots Simulator (Martius et al)");
    00059
    00060     static const int PHYSICS_CALLBACKABLE = 1; //!< called each ode/physics step
    00061     static const int GRAPHICS_CALLBACKABLE = 2; //!< called each osg/draw step
    00062
    00063     /// create the ground plane
    00064     virtual void makePhysicsScene();
    00065     /** creates the base scene graph with world, sky and floor and shadow and HUD
    00066         and stores it in scene
    00067      */
    00068     virtual void makeScene(OsgScene* scene, const OsgConfig& config);
    00069     virtual osg::Node* makeSky(const OsgConfig& config);
    00070     virtual osg::Node* makeGround(const OsgConfig& config);
    00071     /** creates hud and is supposed to return the camera to it and
    00072         adds the geode of the hud to the scene */
    00073     virtual osg::Node* createHUD(OsgScene* scene, const OsgConfig& config);
    00074     virtual void createHUDManager(osg::Geode* geode, osgText::Font* font);
    00075     /// adds light to the node
    00076     virtual void makeLights(osg::Group* node, const OsgConfig& config);
    00077
    00078     /** Shadow types:
    00079      * 1 - ShadowVolume
    00080      * 2 - ShadowTextue
    00081      * 3 - ParallelSplitShadowMap
    00082      * 4 - SoftShadowMap
    00083      * 5 - ShadowMap
    00084      */
    00085     virtual osgShadow::ShadowedScene* createShadowedScene(osg::Node* sceneToShadow, osg::LightSource* lightSource, int shadowType);
    00086
    00087     virtual void setGroundTexture(const char* filename) {
    00088       this->groundTexture = filename;
    00089     }
    00090
    00091     /// sets the cpation that is printed at the right of the status line
    00092     virtual void setCaption(const std::string& caption);
    00093
    00094     /// sets the title that is printed in the center of the status line
    00095     virtual void setTitle(const std::string& title);
    00096
    00097     /**
    00098      * Create HUDStatisticsManager and register it for being called back every step.
    00099      * But do not display if the system is initialised with -nographics.
    00100      * @return the actual HUDStatisticsManager
    00101      */
    00102     virtual HUDStatisticsManager* getHUDSM();
    00103
    00104     virtual ~Base();
    00105
    00106   protected:
    00107     virtual void setTimeStats(double time, double realtimefactor,
    00108                               double truerealtimefactor,bool pause);
    00109
    00110     /**
    00111      * Changes the currently used shadow technique.
    00112      * The switch is realized between:
    00113      * 0 - NoShadow
    00114      * 3 - ParallelSplitShadowMap
    00115      * 4 - SoftShadowMap
    00116      * 5 - ShadowMap (simple)
    00117      * Currently not supported by this function:
    00118      * 1 - ShadowVolume
    00119      * 2 - ShadowTextue
    00120      */
    00121     virtual void changeShadowTechnique();
    00122
    00123     /// deletes the stuff that is created on makescene and the like
    00124     virtual void base_close();
    00125
    00126     dGeomID ground;
    00127
    00128
    00129     OsgHandle osgHandle;
    00130     // ODE globals
    00131     OdeHandle odeHandle;
    00132     std::string caption;
    00133     std::string title;
    00134     std::string groundTexture;
    00135
    00136     osg::Group* dummy;
    00137
    00138     osg::Node* hud;
    00139     osgText::Text* timestats;
    00140     osgText::Text* captionline;
    00141     osgText::Text* titleline;
    00142
    00143     Primitive* plane;
    00144
    00145     /// this manager provides methods for displaying statistics on the graphical window!
    00146     HUDStatisticsManager* hUDStatisticsManager;
    00147
    00148     int ReceivesShadowTraversalMask;
    00149     int CastsShadowTraversalMask;
    00150
    00151     // the types are double because they are configurable and stored to the cfg file
    00152     // int shadow;     // set by child class Simulation, now found in OsgHandle
    00153     int shadowTexSize;  // set by child class Simulation
    00154     bool useNVidia;      // unused: if false use ATI Radeon!
    00155
    00156
    00157   public:
    00158     // Helper
    00159     /// returns the index+1 if the list contains the given string or 0 if not
    00160     static int contains(char **list, int len,  const char *str);
    00161
    00162   };
    00163 }
    00164
    00165 #endif