tesseract  4.00.00dev
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() [1/2]

BLOBNBOX::BLOBNBOX ( )
inline

Definition at line 131 of file blobbox.h.

131  {
133  }
void ConstructionInit()
Definition: blobbox.h:455

◆ BLOBNBOX() [2/2]

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
inT32 area()
Definition: stepblob.cpp:270
TBOX bounding_box() const
Definition: stepblob.cpp:250

◆ ~BLOBNBOX()

BLOBNBOX::~BLOBNBOX ( )
inline

Definition at line 140 of file blobbox.h.

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

Member Function Documentation

◆ area_stroke_width()

float BLOBNBOX::area_stroke_width ( ) const
inline

Definition at line 334 of file blobbox.h.

334  {
335  return area_stroke_width_;
336  }

◆ base_char_blob()

BLOBNBOX* BLOBNBOX::base_char_blob ( ) const
inline

Definition at line 387 of file blobbox.h.

387  {
388  return base_char_blob_;
389  }

◆ base_char_bottom()

int BLOBNBOX::base_char_bottom ( ) const
inline

Definition at line 371 of file blobbox.h.

371  {
372  return base_char_bottom_;
373  }

◆ base_char_top()

int BLOBNBOX::base_char_top ( ) const
inline

Definition at line 368 of file blobbox.h.

368  {
369  return base_char_top_;
370  }

◆ baseline_position()

int BLOBNBOX::baseline_position ( ) const
inline

Definition at line 374 of file blobbox.h.

374  {
375  return baseline_y_;
376  }

◆ bounding_box()

const TBOX& BLOBNBOX::bounding_box ( ) const
inline

Definition at line 215 of file blobbox.h.

215  {
216  return box;
217  }

◆ BoundsWithinLimits()

TBOX BLOBNBOX::BoundsWithinLimits ( int  left,
int  right 
)

Definition at line 328 of file blobbox.cpp.

328  {
329  FCOORD no_rotation(1.0f, 0.0f);
330  float top = box.top();
331  float bottom = box.bottom();
332  if (cblob_ptr != NULL) {
333  find_cblob_limits(cblob_ptr, static_cast<float>(left),
334  static_cast<float>(right), no_rotation,
335  bottom, top);
336  }
337 
338  if (top < bottom) {
339  top = box.top();
340  bottom = box.bottom();
341  }
342  FCOORD bot_left(left, bottom);
343  FCOORD top_right(right, top);
344  TBOX shrunken_box(bot_left);
345  TBOX shrunken_box2(top_right);
346  shrunken_box += shrunken_box2;
347  return shrunken_box;
348 }
Definition: points.h:189
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
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:494

◆ BoxColor()

ScrollView::Color BLOBNBOX::BoxColor ( ) const

Definition at line 476 of file blobbox.cpp.

476  {
477  return TextlineColor(region_type_, flow_);
478 }
static ScrollView::Color TextlineColor(BlobRegionType region_type, BlobTextFlowType flow_type)
Definition: blobbox.cpp:439

◆ cblob()

C_BLOB* BLOBNBOX::cblob ( ) const
inline

Definition at line 253 of file blobbox.h.

253  {
254  return cblob_ptr;
255  }

◆ chop()

void BLOBNBOX::chop ( BLOBNBOX_IT *  start_it,
BLOBNBOX_IT *  blob_it,
FCOORD  rotation,
float  xheight 
)

Definition at line 115 of file blobbox.cpp.

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

◆ CleanNeighbours() [1/2]

void BLOBNBOX::CleanNeighbours ( )

Definition at line 209 of file blobbox.cpp.

209  {
210  for (int dir = 0; dir < BND_COUNT; ++dir) {
211  BLOBNBOX* neighbour = neighbours_[dir];
212  if (neighbour != NULL && neighbour->DeletableNoise()) {
213  neighbours_[dir] = NULL;
214  good_stroke_neighbours_[dir] = false;
215  }
216  }
217 }
bool DeletableNoise() const
Definition: blobbox.h:188
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:355

◆ CleanNeighbours() [2/2]

void BLOBNBOX::CleanNeighbours ( BLOBNBOX_LIST *  blobs)
static

Definition at line 359 of file blobbox.cpp.

359  {
360  BLOBNBOX_IT blob_it(blobs);
361  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
362  blob_it.data()->CleanNeighbours();
363  }
364 }

◆ ClearNeighbours()

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  }

◆ compute_bounding_box()

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 top() const
Definition: rect.h:54
TBOX bounding_box() const
Definition: stepblob.cpp:250
inT16 bottom() const
Definition: rect.h:61

◆ ComputeEdgeOffsets()

void BLOBNBOX::ComputeEdgeOffsets ( Pix *  thresholds,
Pix *  grey,
BLOBNBOX_LIST *  blobs 
)
static

Definition at line 380 of file blobbox.cpp.

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

◆ ConfirmNoTabViolation()

bool BLOBNBOX::ConfirmNoTabViolation ( const BLOBNBOX other) const

Definition at line 287 of file blobbox.cpp.

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

◆ ConstructionInit()

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

◆ DefiniteIndividualFlow()

bool BLOBNBOX::DefiniteIndividualFlow ( )

Definition at line 247 of file blobbox.cpp.

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

◆ DeletableNoise()

bool BLOBNBOX::DeletableNoise ( ) const
inline

Definition at line 188 of file blobbox.h.

188  {
189  return owner() == NULL && region_type() == BRT_NOISE;
190  }
tesseract::ColPartition * owner() const
Definition: blobbox.h:337
BlobRegionType region_type() const
Definition: blobbox.h:268

◆ DeleteNoiseBlobs()

void BLOBNBOX::DeleteNoiseBlobs ( BLOBNBOX_LIST *  blobs)
static

Definition at line 367 of file blobbox.cpp.

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

◆ enclosed_area()

inT32 BLOBNBOX::enclosed_area ( ) const
inline

Definition at line 238 of file blobbox.h.

238  {
239  return area;
240  }

◆ EstimateBaselinePosition()

void BLOBNBOX::EstimateBaselinePosition ( )

Definition at line 352 of file blobbox.cpp.

352  {
353  baseline_y_ = box.bottom(); // The default.
354  if (cblob_ptr == NULL) return;
355  baseline_y_ = cblob_ptr->EstimateBaselinePosition();
356 }
inT16 bottom() const
Definition: rect.h:61
inT16 EstimateBaselinePosition()
Definition: stepblob.cpp:427

◆ flow()

BlobTextFlowType BLOBNBOX::flow ( ) const
inline

Definition at line 280 of file blobbox.h.

280  {
281  return flow_;
282  }

◆ good_stroke_neighbour()

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  }

◆ GoodTextBlob()

int BLOBNBOX::GoodTextBlob ( ) const

Definition at line 221 of file blobbox.cpp.

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

◆ horz_possible()

bool BLOBNBOX::horz_possible ( ) const
inline

Definition at line 292 of file blobbox.h.

292  {
293  return horz_possible_;
294  }

◆ horz_stroke_width()

float BLOBNBOX::horz_stroke_width ( ) const
inline

Definition at line 322 of file blobbox.h.

322  {
323  return horz_stroke_width_;
324  }

◆ IsDiacritic()

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 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61

◆ IsImageType()

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  }

◆ IsLineType()

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  }

◆ IsTextType()

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  }

◆ joined_to_prev()

bool BLOBNBOX::joined_to_prev ( ) const
inline

Definition at line 241 of file blobbox.h.

241  {
242  return joined != 0;
243  }

◆ leader_on_left()

bool BLOBNBOX::leader_on_left ( ) const
inline

Definition at line 343 of file blobbox.h.

343  {
344  return leader_on_left_;
345  }

◆ leader_on_right()

bool BLOBNBOX::leader_on_right ( ) const
inline

Definition at line 349 of file blobbox.h.

349  {
350  return leader_on_right_;
351  }

◆ left_crossing_rule()

int BLOBNBOX::left_crossing_rule ( ) const
inline

Definition at line 310 of file blobbox.h.

310  {
311  return left_crossing_rule_;
312  }

◆ left_rule()

int BLOBNBOX::left_rule ( ) const
inline

Definition at line 298 of file blobbox.h.

298  {
299  return left_rule_;
300  }

◆ left_tab_type()

TabType BLOBNBOX::left_tab_type ( ) const
inline

Definition at line 256 of file blobbox.h.

256  {
257  return left_tab_type_;
258  }

◆ line_crossings()

int BLOBNBOX::line_crossings ( ) const
inline

Definition at line 377 of file blobbox.h.

377  {
378  return line_crossings_;
379  }

◆ MatchingStrokeWidth()

bool BLOBNBOX::MatchingStrokeWidth ( const BLOBNBOX other,
double  fractional_tolerance,
double  constant_tolerance 
) const

Definition at line 300 of file blobbox.cpp.

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

◆ merge()

void BLOBNBOX::merge ( BLOBNBOX nextblob)

Definition at line 87 of file blobbox.cpp.

89  {
90  box += nextblob->box; //merge boxes
91  set_diacritic_box(box);
92  nextblob->joined = TRUE;
93 }
#define TRUE
Definition: capi.h:45
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:383

◆ MinMaxGapsClipped()

void BLOBNBOX::MinMaxGapsClipped ( int h_min,
int h_max,
int v_min,
int v_max 
) const

Definition at line 195 of file blobbox.cpp.

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

◆ neighbour()

BLOBNBOX* BLOBNBOX::neighbour ( BlobNeighbourDir  n) const
inline

Definition at line 355 of file blobbox.h.

355  {
356  return neighbours_[n];
357  }

◆ NeighbourGaps()

void BLOBNBOX::NeighbourGaps ( int  gaps[BND_COUNT]) const

Definition at line 176 of file blobbox.cpp.

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

◆ NoisyNeighbours()

int BLOBNBOX::NoisyNeighbours ( ) const

Definition at line 232 of file blobbox.cpp.

232  {
233  int count = 0;
234  for (int dir = 0; dir < BND_COUNT; ++dir) {
235  BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir);
236  BLOBNBOX* blob = neighbour(bnd);
237  if (blob != NULL && blob->region_type() == BRT_NOISE)
238  ++count;
239  }
240  return count;
241 }
BlobRegionType region_type() const
Definition: blobbox.h:268
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:355
BlobNeighbourDir
Definition: blobbox.h:72
int count(LIST var_list)
Definition: oldlist.cpp:103

◆ owner()

tesseract::ColPartition* BLOBNBOX::owner ( ) const
inline

Definition at line 337 of file blobbox.h.

337  {
338  return owner_;
339  }

◆ plot()

void BLOBNBOX::plot ( ScrollView window,
ScrollView::Color  blob_colour,
ScrollView::Color  child_colour 
)

Definition at line 480 of file blobbox.cpp.

482  { // for holes
483  if (cblob_ptr != NULL)
484  cblob_ptr->plot(window, blob_colour, child_colour);
485 }
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: stepblob.cpp:532

◆ PlotBlobs()

void BLOBNBOX::PlotBlobs ( BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour,
ScrollView win 
)
static

Definition at line 414 of file blobbox.cpp.

417  {
418  BLOBNBOX_IT it(list);
419  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
420  it.data()->plot(win, body_colour, child_colour);
421  }
422 }

◆ PlotNoiseBlobs()

void BLOBNBOX::PlotNoiseBlobs ( BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour,
ScrollView win 
)
static

Definition at line 427 of file blobbox.cpp.

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

◆ RealBlob()

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

◆ really_merge()

void BLOBNBOX::really_merge ( BLOBNBOX other)

Definition at line 98 of file blobbox.cpp.

98  {
99  if (cblob_ptr != NULL && other->cblob_ptr != NULL) {
100  C_OUTLINE_IT ol_it(cblob_ptr->out_list());
101  ol_it.add_list_after(other->cblob_ptr->out_list());
102  }
104 }
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:64
void compute_bounding_box()
Definition: blobbox.h:225

◆ red_box_set()

bool BLOBNBOX::red_box_set ( ) const
inline

Definition at line 244 of file blobbox.h.

244  {
245  return reduced != 0;
246  }

◆ reduced_box()

const TBOX& BLOBNBOX::reduced_box ( ) const
inline

Definition at line 231 of file blobbox.h.

231  {
232  return red_box;
233  }

◆ reflect_box_in_y_axis()

void BLOBNBOX::reflect_box_in_y_axis ( )

Definition at line 57 of file blobbox.cpp.

57  {
58  int left = -box.right();
59  box.set_right(-box.left());
60  box.set_left(left);
61 }
inT16 left() const
Definition: rect.h:68
inT16 right() const
Definition: rect.h:75
void set_right(int x)
Definition: rect.h:78
void set_left(int x)
Definition: rect.h:71

◆ region_type()

BlobRegionType BLOBNBOX::region_type ( ) const
inline

Definition at line 268 of file blobbox.h.

268  {
269  return region_type_;
270  }

◆ ReInit()

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  }
C_BLOB * cblob() const
Definition: blobbox.h:253
void ClearNeighbours()
Definition: blobbox.h:494
inT16 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61
inT32 perimeter()
Definition: stepblob.cpp:289

◆ repeated_set()

int BLOBNBOX::repeated_set ( ) const
inline

Definition at line 247 of file blobbox.h.

247  {
248  return repeated_set_;
249  }

◆ right_crossing_rule()

int BLOBNBOX::right_crossing_rule ( ) const
inline

Definition at line 316 of file blobbox.h.

316  {
317  return right_crossing_rule_;
318  }

◆ right_rule()

int BLOBNBOX::right_rule ( ) const
inline

Definition at line 304 of file blobbox.h.

304  {
305  return right_rule_;
306  }

◆ right_tab_type()

TabType BLOBNBOX::right_tab_type ( ) const
inline

Definition at line 262 of file blobbox.h.

262  {
263  return right_tab_type_;
264  }

◆ rotate()

void BLOBNBOX::rotate ( FCOORD  rotation)

Definition at line 50 of file blobbox.cpp.

50  {
51  cblob_ptr->rotate(rotation);
52  rotate_box(rotation);
54 }
void rotate_box(FCOORD rotation)
Definition: blobbox.cpp:66
void rotate(const FCOORD &rotation)
Definition: stepblob.cpp:387
void compute_bounding_box()
Definition: blobbox.h:225

◆ rotate_box()

void BLOBNBOX::rotate_box ( FCOORD  rotation)

Definition at line 66 of file blobbox.cpp.

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

◆ set_base_char_blob()

void BLOBNBOX::set_base_char_blob ( BLOBNBOX blob)
inline

Definition at line 390 of file blobbox.h.

390  {
391  base_char_blob_ = blob;
392  }

◆ set_bounding_box()

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 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61

◆ set_diacritic_box()

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 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61

◆ set_flow()

void BLOBNBOX::set_flow ( BlobTextFlowType  value)
inline

Definition at line 283 of file blobbox.h.

283  {
284  flow_ = value;
285  }

◆ set_horz_possible()

void BLOBNBOX::set_horz_possible ( bool  value)
inline

Definition at line 295 of file blobbox.h.

295  {
296  horz_possible_ = value;
297  }

◆ set_horz_stroke_width()

void BLOBNBOX::set_horz_stroke_width ( float  width)
inline

Definition at line 325 of file blobbox.h.

325  {
326  horz_stroke_width_ = width;
327  }

◆ set_leader_on_left()

void BLOBNBOX::set_leader_on_left ( bool  flag)
inline

Definition at line 346 of file blobbox.h.

346  {
347  leader_on_left_ = flag;
348  }

◆ set_leader_on_right()

void BLOBNBOX::set_leader_on_right ( bool  flag)
inline

Definition at line 352 of file blobbox.h.

352  {
353  leader_on_right_ = flag;
354  }

◆ set_left_crossing_rule()

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  }

◆ set_left_rule()

void BLOBNBOX::set_left_rule ( int  new_left)
inline

Definition at line 301 of file blobbox.h.

301  {
302  left_rule_ = new_left;
303  }

◆ set_left_tab_type()

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  }

◆ set_line_crossings()

void BLOBNBOX::set_line_crossings ( int  value)
inline

Definition at line 380 of file blobbox.h.

380  {
381  line_crossings_ = value;
382  }

◆ set_neighbour()

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

◆ set_owner()

void BLOBNBOX::set_owner ( tesseract::ColPartition new_owner)
inline

Definition at line 340 of file blobbox.h.

340  {
341  owner_ = new_owner;
342  }

◆ set_owns_cblob()

void BLOBNBOX::set_owns_cblob ( bool  value)
inline

Definition at line 393 of file blobbox.h.

393 { owns_cblob_ = value; }

◆ set_reduced_box()

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:45

◆ set_region_type()

void BLOBNBOX::set_region_type ( BlobRegionType  new_type)
inline

Definition at line 271 of file blobbox.h.

271  {
272  region_type_ = new_type;
273  }

◆ set_repeated_set()

void BLOBNBOX::set_repeated_set ( int  set_id)
inline

Definition at line 250 of file blobbox.h.

250  {
251  repeated_set_ = set_id;
252  }

◆ set_right_crossing_rule()

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  }

◆ set_right_rule()

void BLOBNBOX::set_right_rule ( int  new_right)
inline

Definition at line 307 of file blobbox.h.

307  {
308  right_rule_ = new_right;
309  }

◆ set_right_tab_type()

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  }

◆ set_special_text_type()

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  }

◆ set_vert_possible()

void BLOBNBOX::set_vert_possible ( bool  value)
inline

Definition at line 289 of file blobbox.h.

289  {
290  vert_possible_ = value;
291  }

◆ set_vert_stroke_width()

void BLOBNBOX::set_vert_stroke_width ( float  width)
inline

Definition at line 331 of file blobbox.h.

331  {
332  vert_stroke_width_ = width;
333  }

◆ special_text_type()

BlobSpecialTextType BLOBNBOX::special_text_type ( ) const
inline

Definition at line 274 of file blobbox.h.

274  {
275  return spt_type_;
276  }

◆ TextlineColor()

ScrollView::Color BLOBNBOX::TextlineColor ( BlobRegionType  region_type,
BlobTextFlowType  flow_type 
)
static

Definition at line 439 of file blobbox.cpp.

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

◆ translate_box()

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  }
bool IsDiacritic() const
Definition: blobbox.h:365
void set_diacritic_box(const TBOX &diacritic_box)
Definition: blobbox.h:383
inT16 y() const
access_function
Definition: points.h:56
void move(const ICOORD vec)
Definition: rect.h:153

◆ UniquelyHorizontal()

bool BLOBNBOX::UniquelyHorizontal ( ) const
inline

Definition at line 398 of file blobbox.h.

398  {
399  return horz_possible_ && !vert_possible_;
400  }

◆ UniquelyVertical()

bool BLOBNBOX::UniquelyVertical ( ) const
inline

Definition at line 395 of file blobbox.h.

395  {
396  return vert_possible_ && !horz_possible_;
397  }

◆ UnMergeableType()

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

◆ vert_possible()

bool BLOBNBOX::vert_possible ( ) const
inline

Definition at line 286 of file blobbox.h.

286  {
287  return vert_possible_;
288  }

◆ vert_stroke_width()

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: