camerasensor.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 #ifndef __CAMERASENSOR_H
00026 #define __CAMERASENSOR_H
00027 
00028 #include "camera.h"
00029 #include "sensor.h"
00030 
00031 namespace lpzrobots {
00032 
00033 
00034   /** This to connect a Camera as a sensor to a robot. 
00035       Essentially it implements the conversion from the 2D image 
00036       to a list of double sensor values. 
00037       The initialization is a bit confusing: use the contructor (of a inherited class)
00038       to provide custom parameter; setInitData sets the handles and the camera
00039       which has to be called before the normal initialization of the Sensor (via init()).
00040       A subclass has to overload intern_init() to initialize intern structures
00041        (e.g. number of channels), sense() and get().
00042       
00043    */
00044   class CameraSensor : public Sensor {
00045   public:  
00046 
00047     /** Creates a camera sensor. Use setInitData() to make it useable.        
00048      */ 
00049     CameraSensor();
00050 
00051     virtual ~CameraSensor();
00052 
00053     /** sets the initial data structures like the camera. 
00054         The camera will be initialized in init() (don't initialize it before).
00055         @param pose position and orientation of camera wrt. 
00056         the primitive that is given at init()
00057      */ 
00058     virtual void setInitData(Camera* camera, const OdeHandle& odeHandle, 
00059                              const OsgHandle& osgHandle, const osg::Matrix& pose);
00060 
00061     /// this function initialized the camera (no need to overload) (Sensor interface)
00062     virtual void init(Primitive* own);
00063 
00064     /// overload this function an process the image (use camera->getImage())
00065     virtual bool sense(const GlobalData& globaldata) = 0;
00066 
00067     /// overload this function and return the number of sensor values
00068     virtual int getSensorNumber() const = 0;
00069 
00070     /// overload this function and return the sensor values
00071     virtual int get(sensor* sensors, int length) const = 0;
00072     
00073     /// we update the camera's visual appearance
00074     virtual void update();
00075 
00076     /// this is implemented based on get(sensor*,int)
00077     virtual std::list<sensor> get() const;
00078 
00079   protected:
00080     /** overload this function to initialized you data structures.
00081         Use camera->getImage() to get the image from the camera
00082     */
00083     virtual void intern_init() = 0;
00084 
00085 
00086     Camera* camera;    
00087     OdeHandle odeHandle;
00088     OsgHandle osgHandle;
00089     osg::Matrix pose;
00090     bool isInitDataSet;
00091   };  
00092 
00093 }
00094 
00095 #endif
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