Go to the documentation of this file.00001
00002 #ifndef vbl_bit_array_2d_h_
00003 #define vbl_bit_array_2d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <vcl_iosfwd.h>
00020
00021
00022
00023 class vbl_bit_array_2d
00024 {
00025 public:
00026
00027 vbl_bit_array_2d() : data_(0), num_rows_(0), num_cols_(0) {}
00028
00029 vbl_bit_array_2d(unsigned int m, unsigned int n) { construct(m,n); }
00030
00031 vbl_bit_array_2d(unsigned int m, unsigned int n, bool v) { construct(m,n); fill(v); }
00032
00033 vbl_bit_array_2d(unsigned int m, unsigned int n, bool v[]);
00034
00035 vbl_bit_array_2d(vbl_bit_array_2d const &);
00036
00037 ~vbl_bit_array_2d() { destruct(); }
00038
00039
00040 vbl_bit_array_2d& operator=(vbl_bit_array_2d const&);
00041
00042
00043 bool operator==(vbl_bit_array_2d const &a) const;
00044
00045 bool operator!=(vbl_bit_array_2d const &a) const { return ! operator==(a); }
00046
00047
00048
00049
00050 void fill(bool value);
00051
00052 void resize(unsigned int m, unsigned int n) { destruct(); construct(m,n); }
00053
00054 void enlarge(unsigned int m, unsigned int n);
00055
00056 void clear() { if (data_) { destruct(); construct(0,0); } }
00057
00058
00059 bool operator() (unsigned int i, unsigned int j) const;
00060 bool operator() (unsigned int i, unsigned int j);
00061
00062 void put(unsigned int i, unsigned int j, bool const &x);
00063 bool get(unsigned int i, unsigned int j) const;
00064
00065 void set(unsigned int i, unsigned int j, bool v=true) { put(i, j, v); }
00066
00067 void flip(unsigned int i, unsigned int j) { put(i, j, !get(i,j)); }
00068
00069 inline unsigned int rows() const { return num_rows_; }
00070 inline unsigned int cols() const { return num_cols_; }
00071 inline unsigned int columns() const { return num_cols_; }
00072
00073 unsigned long size() const;
00074
00075 private:
00076 unsigned char *data_;
00077 unsigned int num_rows_;
00078 unsigned int num_cols_;
00079
00080 void destruct() { delete[] data_; data_=0; }
00081 void construct(unsigned int m, unsigned int n);
00082
00083
00084 void index( unsigned int x, unsigned int y, unsigned long &byteindex, unsigned int &bitindex) const;
00085 };
00086
00087 vcl_ostream& operator<< (vcl_ostream& os, const vbl_bit_array_2d &v);
00088
00089 #endif // vbl_bit_array_2d_h_