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