vbl_bit_array_3d.h
Go to the documentation of this file.
1 // This is core/vbl/vbl_bit_array_3d.h
2 #ifndef vbl_bit_array_3d_h_
3 #define vbl_bit_array_3d_h_
4 //:
5 // \file
6 // \brief contains classes vbl_bit_array_3d_base and vbl_bit_array_3d
7 // \author
8 // Geoffrey Cross, Oxford RRG, 17 Jul 99
9 //
10 // \verbatim
11 // Modifications
12 // 990717 Geoff Initial version.
13 // 011023 Peter Vanroose - renamed and moved to vbl
14 // 040826 Peter Vanroose - adapted interface to that of vbl_array_3d<T>
15 //\endverbatim
16 //
17 //-----------------------------------------------------------------------------
18 
19 #include <iosfwd>
20 #ifdef _MSC_VER
21 # include <vcl_msvc_warnings.h>
22 #endif
23 
24 class vbl_bit_array_3d
25 {
26  public:
27  // Constructors/Destructor---------------------------------------------------
28 
29  //: Create a bitarray of the specified size, without initialising elements
30  vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez)
31  { construct(sizex, sizey, sizez); }
32 
33  //: Create a bitarray of the specified size, with initialisation of elements
34  vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez, bool v)
35  { construct(sizex, sizey, sizez); fill(v); }
36  //: Create a bitarray of the specified size, with initialisation of elements
37  vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez, bool v[]);
38  //: Copy constructor
40  // Destructor
41  ~vbl_bit_array_3d() { delete[] data_; }
42 
43  //: Assignment operator
45 
46  //: Comparison
47  bool operator==(vbl_bit_array_3d const &a) const;
48  //:
49  bool operator!=(vbl_bit_array_3d const &a) const { return ! operator==(a); }
50 
51  // Data Access---------------------------------------------------------------
52 
53  //: Set all cell values to v
54  void fill(bool v);
55 
56  //: Delete contents and resize to m rows x n cols x p layers
57  void resize(unsigned int m, unsigned int n, unsigned int p) { destruct(); construct(m,n,p); }
58 
59  //: make as if default-constructed.
60  void clear() { if (data_) { destruct(); row1_count_=row2_count_=row3_count_=0; } }
61 
62  //: Set the value of a cell
63  void put(unsigned int i1, unsigned int i2, unsigned int i3, bool v);
64 
65  //: Set the value of a cell; default is to set the value on
66  void set(unsigned int i1, unsigned int i2, unsigned int i3, bool v=true)
67  { put(i1, i2, i3, v); }
68 
69  //: Return the value of a cell
70  bool get(unsigned int i1, unsigned int i2, unsigned int i3) const;
71 
72  //: Change the value of a cell
73  void flip(unsigned int i1, unsigned int i2, unsigned int i3);
74 
75  //: Return the value of a cell
76  bool operator() (unsigned int i1, unsigned int i2, unsigned int i3) const;
77 
78  unsigned int row1_count() const { return row1_count_; }
79  unsigned int row2_count() const { return row2_count_; }
80  unsigned int row3_count() const { return row3_count_; }
81  //: Number of bytes allocated by the data
82  unsigned long size() const;
83 
84  private:
85  // Data Members--------------------------------------------------------------
86 
87  unsigned int row1_count_;
88  unsigned int row2_count_;
89  unsigned int row3_count_;
90  unsigned char *data_;
91 
92  // Helpers-------------------------------------------------------------------
93 
94  void destruct() { delete[] data_; data_=nullptr; }
95  void construct(unsigned int m, unsigned int n, unsigned int p);
96 
97  void index(unsigned int x, unsigned int y, unsigned int z,
98  unsigned long &byteindex, unsigned char &bitindex) const;
99 };
100 
101 std::ostream &operator<<(std::ostream &os, vbl_bit_array_3d const&);
102 
103 #endif // vbl_bit_array_3d_h_
bool operator!=(vbl_bit_array_3d const &a) const
void clear()
make as if default-constructed.
void flip(unsigned int i1, unsigned int i2, unsigned int i3)
Change the value of a cell.
bool get(unsigned int i1, unsigned int i2, unsigned int i3) const
Return the value of a cell.
unsigned int row2_count_
void index(unsigned int x, unsigned int y, unsigned int z, unsigned long &byteindex, unsigned char &bitindex) const
vbl_bit_array_3d & operator=(vbl_bit_array_3d const &)
Assignment operator.
bool operator==(vbl_bit_array_3d const &a) const
Comparison.
void resize(unsigned int m, unsigned int n, unsigned int p)
Delete contents and resize to m rows x n cols x p layers.
void set(unsigned int i1, unsigned int i2, unsigned int i3, bool v=true)
Set the value of a cell; default is to set the value on.
vbl_bit_array_3d(unsigned int sizex, unsigned int sizey, unsigned int sizez)
Create a bitarray of the specified size, without initialising elements.
std::ostream & operator<<(std::ostream &os, vbl_bit_array_3d const &)
unsigned int row1_count_
void put(unsigned int i1, unsigned int i2, unsigned int i3, bool v)
Set the value of a cell.
unsigned int row1_count() const
unsigned int row3_count() const
void fill(bool v)
Set all cell values to v.
void construct(unsigned int m, unsigned int n, unsigned int p)
bool operator()(unsigned int i1, unsigned int i2, unsigned int i3) const
Return the value of a cell.
unsigned int row2_count() const
unsigned int row3_count_
unsigned char * data_
unsigned long size() const
Number of bytes allocated by the data.