bulb.h

00001 /***************************************************************************
00002  *  bulb.h - class defining a light bulb as mirror
00003  *
00004  *  Generated: Thu Jul 21 14:25:00 2005
00005  *  Copyright 2005-2006 Tim Niemueller [www.niemueller.de]
00006  *            2005      Martin Heracles
00007  *
00008  ****************************************************************************/
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. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __FIREVISION_MODELS_MIRROR_BULB_H_
00025 #define __FIREVISION_MODELS_MIRROR_BULB_H_
00026 
00027 #include <models/mirror/mirrormodel.h>
00028
00029 #include <string>
00030
00031 class SharedMemoryLookupTable;
00032
00033 class Bulb : public MirrorModel {
00034
00035   friend class BulbGenerator;
00036
00037  public:
00038
00039   // This constructor loads an existing bulb model (lut) from file "filename".
00040   Bulb(const char *filename);
00041   Bulb(const char *filename,
00042        const char *lut_id, bool destroy_on_delete = false);
00043
00044   Bulb(unsigned int width, unsigned int height);
00045   Bulb(unsigned int width, unsigned int height,
00046        const char *lut_id, bool destroy_on_delete = false);
00047
00048   Bulb(const Bulb &bulb);
00049
00050   virtual ~Bulb();
00051
00052   virtual void warp2unwarp(unsigned int warp_x, unsigned int warp_y,
00053                            unsigned int *unwarp_x, unsigned int *unwarp_y);
00054   virtual void unwarp2warp(unsigned int unwarp_x, unsigned int unwarp_y,
00055                            unsigned int *warp_x, unsigned int *warp_y    );
00056
00057   virtual const char * getName();
00058
00059   virtual bool isValid();
00060
00061
00062   virtual void setWorldPoint(unsigned int image_x,
00063                              unsigned int image_y,
00064                              float        world_r,
00065                              float        world_phi);
00066
00067
00068   virtual fawkes::polar_coord_2d_t getWorldPointRelative(unsigned int image_x,
00069                                                          unsigned int image_y  ) const;
00070
00071   virtual fawkes::cart_coord_2d_t getWorldPointGlobal(unsigned int image_x,
00072                                                       unsigned int image_y,
00073                                                       float pose_x, float pose_y,
00074                                                       float pose_ori ) const;
00075
00076   virtual void reset();
00077
00078   virtual fawkes::point_t getCenter() const;
00079   virtual void setCenter(unsigned int image_x,
00080                          unsigned int image_y  );
00081   virtual void setOrientation(float angle);
00082   virtual float getOrientation() const;
00083
00084   virtual bool isValidPoint( unsigned int image_x, unsigned int image_y ) const;
00085
00086
00087   bool isNonZero(unsigned int image_x,
00088                  unsigned int image_y  ) const;
00089
00090   unsigned int numNonZero() const;
00091
00092
00093   float getAngle(unsigned int image_x,
00094                  unsigned int image_y  ) const;
00095
00096   float getDistanceInImage(unsigned int image_p1_x, unsigned int image_p1_y,
00097                            unsigned int image_p2_x, unsigned int image_p2_y  );
00098
00099   float convertAngleI2W (float angle_in_image) const;
00100
00101
00102   void load(const char * filename);
00103   void save(const char * filename);
00104
00105   static std::string composeFilename(const char * format);
00106
00107  protected:
00108 
00109   /** bulb file header. */
00110   typedef struct {
00111     unsigned int width;         /**< width of LUT */
00112     unsigned int height;        /**< height of LUT */
00113     unsigned int center_x;      /**< x coordinate of mirror center in image */
00114     unsigned int center_y;      /**< y coordinate of mirror center in image */
00115     float        orientation;   /**< orientation of camera in image */
00116     float        dist_min;      /**< minimum distance from mirror center */
00117     float        dist_max;      /**< maximum distance from mirror center */
00118   } bulb_file_header_t;
00119
00120
00121  private:
00122   void create();
00123   void erase();
00124   void init();
00125
00126  private:
00127
00128   // dimension of lut (and image)
00129   unsigned int width;
00130   unsigned int height;
00131   unsigned int bytes_per_sample;
00132
00133   // center of omni camera device
00134   unsigned int image_center_x;
00135   unsigned int image_center_y;
00136
00137   // orientation of omni camera device
00138   float orientation;
00139
00140   // distance of closest and of farthest sample point
00141   float distance_min;
00142   float distance_max;
00143
00144   bool valid;
00145
00146   char          *lut_id;
00147   fawkes::polar_coord_2d_t *lut;
00148   unsigned int   lut_bytes;
00149   bool destroy_on_delete;
00150
00151   SharedMemoryLookupTable *shm_lut;
00152
00153
00154 };
00155
00156 #endif