Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
camera.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __CAMERA_H_
25 #define __CAMERA_H_
26 
27 #include "osgforwarddecl.h"
28 
29 #include "osghandle.h"
30 #include "odehandle.h"
31 
32 #include <osg/Matrix>
33 #include <osg/Camera>
34 
35 
36 namespace osg {
37 class Image;
38 }
39 
40 namespace lpzrobots {
41 
42  class OSGCylinder;
43  class OSGBox;
44  class Transform;
45 
47  typedef std::vector<ImageProcessor* > ImageProcessors;
48 
49 
50  struct CameraConf {
51  int width; ///< horizontal resolution (power of 2)
52  int height; ///< vertical resolution (power of 2)
53  float fov; ///< field of view in degree (opening angle of lenses)
54  float anamorph; ///< anamorph ratio of focal length in vertical and horizontal direction
55  float behind; ///< distance of which the camera is behind the actually drawn position (to aviod near clipping)
56  float draw; ///< whether to draw a physical camera object
57  float camSize; ///< size of the physical camera object
58  bool show; ///< whether to show the image on the screen
59  float scale; ///< scaling for display
60  std::string name; ///< name of the camera
61  ImageProcessors processors; ///< list of image processors that filter the raw image
62 
63  /// removes and deletes all processor
64  void removeProcessors();
65  };
66 
67  /** A Robot Camera. Implements a simulated camera with full OpenGL rendering.
68  */
69  class Camera {
70  public:
71  struct PostDrawCallback : public osg::Camera::DrawCallback {
73  cam(cam) { }
74  virtual void operator () (const osg::Camera& /*camera*/) const;
76  };
77 
78 
79  /// structure to store the image data and information for display
80  struct CameraImage{
82  CameraImage(osg::Image* img, bool show, float scale, const std::string& name)
83  : img(img), show(show), scale(scale), name(name){
84  }
85  osg::Image* img;
86  bool show; ///< whether to show the image on the screen
87  float scale; ///< scaling for display
88  std::string name; ///< name of the image
89  };
90 
91  typedef std::vector<CameraImage > CameraImages;
92 
93  /** Creates a camera.
94  Note that the order in which the image processors are positioned
95  in conf.imageProcessors matters.
96  The resulting CameraImages are stored in a list (see getImages) and
97  usually the processors use the last image in this list (result of last processing).
98  */
99 
100  Camera( const CameraConf& conf = getDefaultConf() );
101 
103  CameraConf c;
104  c.width = 256;
105  c.height = 128;
106  c.fov = 90;
107  c.anamorph = 1;
108  c.behind = 0.04; // since the nearplane is at 0.05
109  c.camSize = 0.2;
110  c.draw = true;
111  c.show = true;
112  c.scale = 1.0;
113  c.name = "raw";
114  return c;
115  }
116 
117  virtual ~Camera();
118 
119  /** initializes the camera. The OSG camera is created and the
120  raw image and the imageprocessor is initialized.
121  */
122  virtual void init(const OdeHandle& odeHandle,
123  const OsgHandle& osgHandle,
124  Primitive* body,
125  const osg::Matrix& pose);
126 
127  /// changes the relative pose of the camera
128  virtual void setPose(const osg::Matrix& pose);
129 
130  /// relative pose of the camera
131  virtual osg::Matrix getPose();
132 
133  // virtual bool sense(const GlobalData& globaldata);
134 
135  /// all images (raw and processed)
136  virtual const CameraImages& getImages() const { return cameraImages;}
137 
138  /// last image of processing stack
139  virtual const osg::Image* getImage() const { return cameraImages.back().img;}
140 
141  virtual osg::Camera* getRRTCam() { return cam;}
142 
143  virtual void update();
144 
145  bool isInitialized() { return initialized; }
146  private:
147  CameraConf conf;
148 
149  osg::Camera* cam;
150  osg::Image* ccd;
151  CameraImages cameraImages;
152 
153  Primitive* body;
154  osg::Matrix pose;
155 
156  OSGBox* sensorBody1;
157  OSGCylinder* sensorBody2;
158  OsgHandle osgHandle;
159  Transform* transform;
160 
161  bool initialized;
162  };
163 
164 }
165 
166 #endif /* __CAMERA_H_ */
std::vector< CameraImage > CameraImages
Definition: camera.h:91
float draw
whether to draw a physical camera object
Definition: camera.h:56
Data structure for accessing the ODE.
Definition: odehandle.h:44
float behind
distance of which the camera is behind the actually drawn position (to aviod near clipping) ...
Definition: camera.h:55
virtual void update()
Definition: camera.cpp:145
bool show
whether to show the image on the screen
Definition: camera.h:58
float scale
scaling for display
Definition: camera.h:59
Matrixd Matrix
Definition: osgforwarddecl.h:47
Camera(const CameraConf &conf=getDefaultConf())
Creates a camera.
Definition: camera.cpp:59
A Robot Camera.
Definition: camera.h:69
int width
horizontal resolution (power of 2)
Definition: camera.h:51
PostDrawCallback(Camera *cam)
Definition: camera.h:72
Definition: camera.h:50
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual ~Camera()
Definition: camera.cpp:66
std::string name
name of the camera
Definition: camera.h:60
structure to store the image data and information for display
Definition: camera.h:80
virtual void setPose(const osg::Matrix &pose)
changes the relative pose of the camera
Definition: camera.cpp:136
Graphical box.
Definition: osgprimitive.h:141
std::vector< ImageProcessor * > ImageProcessors
Definition: camera.h:46
float camSize
size of the physical camera object
Definition: camera.h:57
virtual osg::Camera * getRRTCam()
Definition: camera.h:141
CameraImage()
Definition: camera.h:81
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
float scale
scaling for display
Definition: camera.h:87
float fov
field of view in degree (opening angle of lenses)
Definition: camera.h:53
bool isInitialized()
Definition: camera.h:145
CameraImage(osg::Image *img, bool show, float scale, const std::string &name)
Definition: camera.h:82
static CameraConf getDefaultConf()
Definition: camera.h:102
virtual osg::Matrix getPose()
relative pose of the camera
Definition: camera.cpp:141
Base class for image processing units.
Definition: imageprocessor.h:39
std::string name
name of the image
Definition: camera.h:88
void removeProcessors()
removes and deletes all processor
Definition: camera.cpp:45
ImageProcessors processors
list of image processors that filter the raw image
Definition: camera.h:61
Graphical cylinder.
Definition: osgprimitive.h:215
Primitive for transforming a geom (primitive without body) in respect to a body (primitive with body)...
Definition: primitive.h:410
float anamorph
anamorph ratio of focal length in vertical and horizontal direction
Definition: camera.h:54
virtual const CameraImages & getImages() const
all images (raw and processed)
Definition: camera.h:136
osg::Image * img
Definition: camera.h:85
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, Primitive *body, const osg::Matrix &pose)
initializes the camera.
Definition: camera.cpp:73
virtual const osg::Image * getImage() const
last image of processing stack
Definition: camera.h:139
bool show
whether to show the image on the screen
Definition: camera.h:86
Camera * cam
Definition: camera.h:75
int c
Definition: hexapod.cpp:56
virtual void operator()(const osg::Camera &) const
Definition: camera.cpp:52
int height
vertical resolution (power of 2)
Definition: camera.h:52