osghandle.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 __OSGHANDLE_H
00025 #define __OSGHANDLE_H
00026 
00027 #include "osgforwarddecl.h"
00028 #include "color.h"
00029 #include "colorschema.h"
00030 
00031 namespace osgShadow {
00032   class ShadowedScene;
00033 }
00034 
00035 namespace lpzrobots {
00036 
00037   class RobotCameraManager;
00038 
00039 
00040   /** Data structure containing some configuration variables for OSG */
00041   struct OsgConfig {
00042     OsgConfig() : normalState(0), transparentState(0), 
00043                   shadowType(0), noGraphics(false) {}
00044     osg::TessellationHints* tesselhints[3];  
00045     osg::StateSet* normalState;  
00046     osg::StateSet* transparentState;  
00047     ColorSchema* cs; // color schema
00048     int shadowType;
00049     bool noGraphics;        
00050   };
00051 
00052   /** Data structure containing the scene notes (e.g. with and without shadow)*/
00053   struct OsgScene {
00054     OsgScene() :  root(0), world(0),world_noshadow(0),scene(0),
00055                   shadowedScene(0), shadowedSceneRoot(0), groundScene(0), 
00056                   lightSource(0), worldtransform(0),
00057                   robotCamManager(0) {}
00058     osg::Group* root;  // master note (contains world,hud..)
00059     osg::Group* world; // world note  (contains ground,sky and shadowed scene)
00060     osg::Group* world_noshadow; // world note without shadow (contains ground,sky and scene)
00061     osg::Group* scene; // actual scene for robots and stuff    
00062 
00063     osgShadow::ShadowedScene* shadowedScene;
00064     osg::Group* shadowedSceneRoot; // root node of shadowed scene 
00065     osg::Node* groundScene;
00066 
00067     osg::Geode* hud;  
00068 
00069     osg::LightSource* lightSource;  // the light source
00070     osg::Transform* worldtransform; // unit transformation at the moment
00071 
00072     RobotCameraManager* robotCamManager; // manages robot cameras and their display
00073   };
00074 
00075   
00076 
00077 
00078 /** Data structure for accessing the OpenSceneGraph */
00079 class OsgHandle
00080 {
00081 public:
00082   OsgHandle();
00083 
00084   ~OsgHandle();
00085 
00086   /// initialization of the structure
00087   void init();
00088   /// set up robotcameramanager (must be called after init but before usage of the structure)
00089   void setup(int windowW, int windowH);
00090   /// deletes all internal variables
00091   void close();
00092 
00093   /// decides whether to draw bounding boxes 
00094   bool drawBoundings;   
00095 
00096   Color color;    
00097 
00098   OsgConfig* cfg; // the config is shared
00099   OsgScene*  scene;  // the scene is shared
00100   osg::Group* parent; // the place where individual osgprimitives are added
00101   
00102   /// returns a new osghandle with only the color changed
00103   OsgHandle changeColor(const Color& color) const;
00104   /// returns a new osghandle with only the color changed
00105   OsgHandle changeColor(double r, double g, double b, double a=1.0) const;
00106   /// returns a new osghandle with only the alpha channel changed
00107   OsgHandle changeAlpha(double alpha) const; 
00108 
00109   /** returns a new osghandle with only the color changed
00110       @param name name,id, or alias of a color in the colorschema
00111       The current color_set is used
00112    */
00113   OsgHandle changeColor(const std::string& name) const;
00114 
00115   /** like changeColor(string) but with a default color (defcolor) in case 
00116       no color with the name exists */ 
00117   OsgHandle changeColorDef(const std::string& name, const Color& defcolor) const;
00118 
00119   /** returns the color that corresponds to the name (name,id, or alias)
00120       in the colorschema. The current color_set is used
00121   */
00122   Color getColor(const std::string& name) const;
00123 
00124 
00125   /** returns a new osghandle with a changed color (alias) set */
00126   OsgHandle changeColorSet(int color_set) const;
00127 
00128   /// modifies the used color set. Only applies to new set colors.
00129   void setColorSet(int color_set); 
00130 
00131   /** returns the color schema. Use this to set/load colors and aliases
00132       Note, the color schema is shared among the osghandles
00133    */
00134   ColorSchema* colorSchema();
00135   const ColorSchema* colorSchema() const;
00136 
00137 
00138 private:
00139   int color_set; // selects the color (alias) set that is used when setting a color
00140   
00141 };
00142 
00143 
00144 }
00145 
00146 #endif
00147 
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3