core/vil/vil_chord.h
Go to the documentation of this file.
00001 #ifndef vil_chord_h_
00002 #define vil_chord_h_
00003 //:
00004 // \file
00005 // \brief Object to store information about position of a row of pixels.
00006 // \author Tim Cootes
00007 
00008 #include <vcl_iostream.h>
00009 #include <vcl_vector.h>
00010 
00011 //: Store information about position of a row of pixels in an image
00012 //  Pixels are ([ilo,ihi],y)
00013 struct vil_chord
00014 {
00015   unsigned ilo;
00016   unsigned ihi;
00017   unsigned j;
00018 
00019   //: Default constructor
00020   vil_chord() : ilo(1),ihi(0),j(0) {}
00021 
00022   //: Construct
00023   vil_chord(unsigned ilo1, unsigned ihi1, unsigned j1)
00024     : ilo(ilo1), ihi(ihi1), j(j1) {}
00025 
00026   //: length == number of pixels
00027   unsigned length() const { return ihi+1-ilo; }
00028 };
00029 
00030 //: Print to stream
00031 inline vcl_ostream& operator<<(vcl_ostream& os, vil_chord c)
00032 {
00033   return os<<"(["<<c.ilo<<','<<c.ihi<<"],"<<c.j<<')';
00034 }
00035 
00036 //: Compute area of region defined by (non-overlapping) chords
00037 inline unsigned vil_area(const vcl_vector<vil_chord>& region)
00038 {
00039   unsigned A=0;
00040   for (unsigned i=0;i<region.size();++i) A+=region[i].length();
00041   return A;
00042 }
00043 
00044 #endif // vil_chord_h_