Fawkes API  Fawkes Development Version
bulb.h
1 
2 /***************************************************************************
3  * bulb.h - class defining a light bulb as mirror
4  *
5  * Created: Thu Jul 21 14:25:00 2005
6  * Copyright 2005-2012 Tim Niemueller [www.niemueller.de]
7  * 2005 Martin Heracles
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_MODELS_MIRROR_BULB_H_
25 #define __FIREVISION_MODELS_MIRROR_BULB_H_
26 
27 #include <fvmodels/mirror/mirrormodel.h>
28 
29 #include <string>
30 
31 namespace firevision {
32 #if 0 /* just to make Emacs auto-indent happy */
33 }
34 #endif
35 
36 class SharedMemoryLookupTable;
37 
38 class Bulb : public MirrorModel
39 {
40  friend class BulbGenerator;
41  public:
42 
43  // This constructor loads an existing bulb model (lut) from file "filename".
44  Bulb(const char *filename);
45  Bulb(const char *filename,
46  const char *lut_id, bool destroy_on_delete = false);
47 
48  Bulb(unsigned int width, unsigned int height);
49  Bulb(unsigned int width, unsigned int height,
50  const char *lut_id, bool destroy_on_delete = false);
51 
52  Bulb(const Bulb &bulb);
53 
54  virtual ~Bulb();
55 
56  virtual void warp2unwarp(unsigned int warp_x, unsigned int warp_y,
57  unsigned int *unwarp_x, unsigned int *unwarp_y);
58  virtual void unwarp2warp(unsigned int unwarp_x, unsigned int unwarp_y,
59  unsigned int *warp_x, unsigned int *warp_y );
60 
61  virtual const char * getName();
62 
63  virtual bool isValid();
64 
65 
66  virtual void setWorldPoint(unsigned int image_x,
67  unsigned int image_y,
68  float world_r,
69  float world_phi);
70 
71 
72  virtual fawkes::polar_coord_2d_t getWorldPointRelative(unsigned int image_x,
73  unsigned int image_y ) const;
74 
75  virtual fawkes::cart_coord_2d_t getWorldPointGlobal(unsigned int image_x,
76  unsigned int image_y,
77  float pose_x, float pose_y,
78  float pose_ori ) const;
79 
80  virtual void reset();
81 
82  virtual fawkes::upoint_t getCenter() const;
83  virtual void setCenter(unsigned int image_x,
84  unsigned int image_y );
85  virtual void setOrientation(float angle);
86  virtual float getOrientation() const;
87 
88  virtual bool isValidPoint( unsigned int image_x, unsigned int image_y ) const;
89 
90 
91  bool isNonZero(unsigned int image_x,
92  unsigned int image_y ) const;
93 
94  unsigned int numNonZero() const;
95 
96 
97  float getAngle(unsigned int image_x,
98  unsigned int image_y ) const;
99 
100  float getDistanceInImage(unsigned int image_p1_x, unsigned int image_p1_y,
101  unsigned int image_p2_x, unsigned int image_p2_y );
102 
103  float convertAngleI2W (float angle_in_image) const;
104 
105 
106  void load(const char * filename);
107  void save(const char * filename);
108 
109  static std::string composeFilename(const char * format);
110 
111  const fawkes::polar_coord_2d_t * get_lut() const;
112 
113  protected:
114 
115  /** bulb file header. */
116  typedef struct {
117  unsigned int width; /**< width of LUT */
118  unsigned int height; /**< height of LUT */
119  unsigned int center_x; /**< x coordinate of mirror center in image */
120  unsigned int center_y; /**< y coordinate of mirror center in image */
121  float orientation; /**< orientation of camera in image */
122  float dist_min; /**< minimum distance from mirror center */
123  float dist_max; /**< maximum distance from mirror center */
125 
126 
127  private:
128  void create();
129  void erase();
130  void init();
131 
132  private:
133 
134  // dimension of lut (and image)
135  unsigned int width;
136  unsigned int height;
137  unsigned int bytes_per_sample;
138 
139  // center of omni camera device
140  unsigned int image_center_x;
141  unsigned int image_center_y;
142 
143  // orientation of omni camera device
144  float orientation;
145 
146  // distance of closest and of farthest sample point
147  float distance_min;
148  float distance_max;
149 
150  bool valid;
151 
152  char *lut_id;
154  unsigned int lut_bytes;
155  bool destroy_on_delete;
156 
157  SharedMemoryLookupTable *shm_lut;
158 
159 
160 };
161 
162 } // end namespace firevision
163 
164 #endif
virtual fawkes::upoint_t getCenter() const
Get the image pixel that is the center of the omni-camera.
Definition: bulb.cpp:486
Cartesian coordinates (2D).
Definition: types.h:59
unsigned int center_y
y coordinate of mirror center in image
Definition: bulb.h:120
virtual void reset()
Reset model.
Definition: bulb.cpp:479
float dist_min
minimum distance from mirror center
Definition: bulb.h:122
Bulb(const char *filename)
Constructor.
Definition: bulb.cpp:62
virtual fawkes::polar_coord_2d_t getWorldPointRelative(unsigned int image_x, unsigned int image_y) const
Get relative coordinate based on image coordinates.
Definition: bulb.cpp:364
virtual bool isValid()
Check if a valid LUT has been loaded.
Definition: bulb.cpp:357
virtual bool isValidPoint(unsigned int image_x, unsigned int image_y) const
Check if the given point is valid.
Definition: bulb.cpp:537
virtual void warp2unwarp(unsigned int warp_x, unsigned int warp_y, unsigned int *unwarp_x, unsigned int *unwarp_y)
Transform warped to unwarped point.
Definition: bulb.cpp:323
Polar coordinates.
Definition: types.h:85
float getDistanceInImage(unsigned int image_p1_x, unsigned int image_p1_y, unsigned int image_p2_x, unsigned int image_p2_y)
Euklidean distance between to image points.
Definition: bulb.cpp:603
void load(const char *filename)
Load LUT from file.
Definition: bulb.cpp:251
unsigned int numNonZero() const
Get number of non-zero entries.
Definition: bulb.cpp:565
bool isNonZero(unsigned int image_x, unsigned int image_y) const
Check if pixel maps to valid world point.
Definition: bulb.cpp:551
static std::string composeFilename(const char *format)
Compose a filename matching the given format.
Definition: bulb.cpp:678
virtual float getOrientation() const
Get orientation of the omni-camera.
Definition: bulb.cpp:530
Mirror model interface.
Definition: mirrormodel.h:34
Bulb mirror lookup table.
Definition: bulb.h:38
virtual void setOrientation(float angle)
Set orientation of the omni-camera device.
Definition: bulb.cpp:516
Point with cartesian coordinates as unsigned integers.
Definition: types.h:34
float dist_max
maximum distance from mirror center
Definition: bulb.h:123
virtual ~Bulb()
Destructor.
Definition: bulb.cpp:194
const fawkes::polar_coord_2d_t * get_lut() const
Get the raw lookup table.
Definition: bulb.cpp:432
virtual void unwarp2warp(unsigned int unwarp_x, unsigned int unwarp_y, unsigned int *warp_x, unsigned int *warp_y)
Transform unwarped to warped point.
Definition: bulb.cpp:340
unsigned int width
width of LUT
Definition: bulb.h:117
virtual void setCenter(unsigned int image_x, unsigned int image_y)
Set center of omni-camera to given image pixel.
Definition: bulb.cpp:498
float orientation
orientation of camera in image
Definition: bulb.h:121
virtual const char * getName()
Get name of model.
Definition: bulb.cpp:348
void save(const char *filename)
Save LUT from file.
Definition: bulb.cpp:287
virtual void setWorldPoint(unsigned int image_x, unsigned int image_y, float world_r, float world_phi)
Set a world point mapping.
Definition: bulb.cpp:447
unsigned int center_x
x coordinate of mirror center in image
Definition: bulb.h:119
virtual fawkes::cart_coord_2d_t getWorldPointGlobal(unsigned int image_x, unsigned int image_y, float pose_x, float pose_y, float pose_ori) const
Get global coordinate based on image coordinates.
Definition: bulb.cpp:383
float getAngle(unsigned int image_x, unsigned int image_y) const
Angle between direction to point and "to the right".
Definition: bulb.cpp:587
float convertAngleI2W(float angle_in_image) const
convertAngleI2W
Definition: bulb.cpp:621
Shared memory lookup table.
Definition: shm_lut.h:113
unsigned int height
height of LUT
Definition: bulb.h:118