25 #ifndef TESSERACT_CCSTRUCT_MATRIX_H__
26 #define TESSERACT_CCSTRUCT_MATRIX_H__
31 class BLOB_CHOICE_LIST;
33 #define NOT_CLASSIFIED reinterpret_cast<BLOB_CHOICE_LIST*>(NULL)
53 for (
int x = 0; x <
dim1_; x++)
54 for (
int y = 0; y <
dim2_; y++)
60 void Resize(
int size1,
int size2,
const T& empty) {
74 T* new_array =
new T[size1 * size2];
75 for (
int col = 0; col < size1; ++col) {
76 for (
int row = 0; row < size2; ++row) {
77 int old_index = col *
dim2() + row;
78 int new_index = col * size2 + row;
80 new_array[new_index] =
array_[old_index];
82 new_array[new_index] =
empty_;
96 for (
int i = 0; i < total_size; ++i)
104 if (fwrite(&
empty_,
sizeof(
empty_), 1, fp) != 1)
return false;
106 if (fwrite(
array_,
sizeof(*
array_), size, fp) != size)
return false;
115 if (fread(&
empty_,
sizeof(
empty_), 1, fp) != 1)
return false;
118 if (fread(
array_,
sizeof(*
array_), size, fp) != size)
return false;
120 for (
int i = 0; i < size; ++i)
130 if (!
empty_.Serialize(fp))
return false;
132 for (
int i = 0; i < size; ++i) {
143 if (!
empty_.DeSerialize(swap, fp))
return false;
145 for (
int i = 0; i < size; ++i) {
161 virtual int index(
int column,
int row)
const {
162 return (column *
dim2_ + row);
166 void put(
int column,
int row,
const T& thing) {
171 T
get(
int column,
int row)
const {
193 for (
int i = 0; i < size; ++i) {
194 T matrix_cell =
array_[i];
195 if (matrix_cell !=
empty_)
204 if (fwrite(&size,
sizeof(size), 1, fp) != 1)
return false;
206 if (fwrite(&size,
sizeof(size), 1, fp) != 1)
return false;
213 if (fread(&size1,
sizeof(size1), 1, fp) != 1)
return false;
214 if (fread(&size2,
sizeof(size2), 1, fp) != 1)
return false;
254 virtual int index(
int column,
int row)
const {
257 return column * this->dim2_ + row - column;
267 T* new_array =
new T[new_dim1 * new_dim2];
268 for (
int col = 0; col < new_dim1; ++col) {
269 for (
int j = 0; j < new_dim2; ++j) {
270 int new_index = col * new_dim2 + j;
272 new_array[new_index] = this->
get(col, col + j);
273 }
else if (col >= this->
dim1_ && j < array2->dim2_) {
274 new_array[new_index] = array2->
get(col - this->
dim1_,
275 col - this->
dim1_ + j);
278 new_array[new_index] = this->
empty_;
284 this->
dim1_ = new_dim1;
285 this->
dim2_ = new_dim2;
295 bool Classified(
int col,
int row,
int wildcard_id)
const;
352 #endif // TESSERACT_CCSTRUCT_MATRIX_H__
virtual int num_elements() const
bool DeSerializeSize(bool swap, FILE *fp)
bool SerializeClasses(FILE *fp) const
virtual int index(int column, int row) const
bool SerializeSize(FILE *fp) const
T get(int column, int row) const
void AttachOnCorner(BandTriMatrix< T > *array2)
void MapForSplit(int ind)
virtual ~GENERIC_2D_ARRAY()
MATRIX_COORD(int c, int r)
void Resize(int size1, int size2, const T &empty)
void put(int column, int row, const T &thing)
void delete_matrix_pointers()
T * operator[](int column)
GENERIC_2D_ARRAY(int dim1, int dim2, const T &empty, T *array)
static void Delete(void *arg)
GENERIC_2D_ARRAY(int dim1, int dim2, const T &empty)
MATRIX * DeepCopy() const
bool Valid(const MATRIX &m) const
bool DeSerializeClasses(bool swap, FILE *fp)
BandTriMatrix(int dim1, int dim2, const T &empty)
const T & operator()(int column, int row) const
void ReverseN(void *ptr, int num_bytes)
void print(const UNICHARSET &unicharset) const
MATRIX(int dimension, int bandwidth)
bool Serialize(FILE *fp) const
bool Classified(int col, int row, int wildcard_id) const
MATRIX * ConsumeAndMakeBigger(int ind)
const T * operator[](int column) const
T & operator()(int column, int row)
void ResizeWithCopy(int size1, int size2)
bool DeSerialize(bool swap, FILE *fp)
tesseract::KDPairInc< float, MATRIX_COORD > MatrixCoordPair
void IncreaseBandSize(int bandwidth)
virtual int index(int column, int row) const