My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ImageHandler.h
Go to the documentation of this file.
1 // $Id: ImageHandler.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_IMAGEHANDLER_H
4 #define GCP_UTIL_IMAGEHANDLER_H
5 
16 #include <iostream>
17 #include <vector>
18 
19 #include "gcp/util/common/Angle.h"
20 #include "gcp/util/common/Mutex.h"
21 
22 #include "gcp/grabber/common/Channel.h"
23 
24 #include "gcp/control/code/unix/libunix_src/common/control.h"
25 #include "gcp/control/code/unix/libunix_src/common/optcam.h"
26 
27 namespace gcp {
28  namespace util {
29 
30  class ImageHandler {
31  public:
32 
33  // Object to encapsulate image statistics
34 
35  struct ImStat {
36  unsigned ixmax_;
37  unsigned iymax_;
38 
39  unsigned ixmin_;
40  unsigned iymin_;
41 
42  double min_;
43  double max_;
44 
45  double mean_;
46  double rms_;
47  double snr_;
48 
49  unsigned n_;
50 
51  friend std::ostream& operator<<(std::ostream& os, ImStat& stat);
52  };
53 
54  // Default optical camera field of view
55 
56  static const gcp::util::Angle defaultFov_;
57 
58  // Default Aspect ratio
59 
60  static const double defaultAspectRatio_;
61 
62  // Default rotation angle for the camera
63 
64  static const gcp::util::Angle defaultRotationAngle_;
65 
66  // For experiments with a "deck" axis, this will store the
67  // default sense of the deck rotaion (ie, CW or CCW)
68 
69  static const gcp::control::RotationSense defaultDeckAngleRotationSense_;
70 
71  // Default channel
72 
73  static const gcp::grabber::Channel::FgChannel defaultChannel_;
74 
75  // The Default flatfielding type
76 
77  static const unsigned defaultFlatfieldType_;
78 
79  // The number of frames to combine
80 
81  static const unsigned defaultNcombine_;
82 
83  // The sense of the x,y-axis increment
84 
85  static const gcp::control::ImDir defaultXImDir_;
86  static const gcp::control::ImDir defaultYImDir_;
87 
91  ImageHandler();
92 
96  ImageHandler(const ImageHandler& objToBeCopied);
97 
101  ImageHandler(ImageHandler& objToBeCopied);
102 
106  void operator=(const ImageHandler& objToBeAssigned);
107 
111  void operator=(ImageHandler& objToBeAssigned);
112 
116  friend std::ostream& operator<<(std::ostream& os, ImageHandler& obj);
117 
121  virtual ~ImageHandler();
122 
123  //------------------------------------------------------------
124  // The following functions are virtual, so that inheritors can
125  // define what else, if anything, should happen when these
126  // parameters are reset
127  //------------------------------------------------------------
128 
129  // Public method to set the deck angle rotation sense
130 
131  virtual void setDeckAngleRotationSense(gcp::control::RotationSense sense);
132 
133  // Public method to set the number of images to combine
134 
135  virtual void setNCombine(unsigned ncombine);
136 
137  // Public method to set the channel
138 
139  virtual void setChannel(gcp::grabber::Channel::FgChannel channel);
140 
141  virtual void setChannel(unsigned channel);
142 
143  // Public method to set the flatfield
144 
145  virtual void setFlatfieldType(unsigned flatfieldType);
146 
147  // Public method to set the optical camera image directions
148 
149  virtual void setXImDir(gcp::control::ImDir dir);
150 
151 
152  // Public method to set the optical camera image directions
153 
154  virtual void setYImDir(gcp::control::ImDir dir);
155 
156  // Public method to reset the optical camera FOV
157 
158  virtual void setFov(const gcp::util::Angle& fov);
159 
160  // Public method to set the optical camera FOV
161 
162  virtual void setAspectRatio(double aspectRatio);
163 
164  // Public method to set the optical camera collimation
165 
166  virtual void setRotationAngle(const gcp::util::Angle& rotationAngle);
167 
168  // Public method to set the deck angle
169 
170  virtual void setDeckAngle(const gcp::util::Angle& deckAngle);
171 
172  // Install a new image in the image buffer
173 
174  virtual void installNewImage(unsigned short* image);
175 
176  virtual void installNewImage(unsigned short* image, unsigned int utc[2],
178  gcp::util::Angle* dk=0);
179 
180  // Get statistics on the last received image
181 
182  ImStat getStats();
183  virtual ImStat getStats(unsigned ixmin, unsigned iymin,
184  unsigned ixmax, unsigned iymax);
185 
186  // Return the offset of the peak in x and y, converted to
187  // horizontal and vertical offsets, in degrees
188 
189  void getOffsetInfo(gcp::util::Angle& horiz, gcp::util::Angle& vert,
190  unsigned& ipeak, unsigned& jpeak);
191 
195  void getPeakInfo(double& peak, double& snr);
196 
197  void addIncludeBox(unsigned ixmin, unsigned iymin,
198  unsigned ixmax, unsigned iymax);
199 
200  void addExcludeBox(unsigned ixmin, unsigned iymin,
201  unsigned ixmax, unsigned iymax);
202 
203  void deleteNearestBox(unsigned ix, unsigned iy);
204  void deleteAllBoxes();
205 
206  class Box {
207  public:
208 
209  // Enumerate possible positions of a point w.r.t. this box
210 
211  enum Location {
212  INSIDE,
213 
214  ABOVE_LEFT,
215  ABOVE,
216  ABOVE_RIGHT,
217 
218  RIGHT,
219 
220  BELOW_RIGHT,
221  BELOW,
222  BELOW_LEFT,
223 
224  LEFT
225  };
226 
227  // The boundaries of this box
228 
229  unsigned ixmin_;
230  unsigned ixmax_;
231  unsigned iymin_;
232  unsigned iymax_;
233 
234  // True if this box defines an area that should be included
235  // False if this box defines an area that should be excluded
236 
237  bool inc_;
238 
239  // Return the shortest distance from this box
240 
241  double shortestDistanceFrom(unsigned ix, unsigned iy);
242 
243  // Return the orientation of a pixel wrt to this box
244 
245  Location locationOf(unsigned ix, unsigned iy);
246 
247  // Check passed limits. Rearrange if min > max, and truncate
248  // pixel values that exceed the image size
249 
250  void rectifyCoords(unsigned& ixmin, unsigned& iymin,
251  unsigned& ixmax, unsigned& iymax);
252 
253  // Constructors and assignment operators
254 
255  Box();
256 
257  Box(unsigned ixmin, unsigned ixmax,
258  unsigned iymin, unsigned iymax,
259  bool inc);
260 
261  Box(const Box& box);
262 
263  Box(Box& box);
264 
265  void operator=(const Box& box);
266 
267  void operator=(Box& box);
268  };
269 
270  std::vector<Box> boxes_;
271 
272  gcp::util::Angle fov_;
273  double aspectRatio_;
274  gcp::util::Angle deckAngle_;
275  gcp::util::Angle rotationAngle_;
276  gcp::control::RotationSense deckAngleRotationSense_;
277  gcp::grabber::Channel::FgChannel channel_;
278  unsigned flatfieldType_;
279  unsigned nCombine_;
280  gcp::control::ImDir xImDir_;
281  gcp::control::ImDir yImDir_;
282 
283  std::vector<unsigned short> imageToArchive_;
284 
285  protected:
286 
287  bool haveImage_; // True when an image has been installed
288  double dx_; // The x-increment of a pixel
289  double dy_; // The y-increment of a pixel
290  double xa_; // The x-coordinate of the blc of the image
291  double ya_; // The y-coordinate of the blc of the image
292  double xb_; // The x-coordinate of the trc of the image
293  double yb_; // The y-coordinate of the trc of the image
294 
295  // Size of the image, in pixels
296 
297  unsigned nx_;
298  unsigned ny_;
299 
300  bool usePixel_[GRABBER_IM_SIZE];
301  unsigned short imageToStore_[GRABBER_IM_SIZE];
302  unsigned int utc_[2];
303 
304  //------------------------------------------------------------
305  // Public access to locks on this object
306  //------------------------------------------------------------
307 
308  void lock() {
309  guard_.lock();
310  }
311 
312  void unlock() {
313  guard_.unlock();
314  }
315 
316  // Convert from util pixel offset to sky offset
317 
318  void pixelToSkyOffset(unsigned ix, unsigned iy, gcp::util::Angle& xsky, gcp::util::Angle& ysky);
319 
320  private:
321 
322  gcp::util::Mutex guard_;
323 
324  // Initialize image parameters to defaults
325 
326  void initializeCameraDefaults();
327 
328  // Initialize image statistics to defaults
329 
330  void initializeImageStats();
331 
332  void initialize();
333 
334  void updatePixelFlags();
335 
336  bool pixelIsExcluded(unsigned ix, unsigned iy);
337 
338  static void rectifyCoords(unsigned& ixmin, unsigned& ixmax,
339  unsigned& iymin, unsigned& iymax);
340 
341  }; // End class ImageHandler
342 
343  } // End namespace util
344 } // End namespace gcp
345 
346 
347 
348 #endif // End #ifndef GCP_UTIL_IMAGEHANDLER_H
void unlock()
Definition: Mutex.cc:104
friend std::ostream & operator<<(std::ostream &os, ImageHandler &obj)
void getOffsetInfo(gcp::util::Angle &horiz, gcp::util::Angle &vert, unsigned &ipeak, unsigned &jpeak)
Definition: ImageHandler.cc:469
void operator=(const Box &box)
Definition: ImageHandler.cc:821
virtual void setFov(const gcp::util::Angle &fov)
Definition: ImageHandler.cc:522
void pixelToSkyOffset(unsigned ix, unsigned iy, gcp::util::Angle &xsky, gcp::util::Angle &ysky)
Definition: ImageHandler.cc:586
virtual void setDeckAngleRotationSense(gcp::control::RotationSense sense)
Definition: ImageHandler.cc:498
ImStat getStats()
Definition: ImageHandler.cc:328
ImageHandler()
Definition: ImageHandler.cc:131
virtual void setDeckAngle(const gcp::util::Angle &deckAngle)
Definition: ImageHandler.cc:546
virtual void setNCombine(unsigned ncombine)
Definition: ImageHandler.cc:554
Definition: ImageHandler.h:35
Definition: ImageHandler.h:30
virtual void setYImDir(gcp::control::ImDir dir)
Definition: ImageHandler.cc:514
Definition: ImageHandler.h:206
void lock()
Definition: Mutex.cc:72
Definition: Mutex.h:16
virtual ~ImageHandler()
Definition: ImageHandler.cc:220
virtual void installNewImage(unsigned short *image)
Definition: ImageHandler.cc:225
Definition: Angle.h:20
virtual void setRotationAngle(const gcp::util::Angle &rotationAngle)
Definition: ImageHandler.cc:538
double shortestDistanceFrom(unsigned ix, unsigned iy)
Definition: ImageHandler.cc:873
Box()
Definition: ImageHandler.cc:778
void getPeakInfo(double &peak, double &snr)
Definition: ImageHandler.cc:485
virtual void setChannel(gcp::grabber::Channel::FgChannel channel)
Definition: ImageHandler.cc:562
void operator=(const ImageHandler &objToBeAssigned)
Definition: ImageHandler.cc:155
virtual void setXImDir(gcp::control::ImDir dir)
Definition: ImageHandler.cc:506
Location locationOf(unsigned ix, unsigned iy)
Definition: ImageHandler.cc:939
virtual void setFlatfieldType(unsigned flatfieldType)
Definition: ImageHandler.cc:578