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
osghandle.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 __OSGHANDLE_H
25 #define __OSGHANDLE_H
26 
27 #include "osgforwarddecl.h"
28 #include "color.h"
29 #include "colorschema.h"
30 
31 namespace osgShadow {
32  class ShadowedScene;
33 }
34 
35 namespace lpzrobots {
36 
37  class RobotCameraManager;
38 
39 
40  /** Data structure containing some configuration variables for OSG */
41  struct OsgConfig {
43  shadowType(0), noGraphics(false) {}
44  osg::TessellationHints* tesselhints[3];
45  osg::StateSet* normalState;
46  osg::StateSet* transparentState;
47  ColorSchema* cs; // color schema
49  bool noGraphics;
50  };
51 
52  /** Data structure containing the scene notes (e.g. with and without shadow)*/
53  struct OsgScene {
57  robotCamManager(0) {}
58  osg::Group* root; // master note (contains world,hud..)
59  osg::Group* world; // world note (contains ground,sky and shadowed scene)
60  osg::Group* world_noshadow; // world note without shadow (contains ground,sky and scene)
61  osg::Group* scene; // actual scene for robots and stuff
62 
63  osgShadow::ShadowedScene* shadowedScene;
64  osg::Group* shadowedSceneRoot; // root node of shadowed scene
65  osg::Node* groundScene;
66 
67  osg::Geode* hud;
68 
69  osg::LightSource* lightSource; // the light source
70  osg::Transform* worldtransform; // unit transformation at the moment
71 
72  RobotCameraManager* robotCamManager; // manages robot cameras and their display
73  };
74 
75 
76 
77 
78 /** Data structure for accessing the OpenSceneGraph */
79 class OsgHandle
80 {
81 public:
82  OsgHandle();
83 
84  ~OsgHandle();
85 
86  /// initialization of the structure
87  void init();
88  /// set up robotcameramanager (must be called after init but before usage of the structure)
89  void setup(int windowW, int windowH);
90  /// deletes all internal variables
91  void close();
92 
93  /// decides whether to draw bounding boxes
95 
97 
98  OsgConfig* cfg; // the config is shared
99  OsgScene* scene; // the scene is shared
100  osg::Group* parent; // the place where individual osgprimitives are added
101 
102  /// returns a new osghandle with only the color changed
103  OsgHandle changeColor(const Color& color) const;
104  /// returns a new osghandle with only the color changed
105  OsgHandle changeColor(double r, double g, double b, double a=1.0) const;
106  /// returns a new osghandle with only the alpha channel changed
107  OsgHandle changeAlpha(double alpha) const;
108 
109  /** returns a new osghandle with only the color changed
110  @param name name,id, or alias of a color in the colorschema
111  The current color_set is used
112  */
113  OsgHandle changeColor(const std::string& name) const;
114 
115  /** like changeColor(string) but with a default color (defcolor) in case
116  no color with the name exists */
117  OsgHandle changeColorDef(const std::string& name, const Color& defcolor) const;
118 
119  /** returns the color that corresponds to the name (name,id, or alias)
120  in the colorschema. The current color_set is used
121  */
122  Color getColor(const std::string& name) const;
123 
124 
125  /** returns a new osghandle with a changed color (alias) set */
126  OsgHandle changeColorSet(int color_set) const;
127 
128  /// modifies the used color set. Only applies to new set colors.
129  void setColorSet(int color_set);
130 
131  /** returns the color schema. Use this to set/load colors and aliases
132  Note, the color schema is shared among the osghandles
133  */
135  const ColorSchema* colorSchema() const;
136 
137 
138 private:
139  int color_set; // selects the color (alias) set that is used when setting a color
140 
141 };
142 
143 
144 }
145 
146 #endif
147 
void close()
deletes all internal variables
Definition: osghandle.cpp:77
osg::Group * scene
Definition: osghandle.h:61
osg::Geode * hud
Definition: osghandle.h:67
OsgHandle changeColor(const Color &color) const
returns a new osghandle with only the color changed
Definition: osghandle.cpp:105
OsgScene()
Definition: osghandle.h:54
osg::StateSet * normalState
Definition: osghandle.h:45
bool noGraphics
Definition: osghandle.h:49
void init()
initialization of the structure
Definition: osghandle.cpp:43
OsgHandle changeColorDef(const std::string &name, const Color &defcolor) const
like changeColor(string) but with a default color (defcolor) in case no color with the name exists ...
Definition: osghandle.cpp:139
void setup(int windowW, int windowH)
set up robotcameramanager (must be called after init but before usage of the structure) ...
Definition: osghandle.cpp:97
OsgHandle changeAlpha(double alpha) const
returns a new osghandle with only the alpha channel changed
Definition: osghandle.cpp:117
ColorSchema * cs
Definition: osghandle.h:47
ColorSchema * colorSchema()
returns the color schema.
Definition: osghandle.cpp:149
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
osg::LightSource * lightSource
Definition: osghandle.h:69
osg::StateSet * transparentState
Definition: osghandle.h:46
osg::Group * shadowedSceneRoot
Definition: osghandle.h:64
OsgScene * scene
Definition: osghandle.h:99
A store for colors with a set of aliases.
Definition: colorschema.h:39
osg::Transform * worldtransform
Definition: osghandle.h:70
osg::Group * world_noshadow
Definition: osghandle.h:60
Manages camera sensors.
Definition: robotcameramanager.h:39
osgShadow::ShadowedScene * shadowedScene
Definition: osghandle.h:63
osg::TessellationHints * tesselhints[3]
Definition: osghandle.h:44
Color getColor(const std::string &name) const
returns the color that corresponds to the name (name,id, or alias) in the colorschema.
Definition: osghandle.cpp:130
OsgHandle()
Definition: osghandle.cpp:36
osg::Group * root
Definition: osghandle.h:58
Definition: color.h:32
osg::Node * groundScene
Definition: osghandle.h:65
osg::Group * parent
Definition: osghandle.h:100
double g(double z)
neuron transfer function
Definition: regularisation.h:35
osg::Group * world
Definition: osghandle.h:59
~OsgHandle()
Definition: osghandle.cpp:101
void setColorSet(int color_set)
modifies the used color set. Only applies to new set colors.
Definition: osghandle.cpp:165
int shadowType
Definition: osghandle.h:48
OsgHandle changeColorSet(int color_set) const
returns a new osghandle with a changed color (alias) set
Definition: osghandle.cpp:159
RobotCameraManager * robotCamManager
Definition: osghandle.h:72
bool drawBoundings
decides whether to draw bounding boxes
Definition: osghandle.h:94
Color color
Definition: osghandle.h:96
OsgConfig()
Definition: osghandle.h:42
Data structure containing some configuration variables for OSG.
Definition: osghandle.h:41
Data structure containing the scene notes (e.g.
Definition: osghandle.h:53
OsgConfig * cfg
Definition: osghandle.h:98