Go to the documentation of this file.00001
00002 #ifndef bbgm_feature_image_h_
00003 #define bbgm_feature_image_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vbl/vbl_array_2d.h>
00016 #include <vbl/vbl_ref_count.h>
00017 #include <vsl/vsl_binary_io.h>
00018 #include <vsl/vsl_binary_loader.h>
00019 #include <vcl_iostream.h>
00020
00021
00022 class bbgm_feature_image_base : public vbl_ref_count
00023 {
00024 public:
00025 virtual ~bbgm_feature_image_base(){}
00026
00027
00028 virtual void b_write(vsl_b_ostream &os) const=0;
00029
00030
00031 virtual void b_read(vsl_b_istream &is)=0;
00032
00033 virtual vcl_string is_a() const=0;
00034
00035 virtual bbgm_feature_image_base* clone() const = 0;
00036
00037 virtual unsigned int ni() const = 0;
00038 virtual unsigned int nj() const = 0;
00039 };
00040
00041
00042 template<class f_type_>
00043 class bbgm_feature_image : public bbgm_feature_image_base
00044 {
00045 public:
00046
00047 bbgm_feature_image<f_type_>() {}
00048 bbgm_feature_image<f_type_>(unsigned int ni, unsigned int nj): data_(nj,ni) {}
00049 bbgm_feature_image<f_type_>(unsigned int ni, unsigned int nj,
00050 f_type_ const& feature) : data_(nj,ni,feature) {}
00051
00052
00053
00054 unsigned int ni() const { return data_.cols(); }
00055
00056
00057 unsigned int nj() const { return data_.rows(); }
00058
00059
00060
00061 void set_size(unsigned ni, unsigned nj) { data_.resize(nj,ni); }
00062
00063
00064 const f_type_& operator() (unsigned int i, unsigned int j) const
00065 { return data_(j,i); }
00066
00067
00068 f_type_& operator() (unsigned int i, unsigned int j)
00069 { return data_(j,i); }
00070
00071
00072 void set(unsigned int i, unsigned int j, const f_type_& d)
00073 { data_(j,i) = d; }
00074
00075
00076 class iterator
00077 {
00078 public:
00079 iterator(f_type_* ptr) : ptr_(ptr) {}
00080 iterator(const iterator& other) : ptr_(other.ptr_) {}
00081 iterator& operator++() { ++ptr_; return *this; }
00082 f_type_& operator*(){ return *ptr_; }
00083 f_type_* operator -> () { return ptr_; }
00084 bool operator==(const iterator& other) { return ptr_ == other.ptr_; }
00085 bool operator!=(const iterator& other) { return ptr_ != other.ptr_; }
00086
00087 private:
00088 f_type_* ptr_;
00089 };
00090
00091 class const_iterator
00092 {
00093 public:
00094 const_iterator(const f_type_* ptr) : ptr_(ptr) {}
00095 const_iterator(const const_iterator& other) : ptr_(other.ptr_) {}
00096 const_iterator& operator++() { ++ptr_; return *this; }
00097 const f_type_& operator*(){ return *ptr_; }
00098 const f_type_* operator -> () { return ptr_; }
00099 bool operator==(const const_iterator& other) { return ptr_ == other.ptr_; }
00100 bool operator!=(const const_iterator& other) { return ptr_ != other.ptr_; }
00101
00102 private:
00103 const f_type_* ptr_;
00104 };
00105
00106
00107 iterator begin() { return iterator(data_[0]); }
00108
00109 iterator end() { return iterator(data_[0]+data_.size()); }
00110
00111 const_iterator begin() const { return const_iterator(data_[0]); }
00112
00113 const_iterator end() const { return const_iterator(data_[0]+data_.size()); }
00114
00115
00116
00117
00118
00119
00120 virtual vcl_string is_a() const;
00121
00122 virtual bbgm_feature_image_base* clone() const;
00123
00124
00125 short version() const;
00126
00127
00128 virtual void b_write(vsl_b_ostream &os) const;
00129
00130
00131 virtual void b_read(vsl_b_istream &is);
00132
00133 private:
00134
00135 vbl_array_2d<f_type_ > data_;
00136 };
00137
00138 template <class f_type_>
00139 void vsl_print_summary(vcl_ostream& os,
00140 const bbgm_feature_image<f_type_> & b)
00141 { os << "not yet implemented for bbgm_feature_image\n";}
00142
00143
00144
00145 template <class f_type_>
00146 void vsl_b_write(vsl_b_ostream &os, const bbgm_feature_image<f_type_>& b)
00147 {
00148 b.b_write(os);
00149 }
00150
00151
00152 template <class f_type_>
00153 void vsl_b_read(vsl_b_istream &is, bbgm_feature_image<f_type_>& b)
00154 {
00155 bbgm_feature_image<f_type_> temp;
00156 temp.b_read(is);
00157 b = temp;
00158 }
00159
00160
00161
00162 void vsl_add_to_binary_loader(bbgm_feature_image_base const& b);
00163
00164
00165 #endif // bbgm_feature_image_h_