contrib/mul/mbl/mbl_chord.h
Go to the documentation of this file.
00001 // This is mul/mbl/mbl_chord.h
00002 #ifndef mbl_chord_h_
00003 #define mbl_chord_h_
00004 //:
00005 // \file
00006 // \author Tim Cootes
00007 // \brief Horizontal line used in images, with integer co-ordinates
00008 
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vcl_iostream.h>
00011 
00012 //: Horizontal line used in images, with integer co-ordinates
00013 
00014 class mbl_chord
00015 {
00016 private:
00017   int start_x_;
00018   int end_x_;
00019   int y_;
00020 public:
00021     //: Constructor
00022   mbl_chord() : start_x_(0),end_x_(-1),y_(0) {}
00023 
00024     //: Constructor
00025   mbl_chord(int start_x, int end_x, int y)
00026     : start_x_(start_x), end_x_(end_x), y_(y) {}
00027 
00028     //: X-ordinate of start
00029   int start_x() const { return start_x_; }
00030 
00031     //: X-ordinate of end
00032   int end_x() const { return end_x_; }
00033 
00034     //: y-ordinate
00035   int y() const { return y_; }
00036 
00037     //: Length
00038   int length() const { return 1+end_x_-start_x_; }
00039 
00040     //: Write to binary stream
00041   inline void b_write(vsl_b_ostream& bfs) const;
00042 
00043     //: Read from binary stream
00044   inline void b_read(vsl_b_istream& bfs);
00045 
00046     //: Comparison
00047   bool operator==(const mbl_chord& c) const;
00048 };
00049 
00050     //: Write to binary stream
00051 inline void mbl_chord::b_write(vsl_b_ostream& bfs) const
00052 {
00053   vsl_b_write(bfs,start_x_);
00054   vsl_b_write(bfs,end_x_);
00055   vsl_b_write(bfs,y_);
00056 }
00057 
00058 //: Read from binary stream
00059 inline void mbl_chord::b_read(vsl_b_istream& bfs)
00060 {
00061   vsl_b_read(bfs,start_x_);
00062   vsl_b_read(bfs,end_x_);
00063   vsl_b_read(bfs,y_);
00064 }
00065 
00066 inline bool mbl_chord::operator==(const mbl_chord& c) const
00067 {
00068   return start_x_ ==c.start_x_ && end_x_==c.end_x_ && y_==c.y_;
00069 }
00070 
00071 //: Print
00072 inline vcl_ostream& operator<<(vcl_ostream& os, const mbl_chord& c)
00073 {
00074   return os<<"(["<<c.start_x()<<","<<c.end_x()<<"],"<<c.y()<<")";
00075 }
00076 
00077 //: Save
00078 inline void vsl_b_write(vsl_b_ostream& bfs, const mbl_chord& t)
00079 {
00080   t.b_write(bfs);
00081 }
00082 
00083 //: Load
00084 inline void vsl_b_read(vsl_b_istream& bfs, mbl_chord& t)
00085 {
00086   t.b_read(bfs);
00087 }
00088 
00089 //: Print
00090 inline void vsl_print_summary(vcl_ostream& os, const mbl_chord& t)
00091 {
00092   os<<t;
00093 }
00094 
00095 #endif // mbl_chord_h_