camera.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Robot Group Leipzig                             *
00003  *    georg@nld.ds.mpg.de                                                  *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *                                                                         *
00007  ** Started on  Mon Oct 15 16:48:03 2007 Georg Martius *
00008  ** Last update Mon Oct 15 16:48:03 2007 Georg Martius *
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  *   This program is distributed in the hope that it will be useful,       *
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00018  *   GNU General Public License for more details.                          *
00019  *                                                                         *
00020  *   You should have received a copy of the GNU General Public License     *
00021  *   along with this program; if not, write to the                         *
00022  *   Free Software Foundation, Inc.,                                       *
00023  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00024  ***************************************************************************
00025  *                                                                         *
00026  *  DESCRIPTION                                                            *
00027  *                                                                         *
00028  *   $Log: camera.h,v $
00029  *   Revision 1.6  2010/03/23 18:43:54  martius
00030  *   lpzviewer: added checking function
00031  *   camerasensor new initialization
00032  *   twowheeled allows full customization of camera
00033  *   optical flow improved multiscale check
00034  *
00035  *   Revision 1.5  2010/03/19 17:46:21  martius
00036  *   camerasensors added
00037  *   camera works great now. Near and far plane fixed by hand and optimal positioning
00038  *   many image processings added
00039  *
00040  *   Revision 1.4  2010/03/17 17:26:36  martius
00041  *   robotcameramanager uses keyboard and respects resize
00042  *   (robot) camera is has a conf object
00043  *   image processing implemented, with a few standard procedures
00044  *
00045  *   Revision 1.3  2010/03/16 23:24:38  martius
00046  *   scaling added
00047  *   eventhandling in robotcameramanager added
00048  *
00049  *   Revision 1.2  2010/03/16 15:41:11  martius
00050  *   Camera is working now! Using the new lpzviewer it is possible to run render it at
00051  *    the control cycle independent of the graphics
00052  *
00053  *   Revision 1.1  2010/03/05 14:32:55  martius
00054  *   camera sensor added
00055  *   for that the scenegraph structure was changed into root, world, scene
00056  *   camera does not work with shadows
00057  *   works with newest version of ode (0.11)
00058  *
00059  *
00060  *                                                                 *
00061  ***************************************************************************/
00062 #ifndef __CAMERA_H_
00063 #define __CAMERA_H_
00064 
00065 #include "osgforwarddecl.h"
00066 
00067 #include "osghandle.h"
00068 #include "odehandle.h"
00069 
00070 #include <osg/Matrix>
00071 #include <osg/Camera>
00072 
00073 
00074 namespace osg {
00075 class Image;
00076 }
00077 
00078 namespace lpzrobots {
00079 
00080   class OSGCylinder;
00081   class OSGBox;
00082   class Transform;
00083 
00084   class ImageProcessor;
00085   typedef std::vector<ImageProcessor* > ImageProcessors;
00086 
00087 
00088   struct CameraConf {
00089     int width;       ///< horizontal resolution (power of 2)
00090     int height;      ///< vertical resolution (power of 2)
00091     float fov;       ///< field of view in degree (opening angle of lenses)
00092     float anamorph;  ///< anamorph ratio of focal length in vertical and horizontal direction
00093     float behind;    ///< distance of which the camera is behind the actually drawn position (to aviod near clipping)
00094     float draw;      ///< whether to draw a physical camera object
00095     float camSize;   ///< size of the physical camera object
00096     bool show;       ///< whether to show the image on the screen
00097     float scale;     ///< scaling for display
00098     std::string name; ///< name of the camera
00099     ImageProcessors processors; ///< list of image processors that filter the raw image
00100 
00101     /// removes and deletes all  processor
00102     void removeProcessors();
00103   };
00104 
00105   /** A Robot Camera. Implements a simulated camera with full OpenGL rendering.
00106    */
00107   class Camera {
00108   public:  
00109     struct PostDrawCallback : public osg::Camera::DrawCallback {
00110       PostDrawCallback(Camera* cam):
00111         cam(cam) { }
00112       virtual void operator () (const osg::Camera& /*camera*/) const;
00113       Camera* cam;
00114     };
00115 
00116 
00117     /// structure to store the image data and information for display
00118     struct CameraImage{
00119       CameraImage(){};
00120       CameraImage(osg::Image* img, bool show, float scale, const std::string& name)
00121         : img(img), show(show), scale(scale), name(name){
00122       }
00123       osg::Image* img;
00124       bool show;       ///< whether to show the image on the screen
00125       float scale;     ///< scaling for display
00126       std::string name; ///< name of the image
00127     };
00128 
00129     typedef std::vector<CameraImage > CameraImages;
00130 
00131     /** Creates a camera. 
00132         Note that the order in which the image processors are positioned 
00133          in conf.imageProcessors matters.
00134         The resulting CameraImages are stored in a list (see getImages) and 
00135         usually the processors use the last image in this list (result of last processing).
00136      */
00137 
00138     Camera( const CameraConf& conf = getDefaultConf() );
00139 
00140     static CameraConf getDefaultConf(){
00141       CameraConf c;
00142       c.width     = 256;
00143       c.height    = 128;
00144       c.fov       = 90;
00145       c.anamorph  = 1;
00146       c.behind    = 0.04; // since the nearplane is at 0.05
00147       c.camSize   = 0.2;
00148       c.draw      = true;
00149       c.show      = true;
00150       c.scale     = 1.0;
00151       c.name      = "raw";
00152       return c;
00153     }
00154 
00155     virtual ~Camera();
00156 
00157     /** initializes the camera. The OSG camera is created and the 
00158         raw image and the imageprocessor is initialized.
00159      */
00160     virtual void init(const OdeHandle& odeHandle,
00161                       const OsgHandle& osgHandle, 
00162                       Primitive* body, 
00163                       const osg::Matrix& pose);
00164   
00165     // virtual bool sense(const GlobalData& globaldata);
00166 
00167     /// all images (raw and processed)
00168     virtual const CameraImages& getImages() const  { return cameraImages;}
00169 
00170     /// last image of processing stack
00171     virtual const osg::Image* getImage() const  { return cameraImages.back().img;}
00172 
00173     virtual osg::Camera* getRRTCam() { return cam;}
00174 
00175     virtual void update();
00176 
00177     bool isInitialized() { return initialized; }
00178   private:
00179     CameraConf conf;
00180     
00181     osg::Camera* cam;
00182     osg::Image* ccd;
00183     CameraImages cameraImages;
00184 
00185     Primitive* body;
00186     osg::Matrix pose;
00187 
00188     OSGBox* sensorBody1;
00189     OSGCylinder* sensorBody2;
00190     OsgHandle osgHandle;
00191     Transform* transform;
00192 
00193     bool initialized;
00194   };  
00195 
00196 }
00197 
00198 #endif      /* __CAMERA_H_ */
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