Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::BlobMatchTable Class Reference

#include <matchtab.h>

Public Member Functions

 BlobMatchTable ()
 
 ~BlobMatchTable ()
 
void init_match_table ()
 
void end_match_table ()
 
void put_match (TBLOB *blob, BLOB_CHOICE_LIST *ratings)
 
BLOB_CHOICE_LIST * get_match (TBLOB *blob)
 
BLOB_CHOICE_LIST * get_match_by_box (const TBOX &box)
 
void add_to_match (TBLOB *blob, BLOB_CHOICE_LIST *ratings)
 

Detailed Description

Definition at line 42 of file matchtab.h.

Constructor & Destructor Documentation

tesseract::BlobMatchTable::BlobMatchTable ( )

Definition at line 38 of file matchtab.cpp.

39  : been_initialized_(false), match_table_(NULL) {
41 }
#define NULL
Definition: host.h:144
tesseract::BlobMatchTable::~BlobMatchTable ( )

Definition at line 43 of file matchtab.cpp.

43  {
45 }

Member Function Documentation

void tesseract::BlobMatchTable::add_to_match ( TBLOB blob,
BLOB_CHOICE_LIST *  ratings 
)

Definition at line 183 of file matchtab.cpp.

183  {
184  TBOX bbox = blob->bounding_box();
185  int start = Hash(bbox);
186  int x = start;
187  do {
188  if (IsEmpty(x)) {
189  fprintf(stderr, "Can not update uninitialized entry in match_table\n");
190  ASSERT_HOST(!IsEmpty(x));
191  }
192  if (match_table_[x].box == bbox) {
193  // Copy new ratings to match_table_[x].rating.
194  BLOB_CHOICE_IT it;
195  it.set_to_list(match_table_[x].rating);
196  BLOB_CHOICE_IT new_it;
197  new_it.set_to_list(ratings);
198  assert(it.length() <= new_it.length());
199  for (it.mark_cycle_pt(), new_it.mark_cycle_pt();
200  !it.cycled_list() && !new_it.cycled_list(); new_it.forward()) {
201  if (it.data()->unichar_id() == new_it.data()->unichar_id()) {
202  it.forward();
203  } else {
204  it.add_before_stay_put(new BLOB_CHOICE(*(new_it.data())));
205  }
206  }
207  return;
208  }
209  if (++x >= NUM_MATCH_ENTRIES)
210  x = 0;
211  } while (x != start);
212 }
Definition: rect.h:29
#define NUM_MATCH_ENTRIES
Definition: matchtab.cpp:34
TBOX bounding_box() const
Definition: blobs.cpp:384
#define ASSERT_HOST(x)
Definition: errcode.h:84
void tesseract::BlobMatchTable::end_match_table ( )

Definition at line 71 of file matchtab.cpp.

71  {
72  if (been_initialized_) {
74  delete[] match_table_;
75  match_table_ = NULL;
76  been_initialized_ = false;
77  }
78 }
#define NULL
Definition: host.h:144
BLOB_CHOICE_LIST * tesseract::BlobMatchTable::get_match ( TBLOB blob)

Definition at line 118 of file matchtab.cpp.

118  {
119  return get_match_by_box(blob->bounding_box());
120 }
TBOX bounding_box() const
Definition: blobs.cpp:384
BLOB_CHOICE_LIST * get_match_by_box(const TBOX &box)
Definition: matchtab.cpp:150
BLOB_CHOICE_LIST * tesseract::BlobMatchTable::get_match_by_box ( const TBOX box)

Definition at line 150 of file matchtab.cpp.

150  {
151  int start = Hash(box);
152  int x = start;
153  /* Search for match */
154  do {
155  /* Not found when blank */
156  if (IsEmpty(x))
157  break;
158  /* Is this the match ? */
159  if (match_table_[x].box == box) {
160  BLOB_CHOICE_LIST *blist = new BLOB_CHOICE_LIST();
161  blist->deep_copy(match_table_[x].rating, &BLOB_CHOICE::deep_copy);
162  return blist;
163  }
164  if (++x >= NUM_MATCH_ENTRIES)
165  x = 0;
166  } while (x != start);
167  return NULL;
168 }
#define NULL
Definition: host.h:144
#define NUM_MATCH_ENTRIES
Definition: matchtab.cpp:34
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:126
void tesseract::BlobMatchTable::init_match_table ( )

Definition at line 52 of file matchtab.cpp.

52  {
53  if (been_initialized_) {
54  /* Reclaim old choices */
55  for (int x = 0; x < NUM_MATCH_ENTRIES; x++) {
56  if (!IsEmpty(x)) {
57  match_table_[x].rating->clear();
58  delete match_table_[x].rating;
59  // Reinitialize the entry.
60  match_table_[x].box = TBOX();
61  match_table_[x].rating = NULL;
62  }
63  }
64  } else {
65  /* Allocate memory once */
66  match_table_ = new MATCH[NUM_MATCH_ENTRIES];
67  been_initialized_ = true;
68  }
69 }
#define NULL
Definition: host.h:144
BLOB_CHOICE_LIST * rating
Definition: matchtab.h:36
Definition: rect.h:29
#define NUM_MATCH_ENTRIES
Definition: matchtab.cpp:34
void tesseract::BlobMatchTable::put_match ( TBLOB blob,
BLOB_CHOICE_LIST *  ratings 
)

Definition at line 87 of file matchtab.cpp.

87  {
88  if (!blob) return;
89  /* Hash into table */
90  TBOX bbox(blob->bounding_box());
91  int start = Hash(bbox);
92 
93  /* Look for empty */
94  int x = start;
95  do {
96  if (IsEmpty(x)) {
97  /* Add this entry */
98  match_table_[x].box = bbox;
99  // Copy ratings to match_table_[x].rating
100  match_table_[x].rating = new BLOB_CHOICE_LIST();
101  match_table_[x].rating->deep_copy(ratings, &BLOB_CHOICE::deep_copy);
102  return;
103  }
104  if (++x >= NUM_MATCH_ENTRIES)
105  x = 0;
106  } while (x != start);
107 
108  cprintf ("error: Match table is full\n");
109 }
BLOB_CHOICE_LIST * rating
Definition: matchtab.h:36
Definition: rect.h:29
#define NUM_MATCH_ENTRIES
Definition: matchtab.cpp:34
TBOX bounding_box() const
Definition: blobs.cpp:384
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:126
void cprintf(const char *format,...)
Definition: callcpp.cpp:41

The documentation for this class was generated from the following files: