core/vbl/vbl_bit_array_3d.h
Go to the documentation of this file.
00001 // This is core/vbl/vbl_bit_array_3d.h
00002 #ifndef vbl_bit_array_3d_h_
00003 #define vbl_bit_array_3d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief contains classes vbl_bit_array_3d_base and vbl_bit_array_3d
00010 // \author
00011 //     Geoffrey Cross, Oxford RRG, 17 Jul 99
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   990717 Geoff Initial version.
00016 //   011023 Peter Vanroose - renamed and moved to vbl
00017 //   040826 Peter Vanroose - adapted interface to that of vbl_array_3d<T>
00018 //\endverbatim
00019 //
00020 //-----------------------------------------------------------------------------
00021 
00022 #include <vcl_iosfwd.h>
00023 
00024 class vbl_bit_array_3d
00025 {
00026  public:
00027   // Constructors/Destructor---------------------------------------------------
00028 
00029   //: Create a bitarray of the specified size, without initialising elements
00030   vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez)
00031   { construct(sizex, sizey, sizez); }
00032 
00033   //: Create a bitarray of the specified size, with initialisation of elements
00034   vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez, bool v)
00035   { construct(sizex, sizey, sizez); fill(v); }
00036   //: Create a bitarray of the specified size, with initialisation of elements
00037   vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez, bool v[]);
00038   //: Copy constructor
00039   vbl_bit_array_3d(vbl_bit_array_3d const &);
00040   // Destructor
00041   ~vbl_bit_array_3d() { delete[] data_; }
00042 
00043   //: Assignment operator
00044   vbl_bit_array_3d& operator=(vbl_bit_array_3d const&);
00045 
00046   //: Comparison
00047   bool operator==(vbl_bit_array_3d const &a) const;
00048   //:
00049   bool operator!=(vbl_bit_array_3d const &a) const { return ! operator==(a); }
00050 
00051   // Data Access---------------------------------------------------------------
00052 
00053   //: Set all cell values to v
00054   void fill(bool v);
00055 
00056   //: Delete contents and resize to m rows x n cols x p layers
00057   void resize(unsigned int m, unsigned int n, unsigned int p) { destruct(); construct(m,n,p); }
00058 
00059   //: make as if default-constructed.
00060   void clear() { if (data_) { destruct(); row1_count_=row2_count_=row3_count_=0; } }
00061 
00062   //: Set the value of a cell
00063   void put(unsigned int i1, unsigned int i2, unsigned int i3, bool v);
00064 
00065   //: Set the value of a cell; default is to set the value on
00066   void set(unsigned int i1, unsigned int i2, unsigned int i3, bool v=true)
00067   { put(i1, i2, i3, v); }
00068 
00069   //: Return the value of a cell
00070   bool get(unsigned int i1, unsigned int i2, unsigned int i3) const;
00071 
00072   //: Change the value of a cell
00073   void flip(unsigned int i1, unsigned int i2, unsigned int i3);
00074 
00075   //: Return the value of a cell
00076   bool operator() (unsigned int i1, unsigned int i2, unsigned int i3) const;
00077 
00078   unsigned int row1_count() const { return row1_count_; }
00079   unsigned int row2_count() const { return row2_count_; }
00080   unsigned int row3_count() const { return row3_count_; }
00081   //: Number of bytes allocated by the data
00082   unsigned long size() const;
00083 
00084  private:
00085   // Data Members--------------------------------------------------------------
00086 
00087   unsigned int row1_count_;
00088   unsigned int row2_count_;
00089   unsigned int row3_count_;
00090   unsigned char *data_;
00091 
00092   // Helpers-------------------------------------------------------------------
00093 
00094   void destruct() { delete[] data_; data_=0; }
00095   void construct(unsigned int m, unsigned int n, unsigned int p);
00096 
00097   void index(unsigned int x, unsigned int y, unsigned int z,
00098              unsigned long &byteindex, unsigned char &bitindex) const;
00099 };
00100 
00101 vcl_ostream &operator<<(vcl_ostream &os, vbl_bit_array_3d const&);
00102 
00103 #endif // vbl_bit_array_3d_h_