16 # include <vcl_msvc_warnings.h> 22 unsigned long byteindex;
23 unsigned char bitindex;
25 index(i1, i2, i3, byteindex, bitindex);
27 auto mask = (
unsigned char)(v?(1<<bitindex):0);
28 auto nmask = (
unsigned char)(~(1<<bitindex));
30 data_[byteindex] = mask|(nmask &
data_[byteindex]);
35 unsigned long byteindex;
36 unsigned char bitindex;
38 index(i1, i2, i3, byteindex, bitindex);
40 auto mask = (
unsigned char)((
data_[byteindex] & (1<<bitindex)) ? 0 : (1<<bitindex));
41 auto nmask = (
unsigned char)(~(1<<bitindex));
43 data_[byteindex] = mask|(nmask &
data_[byteindex]);
48 unsigned char temp = v ? ~(
unsigned char)0 : 0;
54 unsigned long byteindex;
55 unsigned char bitindex;
57 index(i1, i2, i3, byteindex, bitindex);
58 auto mask = (
unsigned char)(1<<bitindex);
60 return (
data_[byteindex] & mask) != 0;
64 unsigned long & byteindex,
65 unsigned char & bitindex)
const 70 byteindex = i/CHAR_BIT;
71 bitindex = (
unsigned char)(i%CHAR_BIT);
79 for (
unsigned int i=0; i< bitarray.
row3_count(); ++i)
81 for (
unsigned int j=0; j< bitarray.
row2_count(); ++j)
83 for (
unsigned int k=0; k< bitarray.
row1_count(); ++k)
84 os << (bitarray(k,j,i) ?
'x' :
'.');
103 : row1_count_(0), row2_count_(0), row3_count_(0), data_(nullptr)
115 for (
unsigned int x=0; x<m; ++x)
116 for (
unsigned int y=0; y<n; ++y)
117 for (
unsigned int z=0; z<p; ++z)
118 set(x,y,z, v[(n*z+y)*m+x]);
139 return 0 == std::memcmp(
data_, a.
data_, this->size());
void flip(unsigned int i1, unsigned int i2, unsigned int i3)
Change the value of a cell.
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.
contains classes vbl_bit_array_3d_base and vbl_bit_array_3d
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
std::ostream & operator<<(std::ostream &os, vbl_bit_array_3d const &bitarray)
unsigned long size() const
Number of bytes allocated by the data.