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