Go to the documentation of this file.00001
00002 #ifndef vil3d_chord_h_
00003 #define vil3d_chord_h_
00004
00005
00006
00007
00008
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vcl_vector.h>
00011 #include <vcl_iostream.h>
00012
00013
00014 class vil3d_chord
00015 {
00016 private:
00017 int start_x_;
00018 int end_x_;
00019 int y_;
00020 int z_;
00021 public:
00022
00023 vil3d_chord() : start_x_(0),end_x_(-1),y_(0),z_(0) {}
00024
00025
00026 vil3d_chord(int start_x, int end_x, int y, int z)
00027 : start_x_(start_x), end_x_(end_x), y_(y), z_(z) {}
00028
00029
00030 int start_x() const { return start_x_; }
00031
00032
00033 int end_x() const { return end_x_; }
00034
00035
00036 int y() const { return y_; }
00037
00038
00039 int z() const { return z_; }
00040
00041
00042 int length() const { return 1+end_x_-start_x_; }
00043
00044
00045 inline void b_write(vsl_b_ostream& bfs) const;
00046
00047
00048 inline void b_read(vsl_b_istream& bfs);
00049
00050
00051 bool operator==(const vil3d_chord& c) const;
00052 };
00053
00054
00055
00056 inline unsigned vil3d_volume(const vcl_vector<vil3d_chord>& chords)
00057 {
00058 if (chords.size()==0) return 0;
00059 unsigned n=0;
00060 vcl_vector<vil3d_chord>::const_iterator c = chords.begin();
00061 for (;c!=chords.end();++c) n+=c->length();
00062 return n;
00063 }
00064
00065
00066
00067 inline void vil3d_chord::b_write(vsl_b_ostream& bfs) const
00068 {
00069 vsl_b_write(bfs,start_x_);
00070 vsl_b_write(bfs,end_x_);
00071 vsl_b_write(bfs,y_);
00072 vsl_b_write(bfs,z_);
00073 }
00074
00075
00076 inline void vil3d_chord::b_read(vsl_b_istream& bfs)
00077 {
00078 vsl_b_read(bfs,start_x_);
00079 vsl_b_read(bfs,end_x_);
00080 vsl_b_read(bfs,y_);
00081 vsl_b_read(bfs,z_);
00082 }
00083
00084 inline bool vil3d_chord::operator==(const vil3d_chord& c) const
00085 {
00086 return start_x_ ==c.start_x_ && end_x_==c.end_x_ && y_==c.y_ && z_==c.z_;
00087 }
00088
00089
00090 inline vcl_ostream& operator<<(vcl_ostream& os, const vil3d_chord& c)
00091 {
00092 return os<<"(["<<c.start_x()<<","<<c.end_x()<<"],"<<c.y()<<","<<c.z()<<")";
00093 }
00094
00095
00096 inline void vsl_b_write(vsl_b_ostream& bfs, const vil3d_chord& t)
00097 {
00098 t.b_write(bfs);
00099 }
00100
00101
00102 inline void vsl_b_write(vsl_b_ostream& bfs,
00103 const vcl_vector<vil3d_chord>& t)
00104 {
00105 vsl_b_write(bfs,unsigned(t.size()));
00106 for (unsigned i=0;i<t.size();++i) t[i].b_write(bfs);
00107 }
00108
00109
00110 inline void vsl_b_read(vsl_b_istream& bfs, vil3d_chord& t)
00111 {
00112 t.b_read(bfs);
00113 }
00114
00115
00116 inline void vsl_b_read(vsl_b_istream& bfs,
00117 vcl_vector<vil3d_chord>& t)
00118 {
00119 unsigned n;
00120 vsl_b_read(bfs,n);
00121 t.resize(n);
00122 for (unsigned i=0;i<n;++i) t[i].b_read(bfs);
00123 }
00124
00125
00126 inline void vsl_print_summary(vcl_ostream& os, const vil3d_chord& t)
00127 {
00128 os<<t;
00129 }
00130
00131 #endif // vil3d_chord_h_