Enki  1.9
CircularCam.h
Go to the documentation of this file.
1 /*
2  Enki - a fast 2D robot simulator
3  Copyright (C) 1999-2016 Stephane Magnenat <stephane at magnenat dot net>
4  Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
5  Copyright (c) 2004-2005 Antoine Beyeler <abeyeler at ab-ware dot com>
6  Copyright (C) 2005-2006 Laboratory of Intelligent Systems, EPFL, Lausanne
7  Copyright (C) 2006-2008 Laboratory of Robotics Systems, EPFL, Lausanne
8  See AUTHORS for details
9 
10  This program is free software; the authors of any publication
11  arising from research using this software are asked to add the
12  following reference:
13  Enki - a fast 2D robot simulator
14  http://home.gna.org/enki
15  Stephane Magnenat <stephane at magnenat dot net>,
16  Markus Waibel <markus dot waibel at epfl dot ch>
17  Laboratory of Intelligent Systems, EPFL, Lausanne.
18 
19  You can redistribute this program and/or modify
20  it under the terms of the GNU General Public License as published by
21  the Free Software Foundation; either version 2 of the License, or
22  (at your option) any later version.
23 
24  This program is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  GNU General Public License for more details.
28 
29  You should have received a copy of the GNU General Public License
30  along with this program; if not, write to the Free Software
31  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 */
33 
34 #ifndef __ENKI_CIRCULARCAM_H
35 #define __ENKI_CIRCULARCAM_H
36 
37 #include "../Interaction.h"
38 #include "../PhysicalEngine.h"
39 
40 #include <valarray>
41 
45 namespace Enki
46 {
48 
53  {
55  virtual ~PixelOperationFunctor() { }
57  virtual void operator()(double &zBuffer2, Color &pixelBuffer, const double &objectDist2, const Color &objectColor) = 0;
58  };
59 
60 
62 
68  {
69  protected:
73  double height;
78 
79  public:
81  std::valarray<double> zbuffer;
83  std::valarray<Color> image;
87  double angleOffset;
88 
90  bool useFog;
92  double fogDensity;
95 
98 
99  public :
101 
109  CircularCam(Robot *owner, Vector pos, double height, double orientation, double halfFieldOfView, unsigned pixelCount);
111  virtual ~CircularCam(){}
112  virtual void init(double dt, World* w);
113  virtual void objectStep(double dt, World *w, PhysicalObject *po);
114  virtual void wallsStep(double dt, World* w);
115  virtual void finalize(double dt, World* w);
116 
118  void setRange(double range);
120  Point getAbsolutePosition(void) { return absPos; }
122  double getAbsoluteOrientation(void) { return absOrientation; }
123 
124  protected:
126  double interpolateLinear(double s0, double s1, double sv, double d0, double d1);
128  void drawTexturedLine(const Point &p0, const Point &p1, const Texture &texture);
129  };
130 
131 
134 
135  class OmniCam : public LocalInteraction
136  {
137  public:
139  std::valarray<double> zbuffer;
141  std::valarray<Color> image;
142 
143  protected:
148 
149  public :
151 
156  OmniCam(Robot *owner, double height, unsigned halfPixelCount);
158  virtual ~OmniCam(){}
159  virtual void init(double dt, World* w);
160  virtual void objectStep(double dt, World *w, PhysicalObject *po);
161  virtual void wallsStep(double dt, World* w);
162  virtual void finalize(double dt, World* w);
164  void setRange(double range);
166  void setFogConditions(bool useFog, double density = 0.0, Color threshold = Color::black);
168  void setPixelOperationFunctor(PixelOperationFunctor *pixelOperationFunctor);
169  };
170 }
171 #endif
172 
A vector in a 2D space.
Definition: Geometry.h:68
std::vector< Color > Texture
A texture.
Definition: Types.h:166
std::valarray< double > zbuffer
zbuffer: distances at square (array of size pixelCount of double)
Definition: CircularCam.h:139
double absOrientation
Absolute angle in the world, updated on init()
Definition: CircularCam.h:77
Point getAbsolutePosition(void)
Return the absolute position (world coordinates) of the camera, updated at each time step on init() ...
Definition: CircularCam.h:120
1D omnidirectional circular camera, based on 2 CircularCam Pixels start at -PI and then follow mathem...
Definition: CircularCam.h:135
A situated object in the world with mass, geometry properties, physical properties, ...
Definition: PhysicalEngine.h:131
static const Color black
black (0, 0, 0)
Definition: Types.h:150
std::valarray< double > zbuffer
zbuffer: distances at square (array of size pixelCount of double)
Definition: CircularCam.h:81
virtual ~OmniCam()
Destructor.
Definition: CircularCam.h:158
Functor for pixel operation.
Definition: CircularCam.h:52
Enki is the namespace of the Enki simulator. All Enki functions and classes excepted the math one are...
Definition: BluetoothBase.cpp:44
double height
Height above ground, the camera will not see any object of smaller height.
Definition: CircularCam.h:73
double getAbsoluteOrientation(void)
Return the absolute orientation (world coordinates) of the camera, updated at each time step on init(...
Definition: CircularCam.h:122
CircularCam cam0
Cameras doing the real job, first part.
Definition: CircularCam.h:145
CircularCam cam1
Cameras doing the real job, second part.
Definition: CircularCam.h:147
virtual ~PixelOperationFunctor()
Virtual destructor, do nothing.
Definition: CircularCam.h:55
Vector absPos
Absolute position in the world, updated on init()
Definition: CircularCam.h:75
std::valarray< Color > image
Image (array of size pixelCount of Color)
Definition: CircularCam.h:141
virtual void operator()(double &zBuffer2, Color &pixelBuffer, const double &objectDist2, const Color &objectColor)=0
Modify the pixel and depth buffer² for a given object color and distance²
PixelOperationFunctor * pixelOperation
Pointer to active pixel operation.
Definition: CircularCam.h:97
The world is the container of all objects and robots.
Definition: PhysicalEngine.h:411
double halfFieldOfView
Field of view = [-halfFieldOfView; + halfFieldOfView]. [0; PI/2].
Definition: CircularCam.h:85
virtual ~CircularCam()
Destructor.
Definition: CircularCam.h:111
Color lightThreshold
Minimum incoming light, otherwise 0. Only used if useFog is true.
Definition: CircularCam.h:94
Vector positionOffset
Position offset based on owner position.
Definition: CircularCam.h:71
double fogDensity
Density of fog, used to compute light attenuation with the function: light = light0 * exp(-fogDensity...
Definition: CircularCam.h:92
A color in RGBA.
Definition: Types.h:55
Interacts with another object or wall only up to a certain distance.
Definition: Interaction.h:53
std::valarray< Color > image
Image (array of size pixelCount of Color)
Definition: CircularCam.h:83
bool useFog
Fog switch, exponential decay of light with distance.
Definition: CircularCam.h:90
A robot is a PhysicalObject that has additional interactions and a controller.
Definition: PhysicalEngine.h:379
double angleOffset
Angular offset based on owner angle.
Definition: CircularCam.h:87
1D Circular camera
Definition: CircularCam.h:67