10 # include <vcl_msvc_warnings.h> 17 : data_(nullptr), num_rows_(0), num_cols_(0)
29 for (
unsigned int x=0; x<m; ++x)
30 for (
unsigned int y=0; y<n; ++y)
50 unsigned char *tempdata=
data_;
59 for (
unsigned int i=0; i< tempm; ++i)
62 unsigned long byteindex;
63 unsigned int bitindex;
64 index( i, 0, byteindex, bitindex);
67 auto oldbyteindex= (
unsigned long)(
double(i*tempn)/CHAR_BIT);
70 std::memcpy(
data_+byteindex, tempdata+oldbyteindex, (tempn+CHAR_BIT-1)/CHAR_BIT);
79 unsigned char v = value ? ~(
unsigned char)0 : 0;
102 byteindex= (
unsigned long)(
double(idx)/CHAR_BIT);
103 bitindex = idx%CHAR_BIT;
110 return 0 == std::memcmp(
data_, a.
data_, this->size());
115 unsigned long byteindex;
116 unsigned int bitindex;
117 index( i, j, byteindex, bitindex);
119 auto mask= (
unsigned char)(1<<bitindex);
121 return (
data_[byteindex] & mask) != 0;
126 unsigned long byteindex;
127 unsigned int bitindex;
128 index( i, j, byteindex, bitindex);
130 auto mask= (
unsigned char)(1<<bitindex);
132 return (
data_[byteindex] & mask) != 0;
137 unsigned long byteindex;
138 unsigned int bitindex;
140 index( i, j, byteindex, bitindex);
142 auto mask= (
unsigned char)(x?(1<<bitindex):0);
143 auto nmask= (
unsigned char)(~(1<<bitindex));
145 data_[byteindex]= mask|(nmask &
data_[byteindex]);
156 for (
unsigned int i=0; i< array.
rows(); i++)
158 for (
unsigned int j=0; j< array.
columns(); j++)
159 os << array(i,j) <<
' ';
void enlarge(unsigned int m, unsigned int n)
Resizes and pads with zeros; keeps existing data.
Contains class for a 2d bit array; interface as vbl_array_2d<T>
vbl_bit_array_2d & operator=(vbl_bit_array_2d const &)
Assignment operator.
bool operator()(unsigned int i, unsigned int j) const
bool operator==(vbl_bit_array_2d const &a) const
Comparison.
bool get(unsigned int i, unsigned int j) const
void construct(unsigned int m, unsigned int n)
void resize(unsigned int m, unsigned int n)
Delete contents and resize to m rows x n cols.
unsigned int cols() const
unsigned long size() const
Number of bytes allocated by the data.
std::ostream & operator<<(std::ostream &os, const vbl_bit_array_2d &array)
void put(unsigned int i, unsigned int j, bool const &x)
void set(unsigned int i, unsigned int j, bool v=true)
Set the value of a cell; default is to set the value on.
void index(unsigned int x, unsigned int y, unsigned long &byteindex, unsigned int &bitindex) const
void fill(bool value)
Fill with value.
unsigned int columns() const
unsigned int rows() const