Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
base.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __BASE_H
25 #define __BASE_H
26 
27 #include <ode-dbl/ode.h>
28 #include <osg/Transform>
29 #include <osgText/Text>
30 
31 #include "osghandle.h"
32 #include "odehandle.h"
33 
34 #include "hudstatistics.h"
35 #include <selforg/configurable.h>
36 
37 namespace osgShadow
38 {
39  class ShadowedScene;
40 }
41 
42 namespace lpzrobots
43 {
44 
45  class MoveEarthySkyWithEyePointTransform : public osg::Transform
46  {
47  public:
48  /** Get the transformation matrix which moves from local coords to world coords.*/
49  virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
50 
51  /** Get the transformation matrix which moves from world coords to local coords.*/
52  virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
53  };
54 
56  StatLineProperties(int fontSizeTime, int fontSizeText, const std::string& fontColor)
57  :fontSizeTime(fontSizeTime), fontSizeText(fontSizeText), fontColor(fontColor) {
58  }
61  std::string fontColor;
62  };
63 
64  class Base : public Configurable
65  {
66  public:
67  Base(const std::string& caption="LpzRobots Simulator (Martius et al)");
68 
69  static const int PHYSICS_CALLBACKABLE = 1; //!< called each ode/physics step
70  static const int GRAPHICS_CALLBACKABLE = 2; //!< called each osg/draw step
71 
72  /// create the ground plane
73  virtual void makePhysicsScene();
74  /** creates the base scene graph with world, sky and floor and shadow and HUD
75  and stores it in scene
76  */
77  virtual void makeScene(OsgScene* scene, const OsgConfig& config);
78  virtual osg::Node* makeSky(const OsgConfig& config);
79  virtual osg::Node* makeGround(const OsgConfig& config);
80  /** creates hud and is supposed to return the camera to it and
81  adds the geode of the hud to the scene */
82  virtual osg::Node* createHUD(OsgScene* scene, const OsgConfig& config);
83  virtual void createHUDManager(osg::Geode* geode, osgText::Font* font);
84  /// adds light to the node
85  virtual void makeLights(osg::Group* node, const OsgConfig& config);
86 
87  /** Shadow types:
88  * 1 - ShadowVolume
89  * 2 - ShadowTextue
90  * 3 - ParallelSplitShadowMap
91  * 4 - SoftShadowMap
92  * 5 - ShadowMap
93  */
94  virtual osgShadow::ShadowedScene* createShadowedScene(osg::Node* sceneToShadow, osg::LightSource* lightSource, int shadowType);
95 
96  virtual void setGroundTexture(const char* filename) {
97  this->groundTexture = filename;
98  }
99 
100  virtual Substance getGroundSubstance();
101  virtual void setGroundSubstance(const Substance& substance);
102 
103  /// sets the cpation that is printed at the right of the status line
104  virtual void setCaption(const std::string& caption);
105 
106  /// sets the title that is printed in the center of the status line
107  virtual void setTitle(const std::string& title);
108 
110  /// sets the properties of the status line, do it before the scene is initialized
112  this->statlineprop = statlineprop;
113  }
114 
115  /**
116  * Create HUDStatisticsManager and register it for being called back every step.
117  * But do not display if the system is initialised with -nographics.
118  * @return the actual HUDStatisticsManager
119  */
120  virtual HUDStatisticsManager* getHUDSM();
121 
122  virtual ~Base();
123 
124  protected:
125  virtual void setTimeStats(double time, double realtimefactor,
126  double truerealtimefactor,bool pause);
127 
128  /**
129  * Changes the currently used shadow technique.
130  * The switch is realized between:
131  * 0 - NoShadow
132  * 3 - ParallelSplitShadowMap
133  * 4 - SoftShadowMap
134  * 5 - ShadowMap (simple)
135  * Currently not supported by this function:
136  * 1 - ShadowVolume
137  * 2 - ShadowTextue
138  */
139  virtual void changeShadowTechnique();
140 
141  /// deletes the stuff that is created on makescene and the like
142  virtual void base_close();
143 
144  dGeomID ground;
145 
146 
148  // ODE globals
150  std::string caption;
151  std::string title;
152  std::string groundTexture;
153 
154  osg::Group* dummy;
155 
156  osg::Node* hud;
157  osgText::Text* timestats;
158  osgText::Text* captionline;
159  osgText::Text* titleline;
161 
163 
164  /// this manager provides methods for displaying statistics on the graphical window!
166 
169 
170  // the types are double because they are configurable and stored to the cfg file
171  // int shadow; // set by child class Simulation, now found in OsgHandle
172  int shadowTexSize; // set by child class Simulation
173  bool useNVidia; // unused: if false use ATI Radeon!
174 
175 
176  public:
177  // Helper
178  /// returns the index+1 if the list contains the given string or 0 if not
179  static int contains(char **list, int len, const char *str);
180 
181  };
182 }
183 
184 #endif
Data structure for accessing the ODE.
Definition: odehandle.h:44
osgText::Text * timestats
Definition: base.h:157
Physical substance definition, used for collision detection/treatment What we need is mu...
Definition: substance.h:103
virtual void setGroundTexture(const char *filename)
Definition: base.h:96
virtual void makeLights(osg::Group *node, const OsgConfig &config)
adds light to the node
Definition: base.cpp:749
virtual void makeScene(OsgScene *scene, const OsgConfig &config)
creates the base scene graph with world, sky and floor and shadow and HUD and stores it in scene ...
Definition: base.cpp:451
std::string fontColor
Definition: base.h:61
Matrixd Matrix
Definition: osgforwarddecl.h:47
virtual void setCaption(const std::string &caption)
sets the cpation that is printed at the right of the status line
Definition: base.cpp:437
virtual HUDStatisticsManager * getHUDSM()
Create HUDStatisticsManager and register it for being called back every step.
Definition: base.cpp:403
virtual ~Base()
Definition: base.cpp:115
osg::Node * hud
Definition: base.h:156
osg::Group * dummy
Definition: base.h:154
virtual osg::Node * makeSky(const OsgConfig &config)
Definition: base.cpp:538
StatLineProperties(int fontSizeTime, int fontSizeText, const std::string &fontColor)
Definition: base.h:56
int CastsShadowTraversalMask
Definition: base.h:168
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void setTimeStats(double time, double realtimefactor, double truerealtimefactor, bool pause)
Definition: base.cpp:415
manages all the stuff displaying statistics on the graphics window.
Definition: hudstatistics.h:60
static int contains(char **list, int len, const char *str)
returns the index+1 if the list contains the given string or 0 if not
Definition: base.cpp:893
Definition: base.h:64
std::string title
Definition: base.h:151
int shadowTexSize
Definition: base.h:172
virtual osgShadow::ShadowedScene * createShadowedScene(osg::Node *sceneToShadow, osg::LightSource *lightSource, int shadowType)
Shadow types: 1 - ShadowVolume 2 - ShadowTextue 3 - ParallelSplitShadowMap 4 - SoftShadowMap 5 - Shad...
Definition: base.cpp:132
virtual osg::Node * createHUD(OsgScene *scene, const OsgConfig &config)
creates hud and is supposed to return the camera to it and adds the geode of the hud to the scene ...
Definition: base.cpp:280
virtual void makePhysicsScene()
create the ground plane
Definition: base.cpp:642
int fontSizeTime
Definition: base.h:59
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
osgText::Text * titleline
Definition: base.h:159
virtual bool computeLocalToWorldMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const
Get the transformation matrix which moves from local coords to world coords.
Definition: base.cpp:810
Abstact class for configurable objects.
Definition: configurable.h:81
bool useNVidia
Definition: base.h:173
virtual void setStatLineProperties(const StatLineProperties &statlineprop)
sets the properties of the status line, do it before the scene is initialized
Definition: base.h:111
StatLineProperties statlineprop
Definition: base.h:160
virtual void changeShadowTechnique()
Changes the currently used shadow technique.
Definition: base.cpp:835
Base(const std::string &caption="LpzRobots Simulator (Martius et al)")
Definition: base.cpp:103
Definition: base.h:55
int fontSizeText
Definition: base.h:60
std::string groundTexture
Definition: base.h:152
virtual Substance getGroundSubstance()
Definition: base.cpp:653
HUDStatisticsManager * hUDStatisticsManager
this manager provides methods for displaying statistics on the graphical window!
Definition: base.h:165
virtual void setTitle(const std::string &title)
sets the title that is printed in the center of the status line
Definition: base.cpp:444
virtual bool computeWorldToLocalMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const
Get the transformation matrix which moves from world coords to local coords.
Definition: base.cpp:821
virtual StatLineProperties getStatLineProperties()
Definition: base.h:109
virtual osg::Node * makeGround(const OsgConfig &config)
Definition: base.cpp:663
static const int PHYSICS_CALLBACKABLE
called each ode/physics step
Definition: base.h:69
OdeHandle odeHandle
Definition: base.h:149
virtual void base_close()
deletes the stuff that is created on makescene and the like
Definition: base.cpp:118
virtual void createHUDManager(osg::Geode *geode, osgText::Font *font)
Definition: base.cpp:395
dGeomID ground
Definition: base.h:144
OsgHandle osgHandle
Definition: base.h:147
int ReceivesShadowTraversalMask
Definition: base.h:167
Data structure containing some configuration variables for OSG.
Definition: osghandle.h:41
Data structure containing the scene notes (e.g.
Definition: osghandle.h:53
static const int GRAPHICS_CALLBACKABLE
called each osg/draw step
Definition: base.h:70
Primitive * plane
Definition: base.h:162
std::string caption
Definition: base.h:150
osgText::Text * captionline
Definition: base.h:158
virtual void setGroundSubstance(const Substance &substance)
Definition: base.cpp:658