tesseract  5.0.0-alpha-619-ge9db
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 36 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 158 of file stepblob.cpp.

163  {
164  for (C_OUTLINE_IT ol_it(outline_list); !ol_it.empty(); ol_it.forward()) {
165  C_OUTLINE* outline = ol_it.extract();

◆ C_BLOB() [3/3]

C_BLOB::C_BLOB ( C_OUTLINE outline)
explicit

Definition at line 169 of file stepblob.cpp.

Member Function Documentation

◆ area()

int32_t C_BLOB::area ( )

Definition at line 266 of file stepblob.cpp.

273  { //area
274  C_OUTLINE *outline; //current outline
275  C_OUTLINE_IT it = &outlines; //outlines of blob
276  int32_t total; //total area
277 

◆ bounding_box()

TBOX C_BLOB::bounding_box ( ) const

Definition at line 247 of file stepblob.cpp.

253  { // bounding box
254  C_OUTLINE *outline; // current outline
255  // This is a read-only iteration of the outlines.
256  C_OUTLINE_IT it = const_cast<C_OUTLINE_LIST*>(&outlines);
257  TBOX box; // bounding box
258 

◆ CheckInverseFlagAndDirection()

void C_BLOB::CheckInverseFlagAndDirection ( )

Definition at line 219 of file stepblob.cpp.

224  {
225  C_OUTLINE_IT ol_it(&outlines);
226  for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
227  C_OUTLINE* outline = ol_it.data();
228  if (outline->turn_direction() < 0) {
229  outline->reverse();
230  reverse_outline_list(outline->child());
231  outline->set_flag(COUT_INVERSE, true);

◆ ComputeEdgeOffsets()

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

Definition at line 401 of file stepblob.cpp.

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

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

◆ count_transitions()

int32_t C_BLOB::count_transitions ( int32_t  threshold)

Definition at line 323 of file stepblob.cpp.

335  {
336  C_OUTLINE *outline; //current outline

◆ deep_copy()

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

Definition at line 118 of file stepblob.h.

119  {
120  auto* blob = new C_BLOB;
121  *blob = *src;
122  return blob;

◆ EstimateBaselinePosition()

int16_t C_BLOB::EstimateBaselinePosition ( )

Definition at line 419 of file stepblob.cpp.

431  {
432  TBOX box = bounding_box();
433  int left = box.left();
434  int width = box.width();
435  int bottom = box.bottom();
436  if (outlines.empty() || perimeter() > width * kMaxPerimeterWidthRatio)
437  return bottom; // This is only for non-CJK blobs.
438  // Get the minimum y coordinate at each x-coordinate.
439  GenericVector<int> y_mins;
440  y_mins.init_to_size(width + 1, box.top());
441  C_OUTLINE_IT it(&outlines);
442  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
443  C_OUTLINE* outline = it.data();
444  ICOORD pos = outline->start_pos();
445  for (int s = 0; s < outline->pathlength(); ++s) {
446  if (pos.y() < y_mins[pos.x() - left])
447  y_mins[pos.x() - left] = pos.y();
448  pos += outline->step(s);
449  }
450  }
451  // Find the total extent of the bottom or bottom + 1.
452  int bottom_extent = 0;
453  for (int x = 0; x <= width; ++x) {
454  if (y_mins[x] == bottom || y_mins[x] == bottom + 1)
455  ++bottom_extent;
456  }
457  // Find the lowest run longer than the bottom extent that is not the bottom.
458  int best_min = box.top();
459  int prev_run = 0;
460  int prev_y = box.top();
461  int prev_prev_y = box.top();
462  for (int x = 0; x < width; x += prev_run) {
463  // Find the length of the current run.
464  int y_at_x = y_mins[x];
465  int run = 1;
466  while (x + run <= width && y_mins[x + run] == y_at_x) ++run;
467  if (y_at_x > bottom + 1) {
468  // Possible contender.
469  int total_run = run;
470  // Find extent of current value or +1 to the right of x.
471  while (x + total_run <= width &&
472  (y_mins[x + total_run] == y_at_x ||
473  y_mins[x + total_run] == y_at_x + 1)) ++total_run;
474  // At least one end has to be higher so it is not a local max.
475  if (prev_prev_y > y_at_x + 1 || x + total_run > width ||
476  y_mins[x + total_run] > y_at_x + 1) {
477  // If the prev_run is at y + 1, then we can add that too. There cannot
478  // be a suitable run at y before that or we would have found it already.

◆ FakeBlob()

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

Definition at line 236 of file stepblob.cpp.

◆ move()

void C_BLOB::move ( const ICOORD  vec)

Definition at line 344 of file stepblob.cpp.

◆ operator=()

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

Definition at line 111 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;

◆ out_list()

C_OUTLINE_LIST* C_BLOB::out_list ( )
inline

Definition at line 69 of file stepblob.h.

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

◆ outer_area()

int32_t C_BLOB::outer_area ( )

Definition at line 303 of file stepblob.cpp.

312  { //area
313  C_OUTLINE *outline; //current outline
314  C_OUTLINE_IT it = &outlines; //outlines of blob

◆ perimeter()

int32_t C_BLOB::perimeter ( )

Definition at line 284 of file stepblob.cpp.

292  {
293  C_OUTLINE *outline; // current outline
294  C_OUTLINE_IT it = &outlines; // outlines of blob
295  int32_t total; // total perimeter

◆ plot()

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

Definition at line 523 of file stepblob.cpp.

◆ plot_normed()

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

Definition at line 531 of file stepblob.cpp.

◆ render()

Pix * C_BLOB::render ( )

Definition at line 501 of file stepblob.cpp.

504  {
505  C_OUTLINE_IT it(list);
506  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {

◆ render_outline()

Pix * C_BLOB::render_outline ( )

Definition at line 510 of file stepblob.cpp.

513  {
514  TBOX box = bounding_box();
515  Pix* pix = pixCreate(box.width(), box.height(), 1);

◆ rotate()

void C_BLOB::rotate ( const FCOORD rotation)

Definition at line 379 of file stepblob.cpp.

◆ SortByXMiddle()

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

Definition at line 124 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();

The documentation for this class was generated from the following files:
C_BLOB::bounding_box
TBOX bounding_box() const
Definition: stepblob.cpp:247
C_BLOB::perimeter
int32_t perimeter()
Definition: stepblob.cpp:284
C_BLOB::C_BLOB
C_BLOB()=default
C_OUTLINE::set_flag
void set_flag(C_OUTLINE_FLAGS mask, bool value)
Definition: coutln.h:101
ICOORD
integer coordinate
Definition: points.h:30
TBOX::top
int16_t top() const
Definition: rect.h:57
ICOORD::x
int16_t x() const
access function
Definition: points.h:51
C_BLOB
Definition: stepblob.h:36
C_OUTLINE
Definition: coutln.h:71
TBOX::height
int16_t height() const
Definition: rect.h:107
COUT_INVERSE
Definition: coutln.h:41
C_OUTLINE::IsLegallyNested
bool IsLegallyNested() const
Definition: coutln.cpp:604
TBOX::x_middle
int x_middle() const
Definition: rect.h:84
TBOX::width
int16_t width() const
Definition: rect.h:114
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
GenericVector< int >
C_OUTLINE::reverse
void reverse()
Definition: coutln.cpp:565
TBOX::left
int16_t left() const
Definition: rect.h:71
C_OUTLINE::deep_copy
static C_OUTLINE * deep_copy(const C_OUTLINE *src)
Definition: coutln.h:260
GenericVector::init_to_size
void init_to_size(int size, const T &t)
Definition: genericvector.h:706
C_OUTLINE::turn_direction
int16_t turn_direction() const
Definition: coutln.cpp:537
C_OUTLINE::pathlength
int32_t pathlength() const
Definition: coutln.h:134
C_OUTLINE::step
ICOORD step(int index) const
Definition: coutln.h:143
C_OUTLINE::child
C_OUTLINE_LIST * child()
Definition: coutln.h:107
kMaxPerimeterWidthRatio
const double kMaxPerimeterWidthRatio
Definition: stepblob.cpp:31
C_OUTLINE::start_pos
const ICOORD & start_pos() const
Definition: coutln.h:147
ICOORD::y
int16_t y() const
access_function
Definition: points.h:55
TBOX
Definition: rect.h:33