base.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  *  base.h provides osg stuff for basic environment with sky and so on.    *
00025  *                                                                         *
00026  *   $Log: base.h,v $
00027  *   Revision 1.29  2010/03/17 09:33:16  martius
00028  *   removed memory leaks and some small bugs
00029  *   valgrind suppression file is updated
00030  *
00031  *   Revision 1.28  2010/03/16 15:47:46  martius
00032  *   osgHandle has now substructures osgConfig and osgScene
00033  *    that minimized amount of redundant data (this causes a lot of changes)
00034  *   Scenegraph is slightly changed. There is a world and a world_noshadow now.
00035  *    Main idea is to have a world without shadow all the time avaiable for the
00036  *    Robot cameras (since they do not see the right shadow for some reason)
00037  *   tidied up old files
00038  *
00039  *   Revision 1.27  2010/03/09 11:53:41  martius
00040  *   renamed globally ode to ode-dbl
00041  *
00042  *   Revision 1.26  2010/03/07 22:39:08  guettler
00043  *   moved shadow to OsgHandle.shadowType (TODO: move it to OsgConfig)
00044  *
00045  *   Revision 1.25  2010/03/05 14:32:55  martius
00046  *   camera sensor added
00047  *   for that the scenegraph structure was changed into root, world, scene
00048  *   camera does not work with shadows
00049  *   works with newest version of ode (0.11)
00050  *
00051  *   Revision 1.24  2009/11/26 10:06:45  martius
00052  *   added createHUDManager function
00053  *
00054  *   Revision 1.23  2009/09/03 12:53:25  guettler
00055  *   reverted changes of revision 1.37:
00056  *   - getHUDSM is called without calling createHUDSM before
00057  *     if simulation is started with -nographics
00058  *   FIX: createHUDSM calls now getHUDSM (fix of HUDSM was not complete)
00059  *
00060  *   Revision 1.22  2009/08/10 14:55:13  der
00061  *   shadowTexSize and shadow are integer
00062  *
00063  *   Revision 1.21  2009/08/10 08:40:10  guettler
00064  *   changed g&uumlettler to guettler
00065  *
00066  *   Revision 1.20  2009/08/10 08:37:17  guettler
00067  *   try to set guettler in caption to correct characters
00068  *
00069  *   Revision 1.19  2009/08/10 07:54:32  guettler
00070  *   - uses new BackCaller implementation
00071  *   - bugfix: avoid crash if noGraphics when getting HUDSM
00072  *
00073  *   Revision 1.18  2009/08/07 13:27:18  martius
00074  *   makePhysicalScene to create phyiscal scene independent of graphical scene
00075  *     (to cope with new noGraphics implementation)
00076  *
00077  *   Revision 1.17  2009/08/05 23:23:42  martius
00078  *   corrected coding in "Guettler"
00079  *
00080  *   Revision 1.16  2009/07/30 12:09:12  guettler
00081  *   commented out unused variables
00082  *
00083  *   Revision 1.15  2009/03/31 15:45:50  martius
00084  *   caption is a std::string and can be changed on-line
00085  *
00086  *   Revision 1.14  2009/03/27 06:21:31  guettler
00087  *   CTRL +S  changes now the shadow type in the simulation: cleaned up the code
00088  *
00089  *   Revision 1.13  2009/03/25 15:44:23  guettler
00090  *   ParallelSplitShadowMap: corrected light direction (using directional light), complete ground is now shadowed
00091  *
00092  *   Revision 1.12  2009/01/20 17:27:34  martius
00093  *   texture for background changeable from outside
00094  *
00095  *   Revision 1.11  2008/09/11 15:24:01  martius
00096  *   motioncallback resurrected
00097  *   noContact substance
00098  *   use slider center of the connecting objects for slider drawing
00099  *
00100  *   Revision 1.10  2008/05/05 09:35:35  guettler
00101  *   hud now displays if in pause mode
00102  *
00103  *   Revision 1.9  2008/04/23 07:17:16  martius
00104  *   makefiles cleaned
00105  *   new also true realtime factor displayed,
00106  *    warning if out of sync
00107  *   drawinterval in full speed is 10 frames, independent of the speed
00108  *
00109  *   Revision 1.8  2008/04/17 15:59:00  martius
00110  *   OSG2 port finished
00111  *
00112  *   Revision 1.7.2.5  2008/04/11 13:46:50  martius
00113  *   quickMP multithreading included
00114  *
00115  *   Revision 1.7.2.4  2008/04/11 10:41:35  martius
00116  *   config file added
00117  *
00118  *   Revision 1.7.2.3  2008/04/09 14:25:35  martius
00119  *   shadow cmd line option
00120  *
00121  *   Revision 1.7.2.2  2008/04/09 13:57:59  guettler
00122  *   New ShadowTechnique added.
00123  *
00124  *   Revision 1.7.2.1  2008/04/09 10:18:41  martius
00125  *   fullscreen and window options done
00126  *   fonts on hud changed
00127  *
00128  *   Revision 1.7  2007/09/28 12:31:49  robot3
00129  *   The HUDSM is not anymore deduced from StatisticalTools, so the statistics
00130  *   can be updated independently from the HUD
00131  *   addPhysicsCallbackable and addGraphicsCallbackable now exists in Simulation
00132  *
00133  *   Revision 1.6  2007/09/28 10:24:05  robot3
00134  *   The WindowStatisticsManager is now called HUDStatisticsManager
00135  *
00136  *   Revision 1.5  2007/09/27 10:47:04  robot3
00137  *   mathutils: moved abs to selforg/stl_adds.h
00138  *   simulation,base: added callbackable support,
00139  *   added WSM (HUDStatisticsManager) funtionality
00140  *
00141  *   Revision 1.4  2007/08/29 13:07:48  martius
00142  *   added HUD
00143  *
00144  *   Revision 1.3  2006/09/20 15:30:47  martius
00145  *   shadowsize, light
00146  *
00147  *   Revision 1.2  2006/07/14 12:23:33  martius
00148  *   selforg becomes HEAD
00149  *
00150  *   Revision 1.1.2.7  2006/06/29 16:35:56  robot3
00151  *   includes cleared up
00152  *
00153  *   Revision 1.1.2.6  2006/05/28 22:14:56  martius
00154  *   heightfield included
00155  *
00156  *   Revision 1.1.2.5  2006/05/18 11:45:51  robot3
00157  *   -shadowing the normal scene integrated (first version)
00158  *   -note that there is a bug that the shadow disappears
00159  *    after some time (e.g. 60 minutes)
00160  *
00161  *   Revision 1.1.2.4  2006/01/31 15:45:02  martius
00162  *   virtual destructor
00163  *
00164  *   Revision 1.1.2.3  2006/01/12 14:21:00  martius
00165  *   drawmode, material
00166  *
00167  *   Revision 1.1.2.2  2005/12/09 16:54:16  martius
00168  *   camera is woring now
00169  *
00170  *   Revision 1.1.2.1  2005/12/06 17:40:59  martius
00171  *   base class for simulation
00172  *
00173  *                                                                 *
00174  ***************************************************************************/
00175 #ifndef __BASE_H
00176 #define __BASE_H
00177 
00178 #include <ode-dbl/ode.h>
00179 #include <osg/Transform>
00180 #include <osgText/Text>
00181 
00182 #include "osghandle.h"
00183 #include "odehandle.h"
00184 
00185 #include "hudstatistics.h"
00186 #include <selforg/backcaller.h>
00187 
00188 namespace osgShadow
00189 {
00190   class ShadowedScene;
00191 }
00192 
00193 namespace lpzrobots
00194 {
00195 
00196   class MoveEarthySkyWithEyePointTransform : public osg::Transform
00197   {
00198     public:
00199       /** Get the transformation matrix which moves from local coords to world coords.*/
00200       virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
00201 
00202       /** Get the transformation matrix which moves from world coords to local coords.*/
00203       virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
00204   };
00205 
00206   class Base : public BackCaller
00207   {
00208   public:
00209     Base(const std::string& caption="lpzrobots Simulator          Martius, Der, Guettler");
00210 
00211     static const int PHYSICS_CALLBACKABLE = 1; //!< called each ode/physics step
00212     static const int GRAPHICS_CALLBACKABLE = 2; //!< called each osg/draw step
00213 
00214     /// create the ground plane
00215     virtual void makePhysicsScene(); 
00216     /** creates the base scene graph with world, sky and floor and shadow and HUD
00217         and stores it in scene
00218      */
00219     virtual void makeScene(OsgScene* scene);
00220     virtual osg::Node* makeSky();
00221     virtual osg::Node* makeGround();
00222     virtual osg::Node* createHUD();
00223     virtual void createHUDManager(osg::Geode* geode, osgText::Font* font);
00224     virtual osg::LightSource* makeLights(osg::StateSet* stateset);
00225 
00226     /** Shadow types:
00227      * 1 - ShadowVolume
00228      * 2 - ShadowTextue
00229      * 3 - ParallelSplitShadowMap
00230      * 4 - SoftShadowMap
00231      * 5 - ShadowMap
00232      */
00233     virtual osgShadow::ShadowedScene* createShadowedScene(osg::Node* sceneToShadow, osg::LightSource* lightSource, int shadowType);
00234 
00235     virtual void setGroundTexture(const char* filename) {
00236       this->groundTexture = filename;
00237     }
00238 
00239     virtual void setCaption(const std::string& caption);
00240 
00241     /**
00242      * Create HUDStatisticsManager and register it for being called back every step.
00243      * But do not display if the system is initialised with -nographics.
00244      * @return the actual HUDStatisticsManager
00245      */
00246     virtual HUDStatisticsManager* getHUDSM();
00247 
00248     virtual ~Base();
00249 
00250   protected:
00251     virtual void setTimeStats(double time, double realtimefactor,
00252                               double truerealtimefactor,bool pause);
00253 
00254     /**
00255      * Changes the currently used shadow technique.
00256      * The switch is realized between:
00257      * 0 - NoShadow
00258      * 3 - ParallelSplitShadowMap
00259      * 4 - SoftShadowMap
00260      * 5 - ShadowMap (simple)
00261      * Currently not supported by this function:
00262      * 1 - ShadowVolume
00263      * 2 - ShadowTextue
00264      */
00265     virtual void changeShadowTechnique();
00266 
00267     /// deletes the stuff that is created on makescene and the like
00268     virtual void base_close();
00269 
00270     dGeomID ground;
00271 
00272 
00273     OsgHandle osgHandle;
00274     // ODE globals
00275     OdeHandle odeHandle;
00276     std::string caption;
00277     std::string groundTexture;
00278 
00279     osg::Group* dummy;
00280 
00281     osg::Node* hud;
00282     osgText::Text* timestats;
00283     osgText::Text* captionline;
00284     osgText::Text* statisticLine;
00285 
00286     Primitive* plane;
00287 
00288     /// this manager provides methods for displaying statistics on the graphical window!
00289     HUDStatisticsManager* hUDStatisticsManager;
00290 
00291     std::list<Callbackable*> graphicsCallbackables;
00292     std::vector<Callbackable*> physicsCallbackables; // vector because we need to parallelise it
00293 
00294     int ReceivesShadowTraversalMask;
00295     int CastsShadowTraversalMask;
00296 
00297     // the types are double because they are configurable and stored to the cfg file
00298     // int shadow;     // set by child class Simulation, now found in OsgHandle
00299     int shadowTexSize;  // set by child class Simulation
00300     bool useNVidia;      // unused: if false use ATI Radeon!
00301 
00302 
00303   public:
00304     // Helper
00305     /// returns the index+1 if the list contains the given string or 0 if not
00306     static int contains(char **list, int len,  const char *str);
00307 
00308   };
00309 }
00310 
00311 #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