Go to the documentation of this file.00001
00002 #ifndef vgl_window_scan_iterator_h_
00003 #define vgl_window_scan_iterator_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <vcl_cmath.h>
00015 #include <vgl/vgl_region_scan_iterator.h>
00016
00017
00018
00019 template <class T>
00020 class vgl_window_scan_iterator : public vgl_region_scan_iterator
00021 {
00022 int x1, y1, x2, y2;
00023 public:
00024
00025
00026 inline void set_window_corners(T x1_, T y1_, T x2_, T y2_)
00027 {
00028
00029 if (x1_ > x2_) { T x=x1_; x1_=x2_; x2_=x; }
00030 x1 = (int) vcl_ceil (x1_);
00031 x2 = (int) vcl_floor(x2_);
00032
00033 if (y1_ <= y2_) {
00034 y1 = (int) vcl_ceil (y1_);
00035 y2 = (int) vcl_floor(y2_);
00036 }
00037 else {
00038 y2 = (int) vcl_ceil (y2_);
00039 y1 = (int) vcl_floor(y1_);
00040 }
00041 }
00042
00043
00044 inline void set_window(T x, T y, T w, T h)
00045 { set_window_corners(x - w, y - h, x + w, y + h); }
00046
00047
00048 inline void set_window(T x, T y, T r)
00049 { set_window_corners(x - r, y - r, x + r, y + r); }
00050
00051
00052 inline vgl_window_scan_iterator() {}
00053
00054
00055 inline vgl_window_scan_iterator(T x1_, T y1_, T x2_, T y2_)
00056 { set_window_corners(x1_, y1_, x2_, y2_); }
00057
00058 int current_y;
00059
00060 inline void reset() { current_y = y1<=y2 ? y1-1 : y1+1; }
00061 inline bool next () { return y1<=y2 ? ++current_y <= y2 : --current_y >= y2; }
00062 inline int scany () const { return current_y; }
00063 inline int startx() const { return x1; }
00064 inline int endx () const { return x2; }
00065 };
00066
00067 #define VGL_WINDOW_SCAN_ITERATOR_INSTANTIATE(T) extern "please include <vgl/vgl_window_scan_iterator.txx> instead"
00068
00069 #endif // vgl_window_scan_iterator_h_