All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BLOBNBOX Class Reference

#include <blobbox.h>

Inheritance diagram for BLOBNBOX:
ELIST_LINK

Public Member Functions

 BLOBNBOX ()
 
 BLOBNBOX (C_BLOB *srcblob)
 
 ~BLOBNBOX ()
 
void rotate (FCOORD rotation)
 
void reflect_box_in_y_axis ()
 
void rotate_box (FCOORD rotation)
 
void translate_box (ICOORD v)
 
void merge (BLOBNBOX *nextblob)
 
void really_merge (BLOBNBOX *other)
 
void chop (BLOBNBOX_IT *start_it, BLOBNBOX_IT *blob_it, FCOORD rotation, float xheight)
 
void NeighbourGaps (int gaps[BND_COUNT]) const
 
void MinMaxGapsClipped (int *h_min, int *h_max, int *v_min, int *v_max) const
 
void CleanNeighbours ()
 
int GoodTextBlob () const
 
int NoisyNeighbours () const
 
bool DeletableNoise () const
 
bool DefiniteIndividualFlow ()
 
bool ConfirmNoTabViolation (const BLOBNBOX &other) const
 
bool MatchingStrokeWidth (const BLOBNBOX &other, double fractional_tolerance, double constant_tolerance) const
 
TBOX BoundsWithinLimits (int left, int right)
 
void EstimateBaselinePosition ()
 
const TBOXbounding_box () const
 
void set_bounding_box (const TBOX &new_box)
 
void compute_bounding_box ()
 
const TBOXreduced_box () const
 
void set_reduced_box (TBOX new_box)
 
inT32 enclosed_area () const
 
bool joined_to_prev () const
 
bool red_box_set () const
 
int repeated_set () const
 
void set_repeated_set (int set_id)
 
C_BLOBcblob () const
 
TabType left_tab_type () const
 
void set_left_tab_type (TabType new_type)
 
TabType right_tab_type () const
 
void set_right_tab_type (TabType new_type)
 
BlobRegionType region_type () const
 
void set_region_type (BlobRegionType new_type)
 
BlobSpecialTextType special_text_type () const
 
void set_special_text_type (BlobSpecialTextType new_type)
 
BlobTextFlowType flow () const
 
void set_flow (BlobTextFlowType value)
 
bool vert_possible () const
 
void set_vert_possible (bool value)
 
bool horz_possible () const
 
void set_horz_possible (bool value)
 
int left_rule () const
 
void set_left_rule (int new_left)
 
int right_rule () const
 
void set_right_rule (int new_right)
 
int left_crossing_rule () const
 
void set_left_crossing_rule (int new_left)
 
int right_crossing_rule () const
 
void set_right_crossing_rule (int new_right)
 
float horz_stroke_width () const
 
void set_horz_stroke_width (float width)
 
float vert_stroke_width () const
 
void set_vert_stroke_width (float width)
 
float area_stroke_width () const
 
tesseract::ColPartitionowner () const
 
void set_owner (tesseract::ColPartition *new_owner)
 
bool leader_on_left () const
 
void set_leader_on_left (bool flag)
 
bool leader_on_right () const
 
void set_leader_on_right (bool flag)
 
BLOBNBOXneighbour (BlobNeighbourDir n) const
 
bool good_stroke_neighbour (BlobNeighbourDir n) const
 
void set_neighbour (BlobNeighbourDir n, BLOBNBOX *neighbour, bool good)
 
bool IsDiacritic () const
 
int base_char_top () const
 
int base_char_bottom () const
 
int baseline_position () const
 
int line_crossings () const
 
void set_line_crossings (int value)
 
void set_diacritic_box (const TBOX &diacritic_box)
 
BLOBNBOXbase_char_blob () const
 
void set_base_char_blob (BLOBNBOX *blob)
 
void set_owns_cblob (bool value)
 
bool UniquelyVertical () const
 
bool UniquelyHorizontal () const
 
ScrollView::Color BoxColor () const
 
void plot (ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
 
void ConstructionInit ()
 
void ReInit ()
 
void ClearNeighbours ()
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static BLOBNBOXRealBlob (C_OUTLINE *outline)
 
static bool IsTextType (BlobRegionType type)
 
static bool IsImageType (BlobRegionType type)
 
static bool IsLineType (BlobRegionType type)
 
static bool UnMergeableType (BlobRegionType type)
 
static void CleanNeighbours (BLOBNBOX_LIST *blobs)
 
static void DeleteNoiseBlobs (BLOBNBOX_LIST *blobs)
 
static void ComputeEdgeOffsets (Pix *thresholds, Pix *grey, BLOBNBOX_LIST *blobs)
 
static void PlotBlobs (BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour, ScrollView *win)
 
static void PlotNoiseBlobs (BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour, ScrollView *win)
 
static ScrollView::Color TextlineColor (BlobRegionType region_type, BlobTextFlowType flow_type)
 

Detailed Description

Definition at line 128 of file blobbox.h.

Constructor & Destructor Documentation

BLOBNBOX::BLOBNBOX ( )
inline

Definition at line 131 of file blobbox.h.

131  {
133  }
void ConstructionInit()
Definition: blobbox.h:455
BLOBNBOX::BLOBNBOX ( C_BLOB srcblob)
inlineexplicit

Definition at line 134 of file blobbox.h.

134  {
135  box = srcblob->bounding_box();
137  cblob_ptr = srcblob;
138  area = static_cast<int>(srcblob->area());
139  }
void ConstructionInit()
Definition: blobbox.h:455
TBOX bounding_box() const
Definition: stepblob.cpp:250
inT32 area()
Definition: stepblob.cpp:270
BLOBNBOX::~BLOBNBOX ( )
inline

Definition at line 140 of file blobbox.h.

140  {
141  if (owns_cblob_) delete cblob_ptr;
142  }

Member Function Documentation

float BLOBNBOX::area_stroke_width ( ) const
inline

Definition at line 334 of file blobbox.h.

334  {
335  return area_stroke_width_;
336  }
BLOBNBOX* BLOBNBOX::base_char_blob ( ) const
inline

Definition at line 387 of file blobbox.h.

387  {
388  return base_char_blob_;
389  }
int BLOBNBOX::base_char_bottom ( ) const
inline

Definition at line 371 of file blobbox.h.

371  {
372  return base_char_bottom_;
373  }
int BLOBNBOX::base_char_top ( ) const
inline

Definition at line 368 of file blobbox.h.

368  {
369  return base_char_top_;
370  }
int BLOBNBOX::baseline_position ( ) const
inline

Definition at line 374 of file blobbox.h.

374  {
375  return baseline_y_;
376  }
const TBOX& BLOBNBOX::bounding_box ( ) const
inline

Definition at line 215 of file blobbox.h.

215  {
216  return box;
217  }
TBOX BLOBNBOX::BoundsWithinLimits ( int  left,
int  right 
)

Definition at line 326 of file blobbox.cpp.

326  {
327  FCOORD no_rotation(1.0f, 0.0f);
328  float top = box.top();
329  float bottom = box.bottom();
330  if (cblob_ptr != NULL) {
331  find_cblob_limits(cblob_ptr, static_cast<float>(left),
332  static_cast<float>(right), no_rotation,
333  bottom, top);
334  }
335 
336  if (top < bottom) {
337  top = box.top();
338  bottom = box.bottom();
339  }
340  FCOORD bot_left(left, bottom);
341  FCOORD top_right(right, top);
342  TBOX shrunken_box(bot_left);
343  TBOX shrunken_box2(top_right);
344  shrunken_box += shrunken_box2;
345  return shrunken_box;
346 }
inT16 bottom() const
Definition: rect.h:61
void find_cblob_limits(C_BLOB *blob, float leftx, float rightx, FCOORD rotation, float &ymin, float &ymax)
Definition: blobbox.cpp:492
Definition: rect.h:30
#define NULL
Definition: host.h:144
inT16 top() const
Definition: rect.h:54
Definition: points.h:189
ScrollView::Color BLOBNBOX::BoxColor ( ) const

Definition at line 474 of file blobbox.cpp.

474  {
475  return TextlineColor(region_type_, flow_);
476 }
static ScrollView::Color TextlineColor(BlobRegionType region_type, BlobTextFlowType flow_type)
Definition: blobbox.cpp:437
C_BLOB* BLOBNBOX::cblob ( ) const
inline

Definition at line 253 of file blobbox.h.

253  {
254  return cblob_ptr;
255  }
void BLOBNBOX::chop ( BLOBNBOX_IT *  start_it,
BLOBNBOX_IT *  blob_it,
FCOORD  rotation,
float  xheight 
)

Definition at line 113 of file blobbox.cpp.

118  {
119  inT16 blobcount; //no of blobs
120  BLOBNBOX *newblob; //fake blob
121  BLOBNBOX *blob; //current blob
122  inT16 blobindex; //number of chop
123  inT16 leftx; //left edge of blob
124  float blobwidth; //width of each
125  float rightx; //right edge to scan
126  float ymin, ymax; //limits of new blob
127  float test_ymin, test_ymax; //limits of part blob
128  ICOORD bl, tr; //corners of box
129  BLOBNBOX_IT blob_it; //blob iterator
130 
131  //get no of chops
132  blobcount = (inT16) floor (box.width () / xheight);
133  if (blobcount > 1 && cblob_ptr != NULL) {
134  //width of each
135  blobwidth = (float) (box.width () + 1) / blobcount;
136  for (blobindex = blobcount - 1, rightx = box.right ();
137  blobindex >= 0; blobindex--, rightx -= blobwidth) {
138  ymin = (float) MAX_INT32;
139  ymax = (float) -MAX_INT32;
140  blob_it = *start_it;
141  do {
142  blob = blob_it.data ();
143  find_cblob_vlimits(blob->cblob_ptr, rightx - blobwidth,
144  rightx,
145  /*rotation, */ test_ymin, test_ymax);
146  blob_it.forward ();
147  UpdateRange(test_ymin, test_ymax, &ymin, &ymax);
148  }
149  while (blob != end_it->data ());
150  if (ymin < ymax) {
151  leftx = (inT16) floor (rightx - blobwidth);
152  if (leftx < box.left ())
153  leftx = box.left (); //clip to real box
154  bl = ICOORD (leftx, (inT16) floor (ymin));
155  tr = ICOORD ((inT16) ceil (rightx), (inT16) ceil (ymax));
156  if (blobindex == 0)
157  box = TBOX (bl, tr); //change box
158  else {
159  newblob = new BLOBNBOX;
160  //box is all it has
161  newblob->box = TBOX (bl, tr);
162  //stay on current
163  newblob->base_char_top_ = tr.y();
164  newblob->base_char_bottom_ = bl.y();
165  end_it->add_after_stay_put (newblob);
166  }
167  }
168  }
169  }
170 }
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:125
inT16 right() const
Definition: rect.h:75
BLOBNBOX()
Definition: blobbox.h:131
inT16 y() const
access_function
Definition: points.h:56
inT16 left() const
Definition: rect.h:68
#define MAX_INT32
Definition: host.h:120
integer coordinate
Definition: points.h:30
inT16 width() const
Definition: rect.h:111
Definition: rect.h:30
#define NULL
Definition: host.h:144
void find_cblob_vlimits(C_BLOB *blob, float leftx, float rightx, float &ymin, float &ymax)
Definition: blobbox.cpp:532
short inT16
Definition: host.h:100
void BLOBNBOX::CleanNeighbours ( )

Definition at line 207 of file blobbox.cpp.

207  {
208  for (int dir = 0; dir < BND_COUNT; ++dir) {
209  BLOBNBOX* neighbour = neighbours_[dir];
210  if (neighbour != NULL && neighbour->DeletableNoise()) {
211  neighbours_[dir] = NULL;
212  good_stroke_neighbours_[dir] = false;
213  }
214  }
215 }
bool DeletableNoise() const
Definition: blobbox.h:188
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:355
#define NULL
Definition: host.h:144
void BLOBNBOX::CleanNeighbours ( BLOBNBOX_LIST *  blobs)
static

Definition at line 357 of file blobbox.cpp.

357  {
358  BLOBNBOX_IT blob_it(blobs);
359  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
360  blob_it.data()->CleanNeighbours();
361  }
362 }
void BLOBNBOX::ClearNeighbours ( )
inline

Definition at line 494 of file blobbox.h.

494  {
495  for (int n = 0; n < BND_COUNT; ++n) {
496  neighbours_[n] = NULL;
497  good_stroke_neighbours_[n] = false;
498  }
499  }
#define NULL
Definition: host.h:144
void BLOBNBOX::compute_bounding_box ( )
inline

Definition at line 225 of file blobbox.h.

225  {
226  box = cblob_ptr->bounding_box();
227  base_char_top_ = box.top();
228  base_char_bottom_ = box.bottom();
229  baseline_y_ = box.bottom();
230  }
inT16 bottom() const
Definition: rect.h:61
TBOX bounding_box() const
Definition: stepblob.cpp:250
inT16 top() const
Definition: rect.h:54
void BLOBNBOX::ComputeEdgeOffsets ( Pix *  thresholds,
Pix *  grey,
BLOBNBOX_LIST *  blobs 
)
static

Definition at line 378 of file blobbox.cpp.

379  {
380  int grey_height = 0;
381  int thr_height = 0;
382  int scale_factor = 1;
383  if (thresholds != NULL && grey != NULL) {
384  grey_height = pixGetHeight(grey);
385  thr_height = pixGetHeight(thresholds);
386  scale_factor =
387  IntCastRounded(static_cast<double>(grey_height) / thr_height);
388  }
389  BLOBNBOX_IT blob_it(blobs);
390  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
391  BLOBNBOX* blob = blob_it.data();
392  if (blob->cblob() != NULL) {
393  // Get the threshold that applies to this blob.
394  l_uint32 threshold = 128;
395  if (thresholds != NULL && grey != NULL) {
396  const TBOX& box = blob->cblob()->bounding_box();
397  // Transform the coordinates if required.
398  TPOINT pt((box.left() + box.right()) / 2,
399  (box.top() + box.bottom()) / 2);
400  pixGetPixel(thresholds, pt.x / scale_factor,
401  thr_height - 1 - pt.y / scale_factor, &threshold);
402  }
403  blob->cblob()->ComputeEdgeOffsets(threshold, grey);
404  }
405  }
406 }
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
C_BLOB * cblob() const
Definition: blobbox.h:253
Definition: blobs.h:50
void ComputeEdgeOffsets(int threshold, Pix *pix)
Definition: stepblob.cpp:409
inT16 bottom() const
Definition: rect.h:61
int IntCastRounded(double x)
Definition: helpers.h:172
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
#define NULL
Definition: host.h:144
inT16 top() const
Definition: rect.h:54
bool BLOBNBOX::ConfirmNoTabViolation ( const BLOBNBOX other) const

Definition at line 285 of file blobbox.cpp.

285  {
286  if (box.left() < other.box.left() && box.left() < other.left_rule_)
287  return false;
288  if (other.box.left() < box.left() && other.box.left() < left_rule_)
289  return false;
290  if (box.right() > other.box.right() && box.right() > other.right_rule_)
291  return false;
292  if (other.box.right() > box.right() && other.box.right() > right_rule_)
293  return false;
294  return true;
295 }
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
void BLOBNBOX::ConstructionInit ( )
inline

Definition at line 455 of file blobbox.h.

455  {
456  cblob_ptr = NULL;
457  owns_cblob_ = false;
458  area = 0;
459  area_stroke_width_ = 0.0f;
460  horz_stroke_width_ = 0.0f;
461  vert_stroke_width_ = 0.0f;
462  ReInit();
463  }
void ReInit()
Definition: blobbox.h:466
#define NULL
Definition: host.h:144
bool BLOBNBOX::DefiniteIndividualFlow ( )

Definition at line 245 of file blobbox.cpp.

245  {
246  if (cblob() == NULL) return false;
247  int box_perimeter = 2 * (box.height() + box.width());
248  if (box.width() > box.height() * kDefiniteAspectRatio) {
249  // Attempt to distinguish a wide joined word from a dash.
250  // If it is a dash, then its perimeter is approximately
251  // 2 * (box width + stroke width), but more if the outline is noisy,
252  // so perimeter - 2*(box width + stroke width) should be close to zero.
253  // A complex shape such as a joined word should have a much larger value.
254  int perimeter = cblob()->perimeter();
255  if (vert_stroke_width() > 0 || perimeter <= 0)
256  perimeter -= 2 * vert_stroke_width();
257  else
258  perimeter -= 4 * cblob()->area() / perimeter;
259  perimeter -= 2 * box.width();
260  // Use a multiple of the box perimeter as a threshold.
261  if (perimeter > kComplexShapePerimeterRatio * box_perimeter) {
262  set_vert_possible(false);
263  set_horz_possible(true);
264  return true;
265  }
266  }
267  if (box.height() > box.width() * kDefiniteAspectRatio) {
268  // As above, but for a putative vertical word vs a I/1/l.
269  int perimeter = cblob()->perimeter();
270  if (horz_stroke_width() > 0 || perimeter <= 0)
271  perimeter -= 2 * horz_stroke_width();
272  else
273  perimeter -= 4 * cblob()->area() / perimeter;
274  perimeter -= 2 * box.height();
275  if (perimeter > kComplexShapePerimeterRatio * box_perimeter) {
276  set_vert_possible(true);
277  set_horz_possible(false);
278  return true;
279  }
280  }
281  return false;
282 }
const double kDefiniteAspectRatio
Definition: blobbox.cpp:39
C_BLOB * cblob() const
Definition: blobbox.h:253
const double kComplexShapePerimeterRatio
Definition: blobbox.cpp:41
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111
void set_horz_possible(bool value)
Definition: blobbox.h:295
float horz_stroke_width() const
Definition: blobbox.h:322
void set_vert_possible(bool value)
Definition: blobbox.h:289
float vert_stroke_width() const
Definition: blobbox.h:328
#define NULL
Definition: host.h:144
inT32 area()
Definition: stepblob.cpp:270
inT32 perimeter()
Definition: stepblob.cpp:289
bool BLOBNBOX::DeletableNoise ( ) const
inline

Definition at line 188 of file blobbox.h.

188  {
189  return owner() == NULL && region_type() == BRT_NOISE;
190  }
BlobRegionType region_type() const
Definition: blobbox.h:268
tesseract::ColPartition * owner() const
Definition: blobbox.h:337
#define NULL
Definition: host.h:144
void BLOBNBOX::DeleteNoiseBlobs ( BLOBNBOX_LIST *  blobs)
static

Definition at line 365 of file blobbox.cpp.

365  {
366  BLOBNBOX_IT blob_it(blobs);
367  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
368  BLOBNBOX* blob = blob_it.data();
369  if (blob->DeletableNoise()) {
370  delete blob->cblob();
371  delete blob_it.extract();
372  }
373  }
374 }
bool DeletableNoise() const
Definition: blobbox.h:188
C_BLOB * cblob() const
Definition: blobbox.h:253
inT32 BLOBNBOX::enclosed_area ( ) const
inline

Definition at line 238 of file blobbox.h.

238  {
239  return area;
240  }
void BLOBNBOX::EstimateBaselinePosition ( )

Definition at line 350 of file blobbox.cpp.

350  {
351  baseline_y_ = box.bottom(); // The default.
352  if (cblob_ptr == NULL) return;
353  baseline_y_ = cblob_ptr->EstimateBaselinePosition();
354 }
inT16 EstimateBaselinePosition()
Definition: stepblob.cpp:427
inT16 bottom() const
Definition: rect.h:61
#define NULL
Definition: host.h:144
BlobTextFlowType BLOBNBOX::flow ( ) const
inline

Definition at line 280 of file blobbox.h.

280  {
281  return flow_;
282  }
bool BLOBNBOX::good_stroke_neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 358 of file blobbox.h.

358  {
359  return good_stroke_neighbours_[n];
360  }
int BLOBNBOX::GoodTextBlob ( ) const

Definition at line 219 of file blobbox.cpp.

219  {
220  int score = 0;
221  for (int dir = 0; dir < BND_COUNT; ++dir) {
222  BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir);
223  if (good_stroke_neighbour(bnd))
224  ++score;
225  }
226  return score;
227 }
BlobNeighbourDir
Definition: blobbox.h:72
bool good_stroke_neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:358
bool BLOBNBOX::horz_possible ( ) const
inline

Definition at line 292 of file blobbox.h.

292  {
293  return horz_possible_;
294  }
float BLOBNBOX::horz_stroke_width ( ) const
inline

Definition at line 322 of file blobbox.h.

322  {
323  return horz_stroke_width_;
324  }
bool BLOBNBOX::IsDiacritic ( ) const
inline

Definition at line 365 of file blobbox.h.

365  {
366  return base_char_top_ != box.top() || base_char_bottom_ != box.bottom();
367  }
inT16 bottom() const
Definition: rect.h:61
inT16 top() const
Definition: rect.h:54
static bool BLOBNBOX::IsImageType ( BlobRegionType  type)
inlinestatic

Definition at line 407 of file blobbox.h.

407  {
408  return type == BRT_RECTIMAGE || type == BRT_POLYIMAGE;
409  }
static bool BLOBNBOX::IsLineType ( BlobRegionType  type)
inlinestatic

Definition at line 411 of file blobbox.h.

411  {
412  return type == BRT_HLINE || type == BRT_VLINE;
413  }
static bool BLOBNBOX::IsTextType ( BlobRegionType  type)
inlinestatic

Definition at line 403 of file blobbox.h.

403  {
404  return type == BRT_TEXT || type == BRT_VERT_TEXT;
405  }
bool BLOBNBOX::joined_to_prev ( ) const
inline

Definition at line 241 of file blobbox.h.

241  {
242  return joined != 0;
243  }
bool BLOBNBOX::leader_on_left ( ) const
inline

Definition at line 343 of file blobbox.h.

343  {
344  return leader_on_left_;
345  }
bool BLOBNBOX::leader_on_right ( ) const
inline

Definition at line 349 of file blobbox.h.

349  {
350  return leader_on_right_;
351  }
int BLOBNBOX::left_crossing_rule ( ) const
inline

Definition at line 310 of file blobbox.h.

310  {
311  return left_crossing_rule_;
312  }
int BLOBNBOX::left_rule ( ) const
inline

Definition at line 298 of file blobbox.h.

298  {
299  return left_rule_;
300  }
TabType BLOBNBOX::left_tab_type ( ) const
inline

Definition at line 256 of file blobbox.h.

256  {
257  return left_tab_type_;
258  }
int BLOBNBOX::line_crossings ( ) const
inline

Definition at line 377 of file blobbox.h.

377  {
378  return line_crossings_;
379  }
bool BLOBNBOX::MatchingStrokeWidth ( const BLOBNBOX other,
double  fractional_tolerance,
double  constant_tolerance 
) const

Definition at line 298 of file blobbox.cpp.

300  {
301  // The perimeter-based width is used as a backup in case there is
302  // no information in the blob.
303  double p_width = area_stroke_width();
304  double n_p_width = other.area_stroke_width();
305  float h_tolerance = horz_stroke_width_ * fractional_tolerance
306  + constant_tolerance;
307  float v_tolerance = vert_stroke_width_ * fractional_tolerance
308  + constant_tolerance;
309  double p_tolerance = p_width * fractional_tolerance
310  + constant_tolerance;
311  bool h_zero = horz_stroke_width_ == 0.0f || other.horz_stroke_width_ == 0.0f;
312  bool v_zero = vert_stroke_width_ == 0.0f || other.vert_stroke_width_ == 0.0f;
313  bool h_ok = !h_zero && NearlyEqual(horz_stroke_width_,
314  other.horz_stroke_width_, h_tolerance);
315  bool v_ok = !v_zero && NearlyEqual(vert_stroke_width_,
316  other.vert_stroke_width_, v_tolerance);
317  bool p_ok = h_zero && v_zero && NearlyEqual(p_width, n_p_width, p_tolerance);
318  // For a match, at least one of the horizontal and vertical widths
319  // must match, and the other one must either match or be zero.
320  // Only if both are zero will we look at the perimeter metric.
321  return p_ok || ((v_ok || h_ok) && (h_ok || h_zero) && (v_ok || v_zero));
322 }
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:148
float area_stroke_width() const
Definition: blobbox.h:334
void BLOBNBOX::merge ( BLOBNBOX nextblob)

Definition at line 85 of file blobbox.cpp.

87  {
88  box += nextblob->box; //merge boxes
89  set_diacritic_box(box);
90  nextblob->joined = TRUE;
91 }
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:383
#define TRUE
Definition: capi.h:28
void BLOBNBOX::MinMaxGapsClipped ( int *  h_min,
int *  h_max,
int *  v_min,
int *  v_max 
) const

Definition at line 193 of file blobbox.cpp.

194  {
195  int max_dimension = MAX(box.width(), box.height());
196  int gaps[BND_COUNT];
197  NeighbourGaps(gaps);
198  *h_min = MIN(gaps[BND_LEFT], gaps[BND_RIGHT]);
199  *h_max = MAX(gaps[BND_LEFT], gaps[BND_RIGHT]);
200  if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
201  *v_min = MIN(gaps[BND_ABOVE], gaps[BND_BELOW]);
202  *v_max = MAX(gaps[BND_ABOVE], gaps[BND_BELOW]);
203  if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
204 }
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28
void NeighbourGaps(int gaps[BND_COUNT]) const
Definition: blobbox.cpp:174
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111
BLOBNBOX* BLOBNBOX::neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 355 of file blobbox.h.

355  {
356  return neighbours_[n];
357  }
void BLOBNBOX::NeighbourGaps ( int  gaps[BND_COUNT]) const

Definition at line 174 of file blobbox.cpp.

174  {
175  for (int dir = 0; dir < BND_COUNT; ++dir) {
176  gaps[dir] = MAX_INT16;
177  BLOBNBOX* neighbour = neighbours_[dir];
178  if (neighbour != NULL) {
179  TBOX n_box = neighbour->bounding_box();
180  if (dir == BND_LEFT || dir == BND_RIGHT) {
181  gaps[dir] = box.x_gap(n_box);
182  } else {
183  gaps[dir] = box.y_gap(n_box);
184  }
185  }
186  }
187 }
int y_gap(const TBOX &box) const
Definition: rect.h:225
int x_gap(const TBOX &box) const
Definition: rect.h:217
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:355
Definition: rect.h:30
#define MAX_INT16
Definition: host.h:119
#define NULL
Definition: host.h:144
const TBOX & bounding_box() const
Definition: blobbox.h:215
int BLOBNBOX::NoisyNeighbours ( ) const

Definition at line 230 of file blobbox.cpp.

230  {
231  int count = 0;
232  for (int dir = 0; dir < BND_COUNT; ++dir) {
233  BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir);
234  BLOBNBOX* blob = neighbour(bnd);
235  if (blob != NULL && blob->region_type() == BRT_NOISE)
236  ++count;
237  }
238  return count;
239 }
BlobNeighbourDir
Definition: blobbox.h:72
BlobRegionType region_type() const
Definition: blobbox.h:268
int count(LIST var_list)
Definition: oldlist.cpp:108
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:355
#define NULL
Definition: host.h:144
tesseract::ColPartition* BLOBNBOX::owner ( ) const
inline

Definition at line 337 of file blobbox.h.

337  {
338  return owner_;
339  }
void BLOBNBOX::plot ( ScrollView window,
ScrollView::Color  blob_colour,
ScrollView::Color  child_colour 
)

Definition at line 478 of file blobbox.cpp.

480  { // for holes
481  if (cblob_ptr != NULL)
482  cblob_ptr->plot(window, blob_colour, child_colour);
483 }
#define NULL
Definition: host.h:144
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: stepblob.cpp:532
void BLOBNBOX::PlotBlobs ( BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour,
ScrollView win 
)
static

Definition at line 412 of file blobbox.cpp.

415  {
416  BLOBNBOX_IT it(list);
417  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
418  it.data()->plot(win, body_colour, child_colour);
419  }
420 }
void BLOBNBOX::PlotNoiseBlobs ( BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour,
ScrollView win 
)
static

Definition at line 425 of file blobbox.cpp.

428  {
429  BLOBNBOX_IT it(list);
430  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
431  BLOBNBOX* blob = it.data();
432  if (blob->DeletableNoise())
433  blob->plot(win, body_colour, child_colour);
434  }
435 }
bool DeletableNoise() const
Definition: blobbox.h:188
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:478
static BLOBNBOX* BLOBNBOX::RealBlob ( C_OUTLINE outline)
inlinestatic

Definition at line 143 of file blobbox.h.

143  {
144  C_BLOB* blob = new C_BLOB(outline);
145  return new BLOBNBOX(blob);
146  }
BLOBNBOX()
Definition: blobbox.h:131
void BLOBNBOX::really_merge ( BLOBNBOX other)

Definition at line 96 of file blobbox.cpp.

96  {
97  if (cblob_ptr != NULL && other->cblob_ptr != NULL) {
98  C_OUTLINE_IT ol_it(cblob_ptr->out_list());
99  ol_it.add_list_after(other->cblob_ptr->out_list());
100  }
102 }
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:64
void compute_bounding_box()
Definition: blobbox.h:225
#define NULL
Definition: host.h:144
bool BLOBNBOX::red_box_set ( ) const
inline

Definition at line 244 of file blobbox.h.

244  {
245  return reduced != 0;
246  }
const TBOX& BLOBNBOX::reduced_box ( ) const
inline

Definition at line 231 of file blobbox.h.

231  {
232  return red_box;
233  }
void BLOBNBOX::reflect_box_in_y_axis ( )

Definition at line 55 of file blobbox.cpp.

55  {
56  int left = -box.right();
57  box.set_right(-box.left());
58  box.set_left(left);
59 }
void set_right(int x)
Definition: rect.h:78
inT16 right() const
Definition: rect.h:75
void set_left(int x)
Definition: rect.h:71
inT16 left() const
Definition: rect.h:68
BlobRegionType BLOBNBOX::region_type ( ) const
inline

Definition at line 268 of file blobbox.h.

268  {
269  return region_type_;
270  }
void BLOBNBOX::ReInit ( )
inline

Definition at line 466 of file blobbox.h.

466  {
467  joined = false;
468  reduced = false;
469  repeated_set_ = 0;
470  left_tab_type_ = TT_NONE;
471  right_tab_type_ = TT_NONE;
472  region_type_ = BRT_UNKNOWN;
473  flow_ = BTFT_NONE;
474  spt_type_ = BSTT_SKIP;
475  left_rule_ = 0;
476  right_rule_ = 0;
477  left_crossing_rule_ = 0;
478  right_crossing_rule_ = 0;
479  if (area_stroke_width_ == 0.0f && area > 0 && cblob() != NULL)
480  area_stroke_width_ = 2.0f * area / cblob()->perimeter();
481  owner_ = NULL;
482  base_char_top_ = box.top();
483  base_char_bottom_ = box.bottom();
484  baseline_y_ = box.bottom();
485  line_crossings_ = 0;
486  base_char_blob_ = NULL;
487  horz_possible_ = false;
488  vert_possible_ = false;
489  leader_on_left_ = false;
490  leader_on_right_ = false;
491  ClearNeighbours();
492  }
void ClearNeighbours()
Definition: blobbox.h:494
C_BLOB * cblob() const
Definition: blobbox.h:253
inT16 bottom() const
Definition: rect.h:61
#define NULL
Definition: host.h:144
inT16 top() const
Definition: rect.h:54
inT32 perimeter()
Definition: stepblob.cpp:289
int BLOBNBOX::repeated_set ( ) const
inline

Definition at line 247 of file blobbox.h.

247  {
248  return repeated_set_;
249  }
int BLOBNBOX::right_crossing_rule ( ) const
inline

Definition at line 316 of file blobbox.h.

316  {
317  return right_crossing_rule_;
318  }
int BLOBNBOX::right_rule ( ) const
inline

Definition at line 304 of file blobbox.h.

304  {
305  return right_rule_;
306  }
TabType BLOBNBOX::right_tab_type ( ) const
inline

Definition at line 262 of file blobbox.h.

262  {
263  return right_tab_type_;
264  }
void BLOBNBOX::rotate ( FCOORD  rotation)

Definition at line 48 of file blobbox.cpp.

48  {
49  cblob_ptr->rotate(rotation);
50  rotate_box(rotation);
52 }
void rotate(const FCOORD &rotation)
Definition: stepblob.cpp:387
void compute_bounding_box()
Definition: blobbox.h:225
void rotate_box(FCOORD rotation)
Definition: blobbox.cpp:64
void BLOBNBOX::rotate_box ( FCOORD  rotation)

Definition at line 64 of file blobbox.cpp.

64  {
65  if (IsDiacritic()) {
66  ASSERT_HOST(rotation.x() >= kCosSmallAngle)
67  ICOORD top_pt((box.left() + box.right()) / 2, base_char_top_);
68  ICOORD bottom_pt(top_pt.x(), base_char_bottom_);
69  top_pt.rotate(rotation);
70  base_char_top_ = top_pt.y();
71  bottom_pt.rotate(rotation);
72  base_char_bottom_ = bottom_pt.y();
73  box.rotate(rotation);
74  } else {
75  box.rotate(rotation);
76  set_diacritic_box(box);
77  }
78 }
float x() const
Definition: points.h:209
inT16 right() const
Definition: rect.h:75
#define ASSERT_HOST(x)
Definition: errcode.h:84
void rotate(const FCOORD &vec)
Definition: ipoints.h:241
inT16 left() const
Definition: rect.h:68
integer coordinate
Definition: points.h:30
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:383
bool IsDiacritic() const
Definition: blobbox.h:365
void rotate(const FCOORD &vec)
Definition: rect.h:189
void BLOBNBOX::set_base_char_blob ( BLOBNBOX blob)
inline

Definition at line 390 of file blobbox.h.

390  {
391  base_char_blob_ = blob;
392  }
void BLOBNBOX::set_bounding_box ( const TBOX new_box)
inline

Definition at line 220 of file blobbox.h.

220  {
221  box = new_box;
222  base_char_top_ = box.top();
223  base_char_bottom_ = box.bottom();
224  }
inT16 bottom() const
Definition: rect.h:61
inT16 top() const
Definition: rect.h:54
void BLOBNBOX::set_diacritic_box ( const TBOX diacritic_box)
inline

Definition at line 383 of file blobbox.h.

383  {
384  base_char_top_ = diacritic_box.top();
385  base_char_bottom_ = diacritic_box.bottom();
386  }
inT16 bottom() const
Definition: rect.h:61
inT16 top() const
Definition: rect.h:54
void BLOBNBOX::set_flow ( BlobTextFlowType  value)
inline

Definition at line 283 of file blobbox.h.

283  {
284  flow_ = value;
285  }
void BLOBNBOX::set_horz_possible ( bool  value)
inline

Definition at line 295 of file blobbox.h.

295  {
296  horz_possible_ = value;
297  }
void BLOBNBOX::set_horz_stroke_width ( float  width)
inline

Definition at line 325 of file blobbox.h.

325  {
326  horz_stroke_width_ = width;
327  }
void BLOBNBOX::set_leader_on_left ( bool  flag)
inline

Definition at line 346 of file blobbox.h.

346  {
347  leader_on_left_ = flag;
348  }
void BLOBNBOX::set_leader_on_right ( bool  flag)
inline

Definition at line 352 of file blobbox.h.

352  {
353  leader_on_right_ = flag;
354  }
void BLOBNBOX::set_left_crossing_rule ( int  new_left)
inline

Definition at line 313 of file blobbox.h.

313  {
314  left_crossing_rule_ = new_left;
315  }
void BLOBNBOX::set_left_rule ( int  new_left)
inline

Definition at line 301 of file blobbox.h.

301  {
302  left_rule_ = new_left;
303  }
void BLOBNBOX::set_left_tab_type ( TabType  new_type)
inline

Definition at line 259 of file blobbox.h.

259  {
260  left_tab_type_ = new_type;
261  }
void BLOBNBOX::set_line_crossings ( int  value)
inline

Definition at line 380 of file blobbox.h.

380  {
381  line_crossings_ = value;
382  }
void BLOBNBOX::set_neighbour ( BlobNeighbourDir  n,
BLOBNBOX neighbour,
bool  good 
)
inline

Definition at line 361 of file blobbox.h.

361  {
362  neighbours_[n] = neighbour;
363  good_stroke_neighbours_[n] = good;
364  }
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:355
void BLOBNBOX::set_owner ( tesseract::ColPartition new_owner)
inline

Definition at line 340 of file blobbox.h.

340  {
341  owner_ = new_owner;
342  }
void BLOBNBOX::set_owns_cblob ( bool  value)
inline

Definition at line 393 of file blobbox.h.

393 { owns_cblob_ = value; }
void BLOBNBOX::set_reduced_box ( TBOX  new_box)
inline

Definition at line 234 of file blobbox.h.

234  {
235  red_box = new_box;
236  reduced = TRUE;
237  }
#define TRUE
Definition: capi.h:28
void BLOBNBOX::set_region_type ( BlobRegionType  new_type)
inline

Definition at line 271 of file blobbox.h.

271  {
272  region_type_ = new_type;
273  }
void BLOBNBOX::set_repeated_set ( int  set_id)
inline

Definition at line 250 of file blobbox.h.

250  {
251  repeated_set_ = set_id;
252  }
void BLOBNBOX::set_right_crossing_rule ( int  new_right)
inline

Definition at line 319 of file blobbox.h.

319  {
320  right_crossing_rule_ = new_right;
321  }
void BLOBNBOX::set_right_rule ( int  new_right)
inline

Definition at line 307 of file blobbox.h.

307  {
308  right_rule_ = new_right;
309  }
void BLOBNBOX::set_right_tab_type ( TabType  new_type)
inline

Definition at line 265 of file blobbox.h.

265  {
266  right_tab_type_ = new_type;
267  }
void BLOBNBOX::set_special_text_type ( BlobSpecialTextType  new_type)
inline

Definition at line 277 of file blobbox.h.

277  {
278  spt_type_ = new_type;
279  }
void BLOBNBOX::set_vert_possible ( bool  value)
inline

Definition at line 289 of file blobbox.h.

289  {
290  vert_possible_ = value;
291  }
void BLOBNBOX::set_vert_stroke_width ( float  width)
inline

Definition at line 331 of file blobbox.h.

331  {
332  vert_stroke_width_ = width;
333  }
BlobSpecialTextType BLOBNBOX::special_text_type ( ) const
inline

Definition at line 274 of file blobbox.h.

274  {
275  return spt_type_;
276  }
ScrollView::Color BLOBNBOX::TextlineColor ( BlobRegionType  region_type,
BlobTextFlowType  flow_type 
)
static

Definition at line 437 of file blobbox.cpp.

438  {
439  switch (region_type) {
440  case BRT_HLINE:
441  return ScrollView::BROWN;
442  case BRT_VLINE:
443  return ScrollView::DARK_GREEN;
444  case BRT_RECTIMAGE:
445  return ScrollView::RED;
446  case BRT_POLYIMAGE:
447  return ScrollView::ORANGE;
448  case BRT_UNKNOWN:
449  return flow_type == BTFT_NONTEXT ? ScrollView::CYAN : ScrollView::WHITE;
450  case BRT_VERT_TEXT:
451  if (flow_type == BTFT_STRONG_CHAIN || flow_type == BTFT_TEXT_ON_IMAGE)
452  return ScrollView::GREEN;
453  if (flow_type == BTFT_CHAIN)
454  return ScrollView::LIME_GREEN;
455  return ScrollView::YELLOW;
456  case BRT_TEXT:
457  if (flow_type == BTFT_STRONG_CHAIN)
458  return ScrollView::BLUE;
459  if (flow_type == BTFT_TEXT_ON_IMAGE)
460  return ScrollView::LIGHT_BLUE;
461  if (flow_type == BTFT_CHAIN)
463  if (flow_type == BTFT_LEADER)
464  return ScrollView::WHEAT;
465  if (flow_type == BTFT_NONTEXT)
466  return ScrollView::PINK;
467  return ScrollView::MAGENTA;
468  default:
469  return ScrollView::GREY;
470  }
471 }
BlobRegionType region_type() const
Definition: blobbox.h:268
void BLOBNBOX::translate_box ( ICOORD  v)
inline

Definition at line 159 of file blobbox.h.

159  {
160  if (IsDiacritic()) {
161  box.move(v);
162  base_char_top_ += v.y();
163  base_char_bottom_ += v.y();
164  } else {
165  box.move(v);
166  set_diacritic_box(box);
167  }
168  }
inT16 y() const
access_function
Definition: points.h:56
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:383
void move(const ICOORD vec)
Definition: rect.h:153
bool IsDiacritic() const
Definition: blobbox.h:365
bool BLOBNBOX::UniquelyHorizontal ( ) const
inline

Definition at line 398 of file blobbox.h.

398  {
399  return horz_possible_ && !vert_possible_;
400  }
bool BLOBNBOX::UniquelyVertical ( ) const
inline

Definition at line 395 of file blobbox.h.

395  {
396  return vert_possible_ && !horz_possible_;
397  }
static bool BLOBNBOX::UnMergeableType ( BlobRegionType  type)
inlinestatic

Definition at line 415 of file blobbox.h.

415  {
416  return IsLineType(type) || IsImageType(type);
417  }
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:411
static bool IsImageType(BlobRegionType type)
Definition: blobbox.h:407
bool BLOBNBOX::vert_possible ( ) const
inline

Definition at line 286 of file blobbox.h.

286  {
287  return vert_possible_;
288  }
float BLOBNBOX::vert_stroke_width ( ) const
inline

Definition at line 328 of file blobbox.h.

328  {
329  return vert_stroke_width_;
330  }

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