tesseract  4.00.00dev
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(NULL), point2(NULL) {}
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 52 of file split.cpp.

52  {
53  return TBOX(
56 }
TPOINT pos
Definition: blobs.h:163
EDGEPT * point2
Definition: split.h:104
inT16 x
Definition: blobs.h:71
#define MAX(x, y)
Definition: ndminx.h:24
inT16 y
Definition: blobs.h:72
Definition: rect.h:30
#define MIN(x, y)
Definition: ndminx.h:28
EDGEPT * point1
Definition: split.h:103

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

◆ 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:163
EDGEPT * point2
Definition: split.h:104
bool Contains(const TPOINT &pt) const
Definition: blobs.h:234
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 89 of file split.cpp.

91  {
92  TBOX box1 = Box12();
93  TBOX box2 = Box21();
94  int min_left = MIN(box1.left(), box2.left());
95  int max_right = MAX(box1.right(), box2.right());
96  if (xmin < min_left && xmax > max_right) return kBadPriority;
97 
98  float grade = 0.0f;
99  // grade_overlap.
100  int width1 = box1.width();
101  int width2 = box2.width();
102  int min_width = MIN(width1, width2);
103  int overlap = -box1.x_gap(box2);
104  if (overlap == min_width) {
105  grade += 100.0f; // Total overlap.
106  } else {
107  if (2 * overlap > min_width) overlap += 2 * overlap - min_width;
108  if (overlap > 0) grade += overlap_knob * overlap;
109  }
110  // grade_center_of_blob.
111  if (width1 <= centered_maxwidth || width2 <= centered_maxwidth) {
112  grade += MIN(kCenterGradeCap, center_knob * abs(width1 - width2));
113  }
114  // grade_width_change.
115  float width_change_grade = 20 - (max_right - min_left - MAX(width1, width2));
116  if (width_change_grade > 0.0f)
117  grade += width_change_grade * width_change_knob;
118  return grade;
119 }
const int kCenterGradeCap
Definition: split.cpp:45
inT16 left() const
Definition: rect.h:68
TBOX Box21() const
Definition: split.h:46
#define MAX(x, y)
Definition: ndminx.h:24
Definition: rect.h:30
#define MIN(x, y)
Definition: ndminx.h:28
inT16 right() const
Definition: rect.h:75
inT16 width() const
Definition: rect.h:111
TBOX Box12() const
Definition: split.h:44
const double kBadPriority
Definition: split.cpp:47
int x_gap(const TBOX &box) const
Definition: rect.h:217

◆ Hide()

void SPLIT::Hide ( ) const

Definition at line 59 of file split.cpp.

59  {
60  EDGEPT* edgept = point1;
61  do {
62  edgept->Hide();
63  edgept = edgept->next;
64  } while (!edgept->EqualPos(*point2) && edgept != point1);
65  edgept = point2;
66  do {
67  edgept->Hide();
68  edgept = edgept->next;
69  } while (!edgept->EqualPos(*point1) && edgept != point2);
70 }
void Hide()
Definition: blobs.h:147
EDGEPT * point2
Definition: split.h:104
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:105
EDGEPT * point1
Definition: split.h:103

◆ IsHealthy()

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

Definition at line 123 of file split.cpp.

123  {
124  return !IsLittleChunk(min_points, min_area) &&
126 }
TPOINT pos
Definition: blobs.h:163
bool SegmentCrossesOutline(const TPOINT &pt1, const TPOINT &pt2) const
Definition: blobs.h:316
EDGEPT * point2
Definition: split.h:104
bool IsLittleChunk(int min_points, int min_area) const
Definition: split.cpp:130
EDGEPT * point1
Definition: split.h:103

◆ IsLittleChunk()

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

Definition at line 130 of file split.cpp.

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

◆ Mark()

void SPLIT::Mark ( ScrollView window) const

Definition at line 234 of file split.cpp.

234  {
235  window->Pen(ScrollView::GREEN);
236  window->Line(point1->pos.x, point1->pos.y, point2->pos.x, point2->pos.y);
237  window->UpdateWindow();
238 }
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:538
TPOINT pos
Definition: blobs.h:163
void UpdateWindow()
Definition: scrollview.cpp:710
EDGEPT * point2
Definition: split.h:104
inT16 x
Definition: blobs.h:71
inT16 y
Definition: blobs.h:72
EDGEPT * point1
Definition: split.h:103
void Pen(Color color)
Definition: scrollview.cpp:726

◆ Print()

void SPLIT::Print ( ) const

Definition at line 227 of file split.cpp.

227  {
228  tprintf("(%d,%d)--(%d,%d)", point1->pos.x, point1->pos.y, point2->pos.x,
229  point2->pos.y);
230 }
TPOINT pos
Definition: blobs.h:163
#define tprintf(...)
Definition: tprintf.h:31
EDGEPT * point2
Definition: split.h:104
inT16 x
Definition: blobs.h:71
inT16 y
Definition: blobs.h:72
EDGEPT * point1
Definition: split.h:103

◆ Reveal()

void SPLIT::Reveal ( ) const

Definition at line 73 of file split.cpp.

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

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

◆ SplitOutline()

void SPLIT::SplitOutline ( ) const

Definition at line 262 of file split.cpp.

262  {
263  EDGEPT* temp2 = point2->next;
264  EDGEPT* temp1 = point1->next;
265  /* Create two new points */
266  EDGEPT* new_point1 = make_edgept(point1->pos.x, point1->pos.y, temp1, point2);
267  EDGEPT* new_point2 = make_edgept(point2->pos.x, point2->pos.y, temp2, point1);
268  // point1 and 2 are now cross-over points, so they must have NULL
269  // src_outlines and give their src_outline information their new
270  // replacements.
271  new_point1->src_outline = point1->src_outline;
272  new_point1->start_step = point1->start_step;
273  new_point1->step_count = point1->step_count;
274  new_point2->src_outline = point2->src_outline;
275  new_point2->start_step = point2->start_step;
276  new_point2->step_count = point2->step_count;
277  point1->src_outline = NULL;
278  point1->start_step = 0;
279  point1->step_count = 0;
280  point2->src_outline = NULL;
281  point2->start_step = 0;
282  point2->step_count = 0;
283 }
int start_step
Definition: blobs.h:173
EDGEPT * make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:147
TPOINT pos
Definition: blobs.h:163
C_OUTLINE * src_outline
Definition: blobs.h:171
EDGEPT * point2
Definition: split.h:104
inT16 x
Definition: blobs.h:71
int step_count
Definition: blobs.h:174
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72
EDGEPT * point1
Definition: split.h:103

◆ SplitOutlineList()

void SPLIT::SplitOutlineList ( TESSLINE outlines) const

Definition at line 243 of file split.cpp.

243  {
244  SplitOutline();
245  while (outlines->next != NULL) outlines = outlines->next;
246 
247  outlines->next = new TESSLINE;
248  outlines->next->loop = point1;
249  outlines->next->ComputeBoundingBox();
250 
251  outlines = outlines->next;
252 
253  outlines->next = new TESSLINE;
254  outlines->next->loop = point2;
255  outlines->next->ComputeBoundingBox();
256 
257  outlines->next->next = NULL;
258 }
TESSLINE * next
Definition: blobs.h:258
EDGEPT * point2
Definition: split.h:104
EDGEPT * loop
Definition: blobs.h:257
void SplitOutline() const
Definition: split.cpp:262
void ComputeBoundingBox()
Definition: blobs.cpp:225
EDGEPT * point1
Definition: split.h:103

◆ UnsplitOutlineList()

void SPLIT::UnsplitOutlineList ( TBLOB blob) const

Definition at line 287 of file split.cpp.

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

◆ UnsplitOutlines()

void SPLIT::UnsplitOutlines ( ) const

Definition at line 303 of file split.cpp.

303  {
304  EDGEPT* tmp1 = point1->next;
305  EDGEPT* tmp2 = point2->next;
306 
307  tmp1->next->prev = point2;
308  tmp2->next->prev = point1;
309 
310  // tmp2 is coincident with point1. point1 takes tmp2's place as tmp2 is
311  // deleted.
312  point1->next = tmp2->next;
313  point1->src_outline = tmp2->src_outline;
314  point1->start_step = tmp2->start_step;
315  point1->step_count = tmp2->step_count;
316  // Likewise point2 takes tmp1's place.
317  point2->next = tmp1->next;
318  point2->src_outline = tmp1->src_outline;
319  point2->start_step = tmp1->start_step;
320  point2->step_count = tmp1->step_count;
321 
322  delete tmp1;
323  delete tmp2;
324 
325  point1->vec.x = point1->next->pos.x - point1->pos.x;
326  point1->vec.y = point1->next->pos.y - point1->pos.y;
327 
328  point2->vec.x = point2->next->pos.x - point2->pos.x;
329  point2->vec.y = point2->next->pos.y - point2->pos.y;
330 }
int start_step
Definition: blobs.h:173
TPOINT pos
Definition: blobs.h:163
C_OUTLINE * src_outline
Definition: blobs.h:171
EDGEPT * prev
Definition: blobs.h:170
EDGEPT * point2
Definition: split.h:104
VECTOR vec
Definition: blobs.h:164
inT16 x
Definition: blobs.h:71
int step_count
Definition: blobs.h:174
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72
EDGEPT * point1
Definition: split.h:103

◆ 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: