vil_chord.h
Go to the documentation of this file.
1 #ifndef vil_chord_h_
2 #define vil_chord_h_
3 //:
4 // \file
5 // \brief Object to store information about position of a row of pixels.
6 // \author Tim Cootes
7 
8 #include <iostream>
9 #include <vector>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 
14 //: Store information about position of a row of pixels in an image
15 // Pixels are ([ilo,ihi],y)
16 struct vil_chord
17 {
18  unsigned ilo;
19  unsigned ihi;
20  unsigned j;
21 
22  //: Default constructor
23  vil_chord() : ilo(1),ihi(0),j(0) {}
24 
25  //: Construct
26  vil_chord(unsigned ilo1, unsigned ihi1, unsigned j1)
27  : ilo(ilo1), ihi(ihi1), j(j1) {}
28 
29  //: length == number of pixels
30  unsigned length() const { return ihi+1-ilo; }
31 };
32 
33 //: Print to stream
34 inline std::ostream& operator<<(std::ostream& os, vil_chord c)
35 {
36  return os<<"(["<<c.ilo<<','<<c.ihi<<"],"<<c.j<<')';
37 }
38 
39 //: Compute area of region defined by (non-overlapping) chords
40 inline unsigned vil_area(const std::vector<vil_chord>& region)
41 {
42  unsigned A=0;
43  for (auto i : region) A+=i.length();
44  return A;
45 }
46 
47 #endif // vil_chord_h_
unsigned j
Definition: vil_chord.h:20
vil_chord(unsigned ilo1, unsigned ihi1, unsigned j1)
Construct.
Definition: vil_chord.h:26
unsigned ilo
Definition: vil_chord.h:18
vil_chord()
Default constructor.
Definition: vil_chord.h:23
unsigned ihi
Definition: vil_chord.h:19
Store information about position of a row of pixels in an image.
Definition: vil_chord.h:16
unsigned length() const
length == number of pixels.
Definition: vil_chord.h:30
std::ostream & operator<<(std::ostream &os, vil_chord c)
Print to stream.
Definition: vil_chord.h:34
unsigned vil_area(const std::vector< vil_chord > &region)
Compute area of region defined by (non-overlapping) chords.
Definition: vil_chord.h:40