vgl_region_scan_iterator.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_region_scan_iterator.h
2 #ifndef vgl_region_scan_iterator_h_
3 #define vgl_region_scan_iterator_h_
4 //:
5 // \file
6 // \author fsm
7 // \verbatim
8 // Modifications
9 // Nov.2003 - Peter Vanroose - added lots of documentation
10 // \endverbatim
11 
12 //: Abstract base class for iterating over the pixels in a region of an image.
13 // The region should be "scanline-convex", i.e., every horizontal line should
14 // intersect the region in at most one connected part. Vertically, there may
15 // be even disconnected parts: e.g. (part of) a hyperbola with vertical axis.
16 // The region should of course be bounded, otherwise iteration makes no sense.
18 {
19  protected:
20  inline vgl_region_scan_iterator() = default;
21  virtual ~vgl_region_scan_iterator() = default;
22  public:
23 
24  //: Resets the scan iterator to before the first scan line
25  // After calling this function, next() needs to be called before
26  // startx() and endx() form a valid scan line.
27  virtual void reset() =0;
28 
29  //: Tries to move to the next scan line.
30  // Returns false if there are no more scan lines.
31  virtual bool next() =0;
32 
33  //: y-coordinate of the current scan line.
34  // The next scan line is \e not guaranteed to have scany()+1; use next() instead.
35  virtual int scany() const =0;
36 
37  //: Returns starting x-value of the current scan line.
38  // startx() should be smaller than endx(), unless the scan line is empty
39  virtual int startx() const =0;
40 
41  //: Returns ending x-value of the current scan line.
42  // endx() should be larger than startx(), unless the scan line is empty
43  virtual int endx() const =0;
44 
45  // --- Utility functions ---
46 
47  //: Number of image points (= integer grid points) inside the region
48  inline int count()
49  {
50  int cnt = 0; reset();
51  while (next()) { int n = endx() - startx() + 1; if (n > 0) cnt += n; }
52  return cnt;
53  }
54 };
55 
56 #endif // vgl_region_scan_iterator_h_
virtual int scany() const =0
y-coordinate of the current scan line.
virtual ~vgl_region_scan_iterator()=default
vgl_region_scan_iterator()=default
virtual void reset()=0
Resets the scan iterator to before the first scan line.
virtual bool next()=0
Tries to move to the next scan line.
virtual int endx() const =0
Returns ending x-value of the current scan line.
virtual int startx() const =0
Returns starting x-value of the current scan line.
int count()
Number of image points (= integer grid points) inside the region.
Abstract base class for iterating over the pixels in a region of an image.