tesseract v5.3.3.20231005
tesseract::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 33 of file split.h.

Constructor & Destructor Documentation

◆ SPLIT() [1/2]

tesseract::SPLIT::SPLIT ( )
inline

Definition at line 34 of file split.h.

34: point1(nullptr), point2(nullptr) {}
EDGEPT * point2
Definition: split.h:107
EDGEPT * point1
Definition: split.h:106

◆ SPLIT() [2/2]

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

Definition at line 35 of file split.h.

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

Member Function Documentation

◆ bounding_box()

TBOX tesseract::SPLIT::bounding_box ( ) const
inline

Definition at line 38 of file split.h.

38 {
39 return TBOX(std::min(point1->pos.x, point2->pos.x), std::min(point1->pos.y, point2->pos.y),
40 std::max(point1->pos.x, point2->pos.x), std::max(point1->pos.y, point2->pos.y));
41 }
@ TBOX
TDimension x
Definition: blobs.h:89
TDimension y
Definition: blobs.h:90
TPOINT pos
Definition: blobs.h:194

◆ Box12()

TBOX tesseract::SPLIT::Box12 ( ) const
inline

Definition at line 44 of file split.h.

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

◆ Box21()

TBOX tesseract::SPLIT::Box21 ( ) const
inline

Definition at line 48 of file split.h.

48 {
49 return point2->SegmentBox(point1);
50 }

◆ ContainedByBlob()

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

Definition at line 69 of file split.h.

69 {
70 return blob.Contains(point1->pos) && blob.Contains(point2->pos);
71 }

◆ ContainedByOutline()

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

Definition at line 73 of file split.h.

73 {
74 return outline.Contains(point1->pos) && outline.Contains(point2->pos);
75 }

◆ FullPriority()

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

Definition at line 74 of file split.cpp.

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

◆ Hide()

void tesseract::SPLIT::Hide ( ) const

Definition at line 44 of file split.cpp.

44 {
45 EDGEPT *edgept = point1;
46 do {
47 edgept->Hide();
48 edgept = edgept->next;
49 } while (!edgept->EqualPos(*point2) && edgept != point1);
50 edgept = point2;
51 do {
52 edgept->Hide();
53 edgept = edgept->next;
54 } while (!edgept->EqualPos(*point1) && edgept != point2);
55}
void Hide()
Definition: blobs.h:178

◆ IsHealthy()

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

Definition at line 114 of file split.cpp.

114 {
115 return !IsLittleChunk(min_points, min_area) &&
116 !blob.SegmentCrossesOutline(point1->pos, point2->pos);
117}
bool IsLittleChunk(int min_points, int min_area) const
Definition: split.cpp:121

◆ IsLittleChunk()

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

Definition at line 121 of file split.cpp.

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

◆ Mark()

void tesseract::SPLIT::Mark ( ScrollView window) const

Definition at line 224 of file split.cpp.

224 {
225 window->Pen(ScrollView::GREEN);
226 window->Line(point1->pos.x, point1->pos.y, point2->pos.x, point2->pos.y);
227 window->UpdateWindow();
228}

◆ Print()

void tesseract::SPLIT::Print ( ) const

Definition at line 218 of file split.cpp.

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

◆ Reveal()

void tesseract::SPLIT::Reveal ( ) const

Definition at line 58 of file split.cpp.

58 {
59 EDGEPT *edgept = point1;
60 do {
61 edgept->Reveal();
62 edgept = edgept->next;
63 } while (!edgept->EqualPos(*point2) && edgept != point1);
64 edgept = point2;
65 do {
66 edgept->Reveal();
67 edgept = edgept->next;
68 } while (!edgept->EqualPos(*point1) && edgept != point2);
69}
void Reveal()
Definition: blobs.h:181

◆ SharesPosition()

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

Definition at line 64 of file split.h.

64 {
65 return point1->EqualPos(*other.point1) || point1->EqualPos(*other.point2) ||
66 point2->EqualPos(*other.point1) || point2->EqualPos(*other.point2);
67 }
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:124

◆ SplitOutline()

void tesseract::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(TDimension x, TDimension y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:138
EDGEPT * next
Definition: blobs.h:200
C_OUTLINE * src_outline
Definition: blobs.h:202

◆ SplitOutlineList()

void tesseract::SPLIT::SplitOutlineList ( TESSLINE outlines) const

Definition at line 233 of file split.cpp.

233 {
234 SplitOutline();
235 while (outlines->next != nullptr) {
236 outlines = outlines->next;
237 }
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}
void SplitOutline() const
Definition: split.cpp:254

◆ UnsplitOutlineList()

void tesseract::SPLIT::UnsplitOutlineList ( TBLOB blob) const

Definition at line 279 of file split.cpp.

279 {
280 /* Modify edge points */
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}
void UnsplitOutlines() const
Definition: split.cpp:295

◆ UnsplitOutlines()

void tesseract::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}
EDGEPT * prev
Definition: blobs.h:201
VECTOR vec
Definition: blobs.h:195

◆ UsesPoint()

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

Definition at line 60 of file split.h.

60 {
61 return point1 == point || point2 == point;
62 }

Member Data Documentation

◆ point1

EDGEPT* tesseract::SPLIT::point1

Definition at line 106 of file split.h.

◆ point2

EDGEPT* tesseract::SPLIT::point2

Definition at line 107 of file split.h.


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