00001 // This is core/vgl/vgl_region_scan_iterator.h 00002 #ifndef vgl_region_scan_iterator_h_ 00003 #define vgl_region_scan_iterator_h_ 00004 //: 00005 // \file 00006 // \author fsm 00007 // \verbatim 00008 // Modifications 00009 // Nov.2003 - Peter Vanroose - added lots of documentation 00010 // \endverbatim 00011 00012 //: Abstract base class for iterating over the pixels in a region of an image. 00013 // The region should be "scanline-convex", i.e., every horizontal line should 00014 // intersect the region in at most one connected part. Vertically, there may 00015 // be even disconnected parts: e.g. (part of) a hyperbola with vertical axis. 00016 // The region should of course be bounded, otherwise iteration makes no sense. 00017 class vgl_region_scan_iterator 00018 { 00019 protected: 00020 inline vgl_region_scan_iterator() {} 00021 virtual ~vgl_region_scan_iterator() {} 00022 public: 00023 00024 //: Resets the scan iterator to before the first scan line 00025 // After calling this function, next() needs to be called before 00026 // startx() and endx() form a valid scan line. 00027 virtual void reset() =0; 00028 00029 //: Tries to move to the next scan line. 00030 // Returns false if there are no more scan lines. 00031 virtual bool next() =0; 00032 00033 //: y-coordinate of the current scan line. 00034 // The next scan line is \e not guaranteed to have scany()+1; use next() instead. 00035 virtual int scany() const =0; 00036 00037 //: Returns starting x-value of the current scan line. 00038 // startx() should be smaller than endx(), unless the scan line is empty 00039 virtual int startx() const =0; 00040 00041 //: Returns ending x-value of the current scan line. 00042 // endx() should be larger than startx(), unless the scan line is empty 00043 virtual int endx() const =0; 00044 00045 // --- Utility functions --- 00046 00047 //: Number of image points (= integer grid points) inside the region 00048 inline int count() 00049 { 00050 int cnt = 0; reset(); 00051 while (next()) { int n = endx() - startx() + 1; if (n > 0) cnt += n; } 00052 return cnt; 00053 } 00054 }; 00055 00056 #endif // vgl_region_scan_iterator_h_