tesseract  4.0.0-1-g2a2b
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 * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103

◆ SPLIT() [2/2]

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

Definition at line 39 of file split.h.

39 : point1(pt1), point2(pt2) {}
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103

Member Function Documentation

◆ bounding_box()

TBOX SPLIT::bounding_box ( ) const

Definition at line 50 of file split.cpp.

50  {
51  return TBOX(
52  std::min(point1->pos.x, point2->pos.x), std::min(point1->pos.y, point2->pos.y),
53  std::max(point1->pos.x, point2->pos.x), std::max(point1->pos.y, point2->pos.y));
54 }
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
Definition: rect.h:34
EDGEPT * point1
Definition: split.h:103
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79

◆ 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:115
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103

◆ Box21()

TBOX SPLIT::Box21 ( ) const
inline

Definition at line 46 of file split.h.

46 { return point2->SegmentBox(point1); }
TBOX SegmentBox(const EDGEPT *end) const
Definition: blobs.h:115
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103

◆ 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  }
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
bool Contains(const TPOINT &pt) const
Definition: blobs.h:331

◆ 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  }
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
bool Contains(const TPOINT &pt) const
Definition: blobs.h:241
EDGEPT * point1
Definition: split.h:103

◆ 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 87 of file split.cpp.

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

◆ Hide()

void SPLIT::Hide ( ) const

Definition at line 57 of file split.cpp.

57  {
58  EDGEPT* edgept = point1;
59  do {
60  edgept->Hide();
61  edgept = edgept->next;
62  } while (!edgept->EqualPos(*point2) && edgept != point1);
63  edgept = point2;
64  do {
65  edgept->Hide();
66  edgept = edgept->next;
67  } while (!edgept->EqualPos(*point1) && edgept != point2);
68 }
void Hide()
Definition: blobs.h:154
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
Definition: blobs.h:83
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:112
EDGEPT * next
Definition: blobs.h:176

◆ IsHealthy()

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

Definition at line 121 of file split.cpp.

121  {
122  return !IsLittleChunk(min_points, min_area) &&
124 }
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
bool SegmentCrossesOutline(const TPOINT &pt1, const TPOINT &pt2) const
Definition: blobs.h:323
EDGEPT * point1
Definition: split.h:103
bool IsLittleChunk(int min_points, int min_area) const
Definition: split.cpp:128

◆ IsLittleChunk()

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

Definition at line 128 of file split.cpp.

128  {
129  if (point1->ShortNonCircularSegment(min_points, point2) &&
130  point1->SegmentArea(point2) < min_area) {
131  return true;
132  }
133  if (point2->ShortNonCircularSegment(min_points, point1) &&
134  point2->SegmentArea(point1) < min_area) {
135  return true;
136  }
137  return false;
138 }
EDGEPT * point2
Definition: split.h:104
bool ShortNonCircularSegment(int min_points, const EDGEPT *end) const
Definition: blobs.h:142
EDGEPT * point1
Definition: split.h:103
int SegmentArea(const EDGEPT *end) const
Definition: blobs.h:129

◆ Mark()

void SPLIT::Mark ( ScrollView window) const

Definition at line 232 of file split.cpp.

232  {
233  window->Pen(ScrollView::GREEN);
234  window->Line(point1->pos.x, point1->pos.y, point2->pos.x, point2->pos.y);
235  window->UpdateWindow();
236 }
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
int16_t x
Definition: blobs.h:78
void UpdateWindow()
Definition: scrollview.cpp:706
int16_t y
Definition: blobs.h:79
void Pen(Color color)
Definition: scrollview.cpp:722
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:534

◆ Print()

void SPLIT::Print ( ) const

Definition at line 225 of file split.cpp.

225  {
226  tprintf("(%d,%d)--(%d,%d)", point1->pos.x, point1->pos.y, point2->pos.x,
227  point2->pos.y);
228 }
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79

◆ Reveal()

void SPLIT::Reveal ( ) const

Definition at line 71 of file split.cpp.

71  {
72  EDGEPT* edgept = point1;
73  do {
74  edgept->Reveal();
75  edgept = edgept->next;
76  } while (!edgept->EqualPos(*point2) && edgept != point1);
77  edgept = point2;
78  do {
79  edgept->Reveal();
80  edgept = edgept->next;
81  } while (!edgept->EqualPos(*point1) && edgept != point2);
82 }
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
Definition: blobs.h:83
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:112
EDGEPT * next
Definition: blobs.h:176
void Reveal()
Definition: blobs.h:157

◆ 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  }
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:112

◆ SplitOutline()

void SPLIT::SplitOutline ( ) const

Definition at line 260 of file split.cpp.

260  {
261  EDGEPT* temp2 = point2->next;
262  EDGEPT* temp1 = point1->next;
263  /* Create two new points */
264  EDGEPT* new_point1 = make_edgept(point1->pos.x, point1->pos.y, temp1, point2);
265  EDGEPT* new_point2 = make_edgept(point2->pos.x, point2->pos.y, temp2, point1);
266  // point1 and 2 are now cross-over points, so they must have nullptr
267  // src_outlines and give their src_outline information their new
268  // replacements.
269  new_point1->src_outline = point1->src_outline;
270  new_point1->start_step = point1->start_step;
271  new_point1->step_count = point1->step_count;
272  new_point2->src_outline = point2->src_outline;
273  new_point2->start_step = point2->start_step;
274  new_point2->step_count = point2->step_count;
275  point1->src_outline = nullptr;
276  point1->start_step = 0;
277  point1->step_count = 0;
278  point2->src_outline = nullptr;
279  point2->start_step = 0;
280  point2->step_count = 0;
281 }
int step_count
Definition: blobs.h:181
EDGEPT * make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:145
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
int start_step
Definition: blobs.h:180
EDGEPT * point1
Definition: split.h:103
Definition: blobs.h:83
int16_t x
Definition: blobs.h:78
C_OUTLINE * src_outline
Definition: blobs.h:178
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176

◆ SplitOutlineList()

void SPLIT::SplitOutlineList ( TESSLINE outlines) const

Definition at line 241 of file split.cpp.

241  {
242  SplitOutline();
243  while (outlines->next != nullptr) outlines = outlines->next;
244 
245  outlines->next = new TESSLINE;
246  outlines->next->loop = point1;
247  outlines->next->ComputeBoundingBox();
248 
249  outlines = outlines->next;
250 
251  outlines->next = new TESSLINE;
252  outlines->next->loop = point2;
253  outlines->next->ComputeBoundingBox();
254 
255  outlines->next->next = nullptr;
256 }
TESSLINE * next
Definition: blobs.h:265
void ComputeBoundingBox()
Definition: blobs.cpp:223
EDGEPT * point2
Definition: split.h:104
void SplitOutline() const
Definition: split.cpp:260
EDGEPT * point1
Definition: split.h:103
EDGEPT * loop
Definition: blobs.h:264

◆ UnsplitOutlineList()

void SPLIT::UnsplitOutlineList ( TBLOB blob) const

Definition at line 285 of file split.cpp.

285  {
286  /* Modify edge points */
287  UnsplitOutlines();
288 
289  TESSLINE* outline1 = new TESSLINE;
290  outline1->next = blob->outlines;
291  blob->outlines = outline1;
292  outline1->loop = point1;
293 
294  TESSLINE* outline2 = new TESSLINE;
295  outline2->next = blob->outlines;
296  blob->outlines = outline2;
297  outline2->loop = point2;
298 }
void UnsplitOutlines() const
Definition: split.cpp:301
TESSLINE * next
Definition: blobs.h:265
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
EDGEPT * loop
Definition: blobs.h:264
TESSLINE * outlines
Definition: blobs.h:384

◆ UnsplitOutlines()

void SPLIT::UnsplitOutlines ( ) const

Definition at line 301 of file split.cpp.

301  {
302  EDGEPT* tmp1 = point1->next;
303  EDGEPT* tmp2 = point2->next;
304 
305  tmp1->next->prev = point2;
306  tmp2->next->prev = point1;
307 
308  // tmp2 is coincident with point1. point1 takes tmp2's place as tmp2 is
309  // deleted.
310  point1->next = tmp2->next;
311  point1->src_outline = tmp2->src_outline;
312  point1->start_step = tmp2->start_step;
313  point1->step_count = tmp2->step_count;
314  // Likewise point2 takes tmp1's place.
315  point2->next = tmp1->next;
316  point2->src_outline = tmp1->src_outline;
317  point2->start_step = tmp1->start_step;
318  point2->step_count = tmp1->step_count;
319 
320  delete tmp1;
321  delete tmp2;
322 
323  point1->vec.x = point1->next->pos.x - point1->pos.x;
324  point1->vec.y = point1->next->pos.y - point1->pos.y;
325 
326  point2->vec.x = point2->next->pos.x - point2->pos.x;
327  point2->vec.y = point2->next->pos.y - point2->pos.y;
328 }
int step_count
Definition: blobs.h:181
TPOINT pos
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
int start_step
Definition: blobs.h:180
EDGEPT * point1
Definition: split.h:103
VECTOR vec
Definition: blobs.h:171
Definition: blobs.h:83
EDGEPT * prev
Definition: blobs.h:177
int16_t x
Definition: blobs.h:78
C_OUTLINE * src_outline
Definition: blobs.h:178
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176

◆ 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  }
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103

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: