tesseract 4.1.1
Loading...
Searching...
No Matches
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 163 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();
166 // Position this outline in appropriate position in the hierarchy.
167 position_outline(outline, &outlines);
168 }
170}
void CheckInverseFlagAndDirection()
Definition: stepblob.cpp:224

◆ C_BLOB() [3/3]

C_BLOB::C_BLOB ( C_OUTLINE outline)
explicit

Definition at line 174 of file stepblob.cpp.

174 {
175 C_OUTLINE_IT it(&outlines);
176 it.add_to_end(outline);
177}

Member Function Documentation

◆ area()

int32_t C_BLOB::area ( )

Definition at line 273 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
278 total = 0;
279 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
280 outline = it.data ();
281 total += outline->area ();
282 }
283 return total;
284}
int32_t area() const
Definition: coutln.cpp:255

◆ bounding_box()

TBOX C_BLOB::bounding_box ( ) const

Definition at line 253 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
259 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
260 outline = it.data ();
261 box += outline->bounding_box ();
262 }
263 return box;
264}
const TBOX & bounding_box() const
Definition: coutln.h:113
Definition: rect.h:34

◆ CheckInverseFlagAndDirection()

void C_BLOB::CheckInverseFlagAndDirection ( )

Definition at line 224 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);
232 } else {
233 outline->set_flag(COUT_INVERSE, false);
234 }
235 }
236}
@ COUT_INVERSE
Definition: coutln.h:42
C_OUTLINE_LIST * child()
Definition: coutln.h:108
void reverse()
Definition: coutln.cpp:565
void set_flag(C_OUTLINE_FLAGS mask, bool value)
Definition: coutln.h:102
int16_t turn_direction() const
Definition: coutln.cpp:537

◆ ComputeEdgeOffsets()

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

Definition at line 413 of file stepblob.cpp.

413 {
414 ComputeEdgeOffsetsOutlineList(threshold, pix, &outlines);
415}

◆ 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 189 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)
215 bad_blobs_it->add_after_then_move(blob);
216 else
217 good_blobs_it->add_after_then_move(blob);
218 }
219}
bool IsLegallyNested() const
Definition: coutln.cpp:604
C_BLOB()=default

◆ count_transitions()

int32_t C_BLOB::count_transitions ( int32_t  threshold)

Definition at line 333 of file stepblob.cpp.

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

◆ deep_copy()

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

Definition at line 119 of file stepblob.h.

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

◆ EstimateBaselinePosition()

int16_t C_BLOB::EstimateBaselinePosition ( )

Definition at line 431 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.
479 if (prev_run > 0 && prev_y == y_at_x + 1) total_run += prev_run;
480 if (total_run > bottom_extent && y_at_x < best_min) {
481 best_min = y_at_x;
482 }
483 }
484 }
485 prev_run = run;
486 prev_prev_y = prev_y;
487 prev_y = y_at_x;
488 }
489 return best_min == box.top() ? bottom : best_min;
490}
const double kMaxPerimeterWidthRatio
Definition: stepblob.cpp:32
void init_to_size(int size, const T &t)
ICOORD step(int index) const
Definition: coutln.h:144
const ICOORD & start_pos() const
Definition: coutln.h:148
int32_t pathlength() const
Definition: coutln.h:135
integer coordinate
Definition: points.h:32
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
int16_t top() const
Definition: rect.h:58
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t bottom() const
Definition: rect.h:65
TBOX bounding_box() const
Definition: stepblob.cpp:253
int32_t perimeter()
Definition: stepblob.cpp:292

◆ FakeBlob()

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

Definition at line 241 of file stepblob.cpp.

241 {
242 C_OUTLINE_LIST outlines;
243 C_OUTLINE::FakeOutline(box, &outlines);
244 return new C_BLOB(&outlines);
245}
static void FakeOutline(const TBOX &box, C_OUTLINE_LIST *outlines)
Definition: coutln.cpp:239

◆ move()

void C_BLOB::move ( const ICOORD  vec)

Definition at line 355 of file stepblob.cpp.

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

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

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

◆ perimeter()

int32_t C_BLOB::perimeter ( )

Definition at line 292 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
296
297 total = 0;
298 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
299 outline = it.data();
300 total += outline->perimeter();
301 }
302 return total;
303}
int32_t perimeter() const
Definition: coutln.cpp:289

◆ plot()

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

Definition at line 536 of file stepblob.cpp.

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

◆ plot_normed()

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

Definition at line 544 of file stepblob.cpp.

547 {
548 plot_normed_outline_list(denorm, &outlines, blob_colour, child_colour,
549 window);
550}

◆ render()

Pix * C_BLOB::render ( )

Definition at line 513 of file stepblob.cpp.

513 {
514 TBOX box = bounding_box();
515 Pix* pix = pixCreate(box.width(), box.height(), 1);
516 render_outline_list(&outlines, box.left(), box.top(), pix);
517 return pix;
518}
int16_t height() const
Definition: rect.h:108

◆ render_outline()

Pix * C_BLOB::render_outline ( )

Definition at line 522 of file stepblob.cpp.

522 {
523 TBOX box = bounding_box();
524 Pix* pix = pixCreate(box.width(), box.height(), 1);
525 render_outline_list_outline(&outlines, box.left(), box.top(), pix);
526 return pix;
527}

◆ rotate()

void C_BLOB::rotate ( const FCOORD rotation)

Definition at line 391 of file stepblob.cpp.

391 {
392 RotateOutlineList(rotation, &outlines);
393}

◆ 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 }
int x_middle() const
Definition: rect.h:85

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