tesseract  4.0.0-1-g2a2b
C_BLOB Class Reference

#include <stepblob.h>

Inheritance diagram for C_BLOB:
ELIST_LINK

Public Member Functions

 C_BLOB ()=default
 
 C_BLOB (C_OUTLINE_LIST *outline_list)
 
 C_BLOB (C_OUTLINE *outline)
 
void CheckInverseFlagAndDirection ()
 
C_OUTLINE_LIST * out_list ()
 
TBOX bounding_box () const
 
int32_t area ()
 
int32_t perimeter ()
 
int32_t outer_area ()
 
int32_t count_transitions (int32_t threshold)
 
void move (const ICOORD vec)
 
void rotate (const FCOORD &rotation)
 
void ComputeEdgeOffsets (int threshold, Pix *pix)
 
int16_t EstimateBaselinePosition ()
 
Pix * render ()
 
Pix * render_outline ()
 
void plot (ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
 
void plot_normed (const DENORM &denorm, ScrollView::Color blob_colour, ScrollView::Color child_colour, ScrollView *window)
 
C_BLOBoperator= (const C_BLOB &source)
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static void ConstructBlobsFromOutlines (bool good_blob, C_OUTLINE_LIST *outline_list, C_BLOB_IT *good_blobs_it, C_BLOB_IT *bad_blobs_it)
 
static C_BLOBFakeBlob (const TBOX &box)
 
static C_BLOBdeep_copy (const C_BLOB *src)
 
static int SortByXMiddle (const void *v1, const void *v2)
 

Detailed Description

Definition at line 37 of file stepblob.h.

Constructor & Destructor Documentation

◆ C_BLOB() [1/3]

C_BLOB::C_BLOB ( )
default

◆ C_BLOB() [2/3]

C_BLOB::C_BLOB ( C_OUTLINE_LIST *  outline_list)
explicit

Definition at line 165 of file stepblob.cpp.

165  {
166  for (C_OUTLINE_IT ol_it(outline_list); !ol_it.empty(); ol_it.forward()) {
167  C_OUTLINE* outline = ol_it.extract();
168  // Position this outline in appropriate position in the hierarchy.
169  position_outline(outline, &outlines);
170  }
172 }
void CheckInverseFlagAndDirection()
Definition: stepblob.cpp:226

◆ C_BLOB() [3/3]

C_BLOB::C_BLOB ( C_OUTLINE outline)
explicit

Definition at line 176 of file stepblob.cpp.

176  {
177  C_OUTLINE_IT it(&outlines);
178  it.add_to_end(outline);
179 }

Member Function Documentation

◆ area()

int32_t C_BLOB::area ( )

Definition at line 275 of file stepblob.cpp.

275  { //area
276  C_OUTLINE *outline; //current outline
277  C_OUTLINE_IT it = &outlines; //outlines of blob
278  int32_t total; //total area
279 
280  total = 0;
281  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
282  outline = it.data ();
283  total += outline->area ();
284  }
285  return total;
286 }
int32_t area() const
Definition: coutln.cpp:256

◆ bounding_box()

TBOX C_BLOB::bounding_box ( ) const

Definition at line 255 of file stepblob.cpp.

255  { // bounding box
256  C_OUTLINE *outline; // current outline
257  // This is a read-only iteration of the outlines.
258  C_OUTLINE_IT it = const_cast<C_OUTLINE_LIST*>(&outlines);
259  TBOX box; // bounding box
260 
261  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
262  outline = it.data ();
263  box += outline->bounding_box ();
264  }
265  return box;
266 }
Definition: rect.h:34
const TBOX & bounding_box() const
Definition: coutln.h:113

◆ CheckInverseFlagAndDirection()

void C_BLOB::CheckInverseFlagAndDirection ( )

Definition at line 226 of file stepblob.cpp.

226  {
227  C_OUTLINE_IT ol_it(&outlines);
228  for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
229  C_OUTLINE* outline = ol_it.data();
230  if (outline->turn_direction() < 0) {
231  outline->reverse();
232  reverse_outline_list(outline->child());
233  outline->set_flag(COUT_INVERSE, TRUE);
234  } else {
235  outline->set_flag(COUT_INVERSE, FALSE);
236  }
237  }
238 }
#define TRUE
Definition: capi.h:51
int16_t turn_direction() const
Definition: coutln.cpp:538
#define FALSE
Definition: capi.h:52
C_OUTLINE_LIST * child()
Definition: coutln.h:108
void set_flag(C_OUTLINE_FLAGS mask, bool value)
Definition: coutln.h:102
void reverse()
Definition: coutln.cpp:566

◆ ComputeEdgeOffsets()

void C_BLOB::ComputeEdgeOffsets ( int  threshold,
Pix *  pix 
)

Definition at line 415 of file stepblob.cpp.

415  {
416  ComputeEdgeOffsetsOutlineList(threshold, pix, &outlines);
417 }

◆ ConstructBlobsFromOutlines()

void C_BLOB::ConstructBlobsFromOutlines ( bool  good_blob,
C_OUTLINE_LIST *  outline_list,
C_BLOB_IT *  good_blobs_it,
C_BLOB_IT *  bad_blobs_it 
)
static

Definition at line 191 of file stepblob.cpp.

194  {
195  // List of top-level outlines with correctly nested children.
196  C_OUTLINE_LIST nested_outlines;
197  for (C_OUTLINE_IT ol_it(outline_list); !ol_it.empty(); ol_it.forward()) {
198  C_OUTLINE* outline = ol_it.extract();
199  // Position this outline in appropriate position in the hierarchy.
200  position_outline(outline, &nested_outlines);
201  }
202  // Check for legal nesting and reassign as required.
203  for (C_OUTLINE_IT ol_it(&nested_outlines); !ol_it.empty(); ol_it.forward()) {
204  C_OUTLINE* outline = ol_it.extract();
205  bool blob_is_good = good_blob;
206  if (!outline->IsLegallyNested()) {
207  // The blob is illegally nested.
208  // Mark it bad, and add all its children to the top-level list.
209  blob_is_good = false;
210  ol_it.add_list_after(outline->child());
211  }
212  C_BLOB* blob = new C_BLOB(outline);
213  // Set inverse flag and reverse if needed.
215  // Put on appropriate list.
216  if (!blob_is_good && bad_blobs_it != nullptr)
217  bad_blobs_it->add_after_then_move(blob);
218  else
219  good_blobs_it->add_after_then_move(blob);
220  }
221 }
C_OUTLINE_LIST * child()
Definition: coutln.h:108
C_BLOB()=default
bool IsLegallyNested() const
Definition: coutln.cpp:605
void CheckInverseFlagAndDirection()
Definition: stepblob.cpp:226

◆ count_transitions()

int32_t C_BLOB::count_transitions ( int32_t  threshold)

Definition at line 335 of file stepblob.cpp.

337  {
338  C_OUTLINE *outline; //current outline
339  C_OUTLINE_IT it = &outlines; //outlines of blob
340  int32_t total; //total area
341 
342  total = 0;
343  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
344  outline = it.data ();
345  total += outline->count_transitions (threshold);
346  }
347  return total;
348 }
int32_t count_transitions(int32_t threshold)
Definition: coutln.cpp:341

◆ deep_copy()

static C_BLOB* C_BLOB::deep_copy ( const C_BLOB src)
inlinestatic

Definition at line 119 of file stepblob.h.

119  {
120  C_BLOB* blob = new C_BLOB;
121  *blob = *src;
122  return blob;
123  }
C_BLOB()=default

◆ EstimateBaselinePosition()

int16_t C_BLOB::EstimateBaselinePosition ( )

Definition at line 433 of file stepblob.cpp.

433  {
434  TBOX box = bounding_box();
435  int left = box.left();
436  int width = box.width();
437  int bottom = box.bottom();
438  if (outlines.empty() || perimeter() > width * kMaxPerimeterWidthRatio)
439  return bottom; // This is only for non-CJK blobs.
440  // Get the minimum y coordinate at each x-coordinate.
441  GenericVector<int> y_mins;
442  y_mins.init_to_size(width + 1, box.top());
443  C_OUTLINE_IT it(&outlines);
444  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
445  C_OUTLINE* outline = it.data();
446  ICOORD pos = outline->start_pos();
447  for (int s = 0; s < outline->pathlength(); ++s) {
448  if (pos.y() < y_mins[pos.x() - left])
449  y_mins[pos.x() - left] = pos.y();
450  pos += outline->step(s);
451  }
452  }
453  // Find the total extent of the bottom or bottom + 1.
454  int bottom_extent = 0;
455  for (int x = 0; x <= width; ++x) {
456  if (y_mins[x] == bottom || y_mins[x] == bottom + 1)
457  ++bottom_extent;
458  }
459  // Find the lowest run longer than the bottom extent that is not the bottom.
460  int best_min = box.top();
461  int prev_run = 0;
462  int prev_y = box.top();
463  int prev_prev_y = box.top();
464  for (int x = 0; x < width; x += prev_run) {
465  // Find the length of the current run.
466  int y_at_x = y_mins[x];
467  int run = 1;
468  while (x + run <= width && y_mins[x + run] == y_at_x) ++run;
469  if (y_at_x > bottom + 1) {
470  // Possible contender.
471  int total_run = run;
472  // Find extent of current value or +1 to the right of x.
473  while (x + total_run <= width &&
474  (y_mins[x + total_run] == y_at_x ||
475  y_mins[x + total_run] == y_at_x + 1)) ++total_run;
476  // At least one end has to be higher so it is not a local max.
477  if (prev_prev_y > y_at_x + 1 || x + total_run > width ||
478  y_mins[x + total_run] > y_at_x + 1) {
479  // If the prev_run is at y + 1, then we can add that too. There cannot
480  // be a suitable run at y before that or we would have found it already.
481  if (prev_run > 0 && prev_y == y_at_x + 1) total_run += prev_run;
482  if (total_run > bottom_extent && y_at_x < best_min) {
483  best_min = y_at_x;
484  }
485  }
486  }
487  prev_run = run;
488  prev_prev_y = prev_y;
489  prev_y = y_at_x;
490  }
491  return best_min == box.top() ? bottom : best_min;
492 }
const double kMaxPerimeterWidthRatio
Definition: stepblob.cpp:34
int16_t y() const
access_function
Definition: points.h:57
Definition: rect.h:34
const ICOORD & start_pos() const
Definition: coutln.h:148
int32_t perimeter()
Definition: stepblob.cpp:294
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
void init_to_size(int size, const T &t)
int32_t pathlength() const
Definition: coutln.h:135
TBOX bounding_box() const
Definition: stepblob.cpp:255
int16_t bottom() const
Definition: rect.h:65
ICOORD step(int index) const
Definition: coutln.h:144

◆ FakeBlob()

C_BLOB * C_BLOB::FakeBlob ( const TBOX box)
static

Definition at line 243 of file stepblob.cpp.

243  {
244  C_OUTLINE_LIST outlines;
245  C_OUTLINE::FakeOutline(box, &outlines);
246  return new C_BLOB(&outlines);
247 }
C_BLOB()=default
static void FakeOutline(const TBOX &box, C_OUTLINE_LIST *outlines)
Definition: coutln.cpp:240

◆ move()

void C_BLOB::move ( const ICOORD  vec)

Definition at line 357 of file stepblob.cpp.

359  {
360  C_OUTLINE_IT it(&outlines); // iterator
361 
362  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
363  it.data ()->move (vec); // move each outline
364 }

◆ operator=()

C_BLOB& C_BLOB::operator= ( const C_BLOB source)
inline

Definition at line 112 of file stepblob.h.

112  {
113  if (!outlines.empty ())
114  outlines.clear();
115  outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy);
116  return *this;
117  }
static C_OUTLINE * deep_copy(const C_OUTLINE *src)
Definition: coutln.h:261

◆ out_list()

C_OUTLINE_LIST* C_BLOB::out_list ( )
inline

Definition at line 70 of file stepblob.h.

70  { //get outline list
71  return &outlines;
72  }

◆ outer_area()

int32_t C_BLOB::outer_area ( )

Definition at line 314 of file stepblob.cpp.

314  { //area
315  C_OUTLINE *outline; //current outline
316  C_OUTLINE_IT it = &outlines; //outlines of blob
317  int32_t total; //total area
318 
319  total = 0;
320  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
321  outline = it.data ();
322  total += outline->outer_area ();
323  }
324  return total;
325 }
int32_t outer_area() const
Definition: coutln.cpp:309

◆ perimeter()

int32_t C_BLOB::perimeter ( )

Definition at line 294 of file stepblob.cpp.

294  {
295  C_OUTLINE *outline; // current outline
296  C_OUTLINE_IT it = &outlines; // outlines of blob
297  int32_t total; // total perimeter
298 
299  total = 0;
300  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
301  outline = it.data();
302  total += outline->perimeter();
303  }
304  return total;
305 }
int32_t perimeter() const
Definition: coutln.cpp:290

◆ plot()

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

Definition at line 538 of file stepblob.cpp.

540  { // for holes
541  plot_outline_list(&outlines, window, blob_colour, child_colour);
542 }

◆ plot_normed()

void C_BLOB::plot_normed ( const DENORM denorm,
ScrollView::Color  blob_colour,
ScrollView::Color  child_colour,
ScrollView window 
)

Definition at line 546 of file stepblob.cpp.

549  {
550  plot_normed_outline_list(denorm, &outlines, blob_colour, child_colour,
551  window);
552 }

◆ render()

Pix * C_BLOB::render ( )

Definition at line 515 of file stepblob.cpp.

515  {
516  TBOX box = bounding_box();
517  Pix* pix = pixCreate(box.width(), box.height(), 1);
518  render_outline_list(&outlines, box.left(), box.top(), pix);
519  return pix;
520 }
Definition: rect.h:34
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
TBOX bounding_box() const
Definition: stepblob.cpp:255
int16_t height() const
Definition: rect.h:108

◆ render_outline()

Pix * C_BLOB::render_outline ( )

Definition at line 524 of file stepblob.cpp.

524  {
525  TBOX box = bounding_box();
526  Pix* pix = pixCreate(box.width(), box.height(), 1);
527  render_outline_list_outline(&outlines, box.left(), box.top(), pix);
528  return pix;
529 }
Definition: rect.h:34
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
TBOX bounding_box() const
Definition: stepblob.cpp:255
int16_t height() const
Definition: rect.h:108

◆ rotate()

void C_BLOB::rotate ( const FCOORD rotation)

Definition at line 393 of file stepblob.cpp.

393  {
394  RotateOutlineList(rotation, &outlines);
395 }

◆ SortByXMiddle()

static int C_BLOB::SortByXMiddle ( const void *  v1,
const void *  v2 
)
inlinestatic

Definition at line 125 of file stepblob.h.

125  {
126  const C_BLOB* blob1 = *static_cast<const C_BLOB* const*>(v1);
127  const C_BLOB* blob2 = *static_cast<const C_BLOB* const*>(v2);
128  return blob1->bounding_box().x_middle() -
129  blob2->bounding_box().x_middle();
130  }
TBOX bounding_box() const
Definition: stepblob.cpp:255
int x_middle() const
Definition: rect.h:85

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