tesseract  4.1.1
SPLIT Struct Reference

#include <split.h>

Public Member Functions

 SPLIT ()
 
 SPLIT (EDGEPT *pt1, EDGEPT *pt2)
 
TBOX bounding_box () const
 
TBOX Box12 () const
 
TBOX Box21 () const
 
void Hide () const
 
void Reveal () const
 
bool UsesPoint (const EDGEPT *point) const
 
bool SharesPosition (const SPLIT &other) const
 
bool ContainedByBlob (const TBLOB &blob) const
 
bool ContainedByOutline (const TESSLINE &outline) const
 
float FullPriority (int xmin, int xmax, double overlap_knob, int centered_maxwidth, double center_knob, double width_change_knob) const
 
bool IsHealthy (const TBLOB &blob, int min_points, int min_area) const
 
bool IsLittleChunk (int min_points, int min_area) const
 
void Print () const
 
void Mark (ScrollView *window) const
 
void SplitOutlineList (TESSLINE *outlines) const
 
void SplitOutline () const
 
void UnsplitOutlineList (TBLOB *blob) const
 
void UnsplitOutlines () const
 

Public Attributes

EDGEPTpoint1
 
EDGEPTpoint2
 

Detailed Description

Definition at line 37 of file split.h.

Constructor & Destructor Documentation

◆ SPLIT() [1/2]

SPLIT::SPLIT ( )
inline

Definition at line 38 of file split.h.

38 : point1(nullptr), point2(nullptr) {}
EDGEPT * point1
Definition: split.h:103
EDGEPT * point2
Definition: split.h:104

◆ SPLIT() [2/2]

SPLIT::SPLIT ( EDGEPT pt1,
EDGEPT pt2 
)
inline

Definition at line 39 of file split.h.

39 : point1(pt1), point2(pt2) {}

Member Function Documentation

◆ bounding_box()

TBOX SPLIT::bounding_box ( ) const

Definition at line 44 of file split.cpp.

44  {
45  return TBOX(
46  std::min(point1->pos.x, point2->pos.x), std::min(point1->pos.y, point2->pos.y),
47  std::max(point1->pos.x, point2->pos.x), std::max(point1->pos.y, point2->pos.y));
48 }
int16_t x
Definition: blobs.h:93
int16_t y
Definition: blobs.h:94
TPOINT pos
Definition: blobs.h:186
Definition: rect.h:34

◆ Box12()

TBOX SPLIT::Box12 ( ) const
inline

Definition at line 44 of file split.h.

44 { return point1->SegmentBox(point2); }
TBOX SegmentBox(const EDGEPT *end) const
Definition: blobs.h:131

◆ Box21()

TBOX SPLIT::Box21 ( ) const
inline

Definition at line 46 of file split.h.

46 { return point2->SegmentBox(point1); }

◆ ContainedByBlob()

bool SPLIT::ContainedByBlob ( const TBLOB blob) const
inline

Definition at line 65 of file split.h.

65  {
66  return blob.Contains(point1->pos) && blob.Contains(point2->pos);
67  }
bool Contains(const TPOINT &pt) const
Definition: blobs.h:347

◆ ContainedByOutline()

bool SPLIT::ContainedByOutline ( const TESSLINE outline) const
inline

Definition at line 69 of file split.h.

69  {
70  return outline.Contains(point1->pos) && outline.Contains(point2->pos);
71  }
bool Contains(const TPOINT &pt) const
Definition: blobs.h:257

◆ FullPriority()

float SPLIT::FullPriority ( int  xmin,
int  xmax,
double  overlap_knob,
int  centered_maxwidth,
double  center_knob,
double  width_change_knob 
) const

Definition at line 81 of file split.cpp.

83  {
84  TBOX box1 = Box12();
85  TBOX box2 = Box21();
86  int min_left = std::min(box1.left(), box2.left());
87  int max_right = std::max(box1.right(), box2.right());
88  if (xmin < min_left && xmax > max_right) return kBadPriority;
89 
90  float grade = 0.0f;
91  // grade_overlap.
92  int width1 = box1.width();
93  int width2 = box2.width();
94  int min_width = std::min(width1, width2);
95  int overlap = -box1.x_gap(box2);
96  if (overlap == min_width) {
97  grade += 100.0f; // Total overlap.
98  } else {
99  if (2 * overlap > min_width) overlap += 2 * overlap - min_width;
100  if (overlap > 0) grade += overlap_knob * overlap;
101  }
102  // grade_center_of_blob.
103  if (width1 <= centered_maxwidth || width2 <= centered_maxwidth) {
104  grade += std::min(static_cast<double>(kCenterGradeCap), center_knob * abs(width1 - width2));
105  }
106  // grade_width_change.
107  float width_change_grade = 20 - (max_right - min_left - std::max(width1, width2));
108  if (width_change_grade > 0.0f)
109  grade += width_change_grade * width_change_knob;
110  return grade;
111 }
const double kBadPriority
Definition: split.cpp:39
const int kCenterGradeCap
Definition: split.cpp:37
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int x_gap(const TBOX &box) const
Definition: rect.h:225
int16_t right() const
Definition: rect.h:79
TBOX Box12() const
Definition: split.h:44
TBOX Box21() const
Definition: split.h:46

◆ Hide()

void SPLIT::Hide ( ) const

Definition at line 51 of file split.cpp.

51  {
52  EDGEPT* edgept = point1;
53  do {
54  edgept->Hide();
55  edgept = edgept->next;
56  } while (!edgept->EqualPos(*point2) && edgept != point1);
57  edgept = point2;
58  do {
59  edgept->Hide();
60  edgept = edgept->next;
61  } while (!edgept->EqualPos(*point1) && edgept != point2);
62 }
Definition: blobs.h:99
void Hide()
Definition: blobs.h:170
EDGEPT * next
Definition: blobs.h:192
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:128

◆ IsHealthy()

bool SPLIT::IsHealthy ( const TBLOB blob,
int  min_points,
int  min_area 
) const

Definition at line 115 of file split.cpp.

115  {
116  return !IsLittleChunk(min_points, min_area) &&
118 }
bool SegmentCrossesOutline(const TPOINT &pt1, const TPOINT &pt2) const
Definition: blobs.h:339
bool IsLittleChunk(int min_points, int min_area) const
Definition: split.cpp:122

◆ IsLittleChunk()

bool SPLIT::IsLittleChunk ( int  min_points,
int  min_area 
) const

Definition at line 122 of file split.cpp.

122  {
123  if (point1->ShortNonCircularSegment(min_points, point2) &&
124  point1->SegmentArea(point2) < min_area) {
125  return true;
126  }
127  if (point2->ShortNonCircularSegment(min_points, point1) &&
128  point2->SegmentArea(point1) < min_area) {
129  return true;
130  }
131  return false;
132 }
bool ShortNonCircularSegment(int min_points, const EDGEPT *end) const
Definition: blobs.h:158
int SegmentArea(const EDGEPT *end) const
Definition: blobs.h:145

◆ Mark()

void SPLIT::Mark ( ScrollView window) const

Definition at line 226 of file split.cpp.

226  {
227  window->Pen(ScrollView::GREEN);
228  window->Line(point1->pos.x, point1->pos.y, point2->pos.x, point2->pos.y);
229  window->UpdateWindow();
230 }
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:532
void UpdateWindow()
Definition: scrollview.cpp:704
void Pen(Color color)
Definition: scrollview.cpp:719

◆ Print()

void SPLIT::Print ( ) const

Definition at line 219 of file split.cpp.

219  {
220  tprintf("(%d,%d)--(%d,%d)", point1->pos.x, point1->pos.y, point2->pos.x,
221  point2->pos.y);
222 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35

◆ Reveal()

void SPLIT::Reveal ( ) const

Definition at line 65 of file split.cpp.

65  {
66  EDGEPT* edgept = point1;
67  do {
68  edgept->Reveal();
69  edgept = edgept->next;
70  } while (!edgept->EqualPos(*point2) && edgept != point1);
71  edgept = point2;
72  do {
73  edgept->Reveal();
74  edgept = edgept->next;
75  } while (!edgept->EqualPos(*point1) && edgept != point2);
76 }
void Reveal()
Definition: blobs.h:173

◆ SharesPosition()

bool SPLIT::SharesPosition ( const SPLIT other) const
inline

Definition at line 60 of file split.h.

60  {
61  return point1->EqualPos(*other.point1) || point1->EqualPos(*other.point2) ||
62  point2->EqualPos(*other.point1) || point2->EqualPos(*other.point2);
63  }

◆ SplitOutline()

void SPLIT::SplitOutline ( ) const

Definition at line 254 of file split.cpp.

254  {
255  EDGEPT* temp2 = point2->next;
256  EDGEPT* temp1 = point1->next;
257  /* Create two new points */
258  EDGEPT* new_point1 = make_edgept(point1->pos.x, point1->pos.y, temp1, point2);
259  EDGEPT* new_point2 = make_edgept(point2->pos.x, point2->pos.y, temp2, point1);
260  // point1 and 2 are now cross-over points, so they must have nullptr
261  // src_outlines and give their src_outline information their new
262  // replacements.
263  new_point1->src_outline = point1->src_outline;
264  new_point1->start_step = point1->start_step;
265  new_point1->step_count = point1->step_count;
266  new_point2->src_outline = point2->src_outline;
267  new_point2->start_step = point2->start_step;
268  new_point2->step_count = point2->step_count;
269  point1->src_outline = nullptr;
270  point1->start_step = 0;
271  point1->step_count = 0;
272  point2->src_outline = nullptr;
273  point2->start_step = 0;
274  point2->step_count = 0;
275 }
EDGEPT * make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:139
int start_step
Definition: blobs.h:196
int step_count
Definition: blobs.h:197
C_OUTLINE * src_outline
Definition: blobs.h:194

◆ SplitOutlineList()

void SPLIT::SplitOutlineList ( TESSLINE outlines) const

Definition at line 235 of file split.cpp.

235  {
236  SplitOutline();
237  while (outlines->next != nullptr) outlines = outlines->next;
238 
239  outlines->next = new TESSLINE;
240  outlines->next->loop = point1;
241  outlines->next->ComputeBoundingBox();
242 
243  outlines = outlines->next;
244 
245  outlines->next = new TESSLINE;
246  outlines->next->loop = point2;
247  outlines->next->ComputeBoundingBox();
248 
249  outlines->next->next = nullptr;
250 }
EDGEPT * loop
Definition: blobs.h:280
TESSLINE * next
Definition: blobs.h:281
void ComputeBoundingBox()
Definition: blobs.cpp:213
void SplitOutline() const
Definition: split.cpp:254

◆ UnsplitOutlineList()

void SPLIT::UnsplitOutlineList ( TBLOB blob) const

Definition at line 279 of file split.cpp.

279  {
280  /* Modify edge points */
281  UnsplitOutlines();
282 
283  auto* outline1 = new TESSLINE;
284  outline1->next = blob->outlines;
285  blob->outlines = outline1;
286  outline1->loop = point1;
287 
288  auto* outline2 = new TESSLINE;
289  outline2->next = blob->outlines;
290  blob->outlines = outline2;
291  outline2->loop = point2;
292 }
TESSLINE * outlines
Definition: blobs.h:400
void UnsplitOutlines() const
Definition: split.cpp:295

◆ UnsplitOutlines()

void SPLIT::UnsplitOutlines ( ) const

Definition at line 295 of file split.cpp.

295  {
296  EDGEPT* tmp1 = point1->next;
297  EDGEPT* tmp2 = point2->next;
298 
299  tmp1->next->prev = point2;
300  tmp2->next->prev = point1;
301 
302  // tmp2 is coincident with point1. point1 takes tmp2's place as tmp2 is
303  // deleted.
304  point1->next = tmp2->next;
305  point1->src_outline = tmp2->src_outline;
306  point1->start_step = tmp2->start_step;
307  point1->step_count = tmp2->step_count;
308  // Likewise point2 takes tmp1's place.
309  point2->next = tmp1->next;
310  point2->src_outline = tmp1->src_outline;
311  point2->start_step = tmp1->start_step;
312  point2->step_count = tmp1->step_count;
313 
314  delete tmp1;
315  delete tmp2;
316 
317  point1->vec.x = point1->next->pos.x - point1->pos.x;
318  point1->vec.y = point1->next->pos.y - point1->pos.y;
319 
320  point2->vec.x = point2->next->pos.x - point2->pos.x;
321  point2->vec.y = point2->next->pos.y - point2->pos.y;
322 }
VECTOR vec
Definition: blobs.h:187
EDGEPT * prev
Definition: blobs.h:193

◆ UsesPoint()

bool SPLIT::UsesPoint ( const EDGEPT point) const
inline

Definition at line 56 of file split.h.

56  {
57  return point1 == point || point2 == point;
58  }

Member Data Documentation

◆ point1

EDGEPT* SPLIT::point1

Definition at line 103 of file split.h.

◆ point2

EDGEPT* SPLIT::point2

Definition at line 104 of file split.h.


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