tesseract  4.00.00dev
C_BLOB Class Reference

#include <stepblob.h>

Inheritance diagram for C_BLOB:
ELIST_LINK

Public Member Functions

 C_BLOB ()
 
 C_BLOB (C_OUTLINE_LIST *outline_list)
 
 C_BLOB (C_OUTLINE *outline)
 
void CheckInverseFlagAndDirection ()
 
C_OUTLINE_LIST * out_list ()
 
TBOX bounding_box () const
 
inT32 area ()
 
inT32 perimeter ()
 
inT32 outer_area ()
 
inT32 count_transitions (inT32 threshold)
 
void move (const ICOORD vec)
 
void rotate (const FCOORD &rotation)
 
void ComputeEdgeOffsets (int threshold, Pix *pix)
 
inT16 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 30 of file stepblob.h.

Constructor & Destructor Documentation

◆ C_BLOB() [1/3]

C_BLOB::C_BLOB ( )
inline

Definition at line 33 of file stepblob.h.

33  {
34  }

◆ C_BLOB() [2/3]

C_BLOB::C_BLOB ( C_OUTLINE_LIST *  outline_list)
explicit

Definition at line 160 of file stepblob.cpp.

160  {
161  for (C_OUTLINE_IT ol_it(outline_list); !ol_it.empty(); ol_it.forward()) {
162  C_OUTLINE* outline = ol_it.extract();
163  // Position this outline in appropriate position in the hierarchy.
164  position_outline(outline, &outlines);
165  }
167 }
void CheckInverseFlagAndDirection()
Definition: stepblob.cpp:221

◆ C_BLOB() [3/3]

C_BLOB::C_BLOB ( C_OUTLINE outline)
explicit

Definition at line 171 of file stepblob.cpp.

171  {
172  C_OUTLINE_IT it(&outlines);
173  it.add_to_end(outline);
174 }

Member Function Documentation

◆ area()

inT32 C_BLOB::area ( )

Definition at line 270 of file stepblob.cpp.

270  { //area
271  C_OUTLINE *outline; //current outline
272  C_OUTLINE_IT it = &outlines; //outlines of blob
273  inT32 total; //total area
274 
275  total = 0;
276  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
277  outline = it.data ();
278  total += outline->area ();
279  }
280  return total;
281 }
int32_t inT32
Definition: host.h:38
inT32 area() const
Definition: coutln.cpp:255

◆ bounding_box()

TBOX C_BLOB::bounding_box ( ) const

Definition at line 250 of file stepblob.cpp.

250  { // bounding box
251  C_OUTLINE *outline; // current outline
252  // This is a read-only iteration of the outlines.
253  C_OUTLINE_IT it = const_cast<C_OUTLINE_LIST*>(&outlines);
254  TBOX box; // bounding box
255 
256  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
257  outline = it.data ();
258  box += outline->bounding_box ();
259  }
260  return box;
261 }
const TBOX & bounding_box() const
Definition: coutln.h:111
Definition: rect.h:30

◆ CheckInverseFlagAndDirection()

void C_BLOB::CheckInverseFlagAndDirection ( )

Definition at line 221 of file stepblob.cpp.

221  {
222  C_OUTLINE_IT ol_it(&outlines);
223  for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
224  C_OUTLINE* outline = ol_it.data();
225  if (outline->turn_direction() < 0) {
226  outline->reverse();
227  reverse_outline_list(outline->child());
228  outline->set_flag(COUT_INVERSE, TRUE);
229  } else {
230  outline->set_flag(COUT_INVERSE, FALSE);
231  }
232  }
233 }
C_OUTLINE_LIST * child()
Definition: coutln.h:106
#define TRUE
Definition: capi.h:45
inT16 turn_direction() const
Definition: coutln.cpp:537
void reverse()
Definition: coutln.cpp:565
#define FALSE
Definition: capi.h:46
void set_flag(C_OUTLINE_FLAGS mask, BOOL8 value)
Definition: coutln.h:100

◆ ComputeEdgeOffsets()

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

Definition at line 409 of file stepblob.cpp.

409  {
410  ComputeEdgeOffsetsOutlineList(threshold, pix, &outlines);
411 }

◆ 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 186 of file stepblob.cpp.

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

◆ count_transitions()

inT32 C_BLOB::count_transitions ( inT32  threshold)

Definition at line 330 of file stepblob.cpp.

332  {
333  C_OUTLINE *outline; //current outline
334  C_OUTLINE_IT it = &outlines; //outlines of blob
335  inT32 total; //total area
336 
337  total = 0;
338  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
339  outline = it.data ();
340  total += outline->count_transitions (threshold);
341  }
342  return total;
343 }
int32_t inT32
Definition: host.h:38
inT32 count_transitions(inT32 threshold)
Definition: coutln.cpp:340

◆ deep_copy()

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

Definition at line 113 of file stepblob.h.

113  {
114  C_BLOB* blob = new C_BLOB;
115  *blob = *src;
116  return blob;
117  }
C_BLOB()
Definition: stepblob.h:33

◆ EstimateBaselinePosition()

inT16 C_BLOB::EstimateBaselinePosition ( )

Definition at line 427 of file stepblob.cpp.

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

◆ FakeBlob()

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

Definition at line 238 of file stepblob.cpp.

238  {
239  C_OUTLINE_LIST outlines;
240  C_OUTLINE::FakeOutline(box, &outlines);
241  return new C_BLOB(&outlines);
242 }
static void FakeOutline(const TBOX &box, C_OUTLINE_LIST *outlines)
Definition: coutln.cpp:239
C_BLOB()
Definition: stepblob.h:33

◆ move()

void C_BLOB::move ( const ICOORD  vec)

Definition at line 352 of file stepblob.cpp.

354  {
355  C_OUTLINE_IT it(&outlines); // iterator
356 
357  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
358  it.data ()->move (vec); // move each outline
359 }

◆ operator=()

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

Definition at line 106 of file stepblob.h.

106  {
107  if (!outlines.empty ())
108  outlines.clear();
109  outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy);
110  return *this;
111  }
static C_OUTLINE * deep_copy(const C_OUTLINE *src)
Definition: coutln.h:259

◆ out_list()

C_OUTLINE_LIST* C_BLOB::out_list ( )
inline

Definition at line 64 of file stepblob.h.

64  { //get outline list
65  return &outlines;
66  }

◆ outer_area()

inT32 C_BLOB::outer_area ( )

Definition at line 309 of file stepblob.cpp.

309  { //area
310  C_OUTLINE *outline; //current outline
311  C_OUTLINE_IT it = &outlines; //outlines of blob
312  inT32 total; //total area
313 
314  total = 0;
315  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
316  outline = it.data ();
317  total += outline->outer_area ();
318  }
319  return total;
320 }
int32_t inT32
Definition: host.h:38
inT32 outer_area() const
Definition: coutln.cpp:308

◆ perimeter()

inT32 C_BLOB::perimeter ( )

Definition at line 289 of file stepblob.cpp.

289  {
290  C_OUTLINE *outline; // current outline
291  C_OUTLINE_IT it = &outlines; // outlines of blob
292  inT32 total; // total perimeter
293 
294  total = 0;
295  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
296  outline = it.data();
297  total += outline->perimeter();
298  }
299  return total;
300 }
int32_t inT32
Definition: host.h:38
inT32 perimeter() const
Definition: coutln.cpp:289

◆ plot()

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

Definition at line 532 of file stepblob.cpp.

534  { // for holes
535  plot_outline_list(&outlines, window, blob_colour, child_colour);
536 }

◆ plot_normed()

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

Definition at line 540 of file stepblob.cpp.

543  {
544  plot_normed_outline_list(denorm, &outlines, blob_colour, child_colour,
545  window);
546 }

◆ render()

Pix * C_BLOB::render ( )

Definition at line 509 of file stepblob.cpp.

509  {
510  TBOX box = bounding_box();
511  Pix* pix = pixCreate(box.width(), box.height(), 1);
512  render_outline_list(&outlines, box.left(), box.top(), pix);
513  return pix;
514 }
inT16 left() const
Definition: rect.h:68
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111

◆ render_outline()

Pix * C_BLOB::render_outline ( )

Definition at line 518 of file stepblob.cpp.

518  {
519  TBOX box = bounding_box();
520  Pix* pix = pixCreate(box.width(), box.height(), 1);
521  render_outline_list_outline(&outlines, box.left(), box.top(), pix);
522  return pix;
523 }
inT16 left() const
Definition: rect.h:68
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111

◆ rotate()

void C_BLOB::rotate ( const FCOORD rotation)

Definition at line 387 of file stepblob.cpp.

387  {
388  RotateOutlineList(rotation, &outlines);
389 }
void RotateOutlineList(const FCOORD &rotation, C_OUTLINE_LIST *outlines)
Definition: stepblob.cpp:362

◆ SortByXMiddle()

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

Definition at line 119 of file stepblob.h.

119  {
120  const C_BLOB* blob1 = *static_cast<const C_BLOB* const *>(v1);
121  const C_BLOB* blob2 = *static_cast<const C_BLOB* const *>(v2);
122  return blob1->bounding_box().x_middle() -
123  blob2->bounding_box().x_middle();
124  }
TBOX bounding_box() const
Definition: stepblob.cpp:250
int x_middle() const
Definition: rect.h:81

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