camera.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 __CAMERA_H_
00025 #define __CAMERA_H_
00026 
00027 #include "osgforwarddecl.h"
00028 
00029 #include "osghandle.h"
00030 #include "odehandle.h"
00031 
00032 #include <osg/Matrix>
00033 #include <osg/Camera>
00034 
00035 
00036 namespace osg {
00037 class Image;
00038 }
00039 
00040 namespace lpzrobots {
00041 
00042   class OSGCylinder;
00043   class OSGBox;
00044   class Transform;
00045 
00046   class ImageProcessor;
00047   typedef std::vector<ImageProcessor* > ImageProcessors;
00048 
00049 
00050   struct CameraConf {
00051     int width;       ///< horizontal resolution (power of 2)
00052     int height;      ///< vertical resolution (power of 2)
00053     float fov;       ///< field of view in degree (opening angle of lenses)
00054     float anamorph;  ///< anamorph ratio of focal length in vertical and horizontal direction
00055     float behind;    ///< distance of which the camera is behind the actually drawn position (to aviod near clipping)
00056     float draw;      ///< whether to draw a physical camera object
00057     float camSize;   ///< size of the physical camera object
00058     bool show;       ///< whether to show the image on the screen
00059     float scale;     ///< scaling for display
00060     std::string name; ///< name of the camera
00061     ImageProcessors processors; ///< list of image processors that filter the raw image
00062 
00063     /// removes and deletes all  processor
00064     void removeProcessors();
00065   };
00066 
00067   /** A Robot Camera. Implements a simulated camera with full OpenGL rendering.
00068    */
00069   class Camera {
00070   public:  
00071     struct PostDrawCallback : public osg::Camera::DrawCallback {
00072       PostDrawCallback(Camera* cam):
00073         cam(cam) { }
00074       virtual void operator () (const osg::Camera& /*camera*/) const;
00075       Camera* cam;
00076     };
00077 
00078 
00079     /// structure to store the image data and information for display
00080     struct CameraImage{
00081       CameraImage(){};
00082       CameraImage(osg::Image* img, bool show, float scale, const std::string& name)
00083         : img(img), show(show), scale(scale), name(name){
00084       }
00085       osg::Image* img;
00086       bool show;       ///< whether to show the image on the screen
00087       float scale;     ///< scaling for display
00088       std::string name; ///< name of the image
00089     };
00090 
00091     typedef std::vector<CameraImage > CameraImages;
00092 
00093     /** Creates a camera. 
00094         Note that the order in which the image processors are positioned 
00095          in conf.imageProcessors matters.
00096         The resulting CameraImages are stored in a list (see getImages) and 
00097         usually the processors use the last image in this list (result of last processing).
00098      */
00099 
00100     Camera( const CameraConf& conf = getDefaultConf() );
00101 
00102     static CameraConf getDefaultConf(){
00103       CameraConf c;
00104       c.width     = 256;
00105       c.height    = 128;
00106       c.fov       = 90;
00107       c.anamorph  = 1;
00108       c.behind    = 0.04; // since the nearplane is at 0.05
00109       c.camSize   = 0.2;
00110       c.draw      = true;
00111       c.show      = true;
00112       c.scale     = 1.0;
00113       c.name      = "raw";
00114       return c;
00115     }
00116 
00117     virtual ~Camera();
00118 
00119     /** initializes the camera. The OSG camera is created and the 
00120         raw image and the imageprocessor is initialized.
00121      */
00122     virtual void init(const OdeHandle& odeHandle,
00123                       const OsgHandle& osgHandle, 
00124                       Primitive* body, 
00125                       const osg::Matrix& pose);
00126 
00127     /// changes the relative pose of the camera
00128     virtual void setPose(const osg::Matrix& pose);
00129 
00130     /// relative pose of the camera
00131     virtual osg::Matrix getPose();
00132   
00133     // virtual bool sense(const GlobalData& globaldata);
00134 
00135     /// all images (raw and processed)
00136     virtual const CameraImages& getImages() const  { return cameraImages;}
00137 
00138     /// last image of processing stack
00139     virtual const osg::Image* getImage() const  { return cameraImages.back().img;}
00140 
00141     virtual osg::Camera* getRRTCam() { return cam;}
00142 
00143     virtual void update();
00144 
00145     bool isInitialized() { return initialized; }
00146   private:
00147     CameraConf conf;
00148     
00149     osg::Camera* cam;
00150     osg::Image* ccd;
00151     CameraImages cameraImages;
00152 
00153     Primitive* body;
00154     osg::Matrix pose;
00155 
00156     OSGBox* sensorBody1;
00157     OSGCylinder* sensorBody2;
00158     OsgHandle osgHandle;
00159     Transform* transform;
00160 
00161     bool initialized;
00162   };  
00163 
00164 }
00165 
00166 #endif      /* __CAMERA_H_ */
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3