osghandle.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  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  *                                                                         *
00022  *   $Log: osghandle.h,v $
00023  *   Revision 1.11  2010/03/22 14:33:19  martius
00024  *   osghandle changeColor() with single rgba values
00025  *   camerasensors windowfunction bug
00026  *
00027  *   Revision 1.10  2010/03/17 17:26:36  martius
00028  *   robotcameramanager uses keyboard and respects resize
00029  *   (robot) camera is has a conf object
00030  *   image processing implemented, with a few standard procedures
00031  *
00032  *   Revision 1.9  2010/03/16 15:48:02  martius
00033  *   osgHandle has now substructures osgConfig and osgScene
00034  *    that minimized amount of redundant data (this causes a lot of changes)
00035  *   Scenegraph is slightly changed. There is a world and a world_noshadow now.
00036  *    Main idea is to have a world without shadow all the time avaiable for the
00037  *    Robot cameras (since they do not see the right shadow for some reason)
00038  *   tidied up old files
00039  *
00040  *   Revision 1.8  2010/03/07 22:48:23  guettler
00041  *   moved shadow to OsgHandle.shadowType (TODO: move it to OsgConfig)
00042  *
00043  *   Revision 1.7  2010/03/05 14:32:55  martius
00044  *   camera sensor added
00045  *   for that the scenegraph structure was changed into root, world, scene
00046  *   camera does not work with shadows
00047  *   works with newest version of ode (0.11)
00048  *
00049  *   Revision 1.6  2009/07/30 11:23:45  guettler
00050  *   new noGraphics state for OSGPrimitives
00051  *
00052  *   Revision 1.5  2009/07/29 14:19:49  jhoffmann
00053  *   Various bugfixing, remove memory leaks (with valgrind->memcheck / alleyoop)
00054  *
00055  *   Revision 1.4  2007/07/30 14:13:40  martius
00056  *   drawBoundings moved here
00057  *
00058  *   Revision 1.3  2006/12/11 18:26:55  martius
00059  *   destructor, but without any function
00060  *
00061  *   Revision 1.2  2006/07/14 12:23:56  martius
00062  *   selforg becomes HEAD
00063  *
00064  *   Revision 1.1.2.8  2006/06/29 16:39:56  robot3
00065  *   -you can now see bounding shapes if you type ./start -drawboundings
00066  *   -includes cleared up
00067  *   -abstractobstacle and abstractground have now .cpp-files
00068  *
00069  *   Revision 1.1.2.7  2006/06/15 09:17:09  martius
00070  *   restores changeAlpha
00071  *
00072  *   Revision 1.1.2.6  2006/06/12 13:37:55  robot3
00073  *   added missing const OsgHandle->changeAlpha(const float& alpha);
00074  *
00075  *   Revision 1.1.2.5  2006/01/12 14:39:06  martius
00076  *   transparent stateset
00077  *
00078  *   Revision 1.1.2.4  2005/12/29 16:48:06  martius
00079  *   changeColor
00080  *
00081  *   Revision 1.1.2.3  2005/12/22 14:09:56  martius
00082  *   different tesselhints for different level of detail
00083  *
00084  *   Revision 1.1.2.2  2005/12/13 18:12:20  martius
00085  *   some utils
00086  *
00087  *   Revision 1.1.2.1  2005/12/06 16:18:02  martius
00088  *   handle class for OpenSceneGraph
00089  *
00090  *
00091  ***************************************************************************/
00092 #ifndef __OSGHANDLE_H
00093 #define __OSGHANDLE_H
00094 
00095 #include "osgforwarddecl.h"
00096 #include "color.h"
00097 
00098 namespace osgShadow {
00099   class ShadowedScene;
00100 }
00101 
00102 namespace lpzrobots {
00103 
00104   class RobotCameraManager;
00105 
00106 
00107   /** Data structure containing some configuration variables for OSG */
00108   struct OsgConfig {
00109     OsgConfig() : normalState(0), transparentState(0), noGraphics(false) {}
00110     osg::TessellationHints* tesselhints[3];  
00111     osg::StateSet* normalState;  
00112     osg::StateSet* transparentState;  
00113     int shadowType;
00114     bool noGraphics;        
00115   };
00116 
00117   /** Data structure containing the scene notes (e.g. with and without shadow)*/
00118   struct OsgScene {
00119     OsgScene() :  root(0), world(0),world_noshadow(0),scene(0),
00120                   shadowedScene(0), shadowedSceneRoot(0), groundScene(0), 
00121                   lightSource(0), worldtransform(0),
00122                   robotCamManager(0) {}
00123     osg::Group* root;  // master note (contains world,hud..)
00124     osg::Group* world; // world note  (contains ground,sky and shadowed scene)
00125     osg::Group* world_noshadow; // world note without shadow (contains ground,sky and scene)
00126     osg::Group* scene; // actual scene for robots and stuff    
00127 
00128     osgShadow::ShadowedScene* shadowedScene;
00129     osg::Group* shadowedSceneRoot; // root node of shadowed scene 
00130     osg::Node* groundScene;
00131 
00132     osg::LightSource* lightSource;  // the light source
00133     osg::Transform* worldtransform; // unit transformation at the moment
00134 
00135     RobotCameraManager* robotCamManager; // manages robot cameras and their display
00136   };
00137 
00138   
00139 
00140 
00141 /** Data structure for accessing the OpenSceneGraph */
00142 class OsgHandle
00143 {
00144 public:
00145   OsgHandle();
00146 
00147   // Georg: removed. Brauchen wir den wirklich?
00148 //   /**
00149 //    * TODO: Separation of OSGHandle and OSGConfig
00150 //    * @param root
00151 //    * @param world
00152 //    * @param scene
00153 //    * @param tesselhints
00154 //    * @param normalState
00155 //    * @param transparentState
00156 //    * @param color
00157 //    * @param shadowType
00158 //    * @return
00159 //    */
00160 //   OsgHandle( osg::Group* root, osg::Group* world, osg::Group* scene, 
00161 //              osg::TessellationHints* tesselhints[3], 
00162 //           osg::StateSet* normalState, osg::StateSet* transparentState, 
00163 //           const Color& color, int shadowType);
00164 
00165   ~OsgHandle();
00166 
00167   /// initialization of the structure
00168   void init();
00169   /// set up robotcameramanager (must be called after init but before usage of the structure)
00170   void setup(int windowW, int windowH);
00171   /// deletes all internal variables
00172   void close();
00173 
00174   /// decides whether to draw bounding boxes 
00175   bool drawBoundings;   
00176 
00177   Color color;    
00178 
00179   OsgConfig* cfg;
00180   OsgScene*  scene;
00181   osg::Group* parent; // the place there individual osgprimitives are added
00182 
00183   // returns a new osghandle with only the color changed
00184   OsgHandle changeColor(const Color& color) const;
00185   // returns a new osghandle with only the color changed
00186   OsgHandle changeColor(double r, double g, double b, double a=1.0) const;
00187   // returns a new osghandle with only the alpha channel changed
00188   OsgHandle changeAlpha(double alpha) const; 
00189   
00190 };
00191 
00192 
00193 
00194 }
00195 
00196 #endif
00197 
Generated on Fri Nov 4 10:59:39 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3