tesseract  5.0.0-alpha-619-ge9db
split.cpp File Reference
#include "split.h"
#include "coutln.h"
#include "tprintf.h"
#include <algorithm>

Go to the source code of this file.

Functions

EDGEPTmake_edgept (int x, int y, EDGEPT *next, EDGEPT *prev)
 
void remove_edgept (EDGEPT *point)
 

Variables

const int kCenterGradeCap = 25
 
const double kBadPriority = 999.0
 
bool wordrec_display_splits = 0
 

Function Documentation

◆ make_edgept()

EDGEPT* make_edgept ( int  x,
int  y,
EDGEPT next,
EDGEPT prev 
)

Definition at line 136 of file split.cpp.

138  {
139  EDGEPT *this_edgept;
140  /* Create point */
141  this_edgept = new EDGEPT;
142  this_edgept->pos.x = x;
143  this_edgept->pos.y = y;
144  // Now deal with the src_outline steps.
145  C_OUTLINE* prev_ol = prev->src_outline;
146  if (prev_ol != nullptr && prev->next == next) {
147  // Compute the fraction of the segment that is being cut.
148  FCOORD segment_vec(next->pos.x - prev->pos.x, next->pos.y - prev->pos.y);
149  FCOORD target_vec(x - prev->pos.x, y - prev->pos.y);
150  double cut_fraction = target_vec.length() / segment_vec.length();
151  // Get the start and end at the step level.
152  ICOORD step_start = prev_ol->position_at_index(prev->start_step);
153  int end_step = prev->start_step + prev->step_count;
154  int step_length = prev_ol->pathlength();
155  ICOORD step_end = prev_ol->position_at_index(end_step % step_length);
156  ICOORD step_vec = step_end - step_start;
157  double target_length = step_vec.length() * cut_fraction;
158  // Find the point on the segment that gives the length nearest to target.
159  int best_step = prev->start_step;
160  ICOORD total_step(0, 0);
161  double best_dist = target_length;
162  for (int s = prev->start_step; s < end_step; ++s) {
163  total_step += prev_ol->step(s % step_length);
164  double dist = fabs(target_length - total_step.length());
165  if (dist < best_dist) {
166  best_dist = dist;
167  best_step = s + 1;
168  }
169  }
170  // The new point is an intermediate point.
171  this_edgept->src_outline = prev_ol;
172  this_edgept->step_count = end_step - best_step;
173  this_edgept->start_step = best_step % step_length;
174  prev->step_count = best_step - prev->start_step;
175  } else {
176  // The new point is poly only.
177  this_edgept->src_outline = nullptr;
178  this_edgept->step_count = 0;
179  this_edgept->start_step = 0;
180  }
181  /* Hook it up */
182  this_edgept->next = next;
183  this_edgept->prev = prev;
184  prev->next = this_edgept;
185  next->prev = this_edgept;
186  /* Set up vec entries */
187  this_edgept->vec.x = this_edgept->next->pos.x - x;
188  this_edgept->vec.y = this_edgept->next->pos.y - y;
189  this_edgept->prev->vec.x = x - this_edgept->prev->pos.x;
190  this_edgept->prev->vec.y = y - this_edgept->prev->pos.y;

◆ remove_edgept()

void remove_edgept ( EDGEPT point)

Definition at line 196 of file split.cpp.

199  {
200  EDGEPT *prev = point->prev;
201  EDGEPT *next = point->next;
202  // Add point's steps onto prev's steps if they are from the same outline.
203  if (prev->src_outline == point->src_outline && prev->src_outline != nullptr) {
204  prev->step_count += point->step_count;
205  }
206  prev->next = next;
207  next->prev = prev;
208  prev->vec.x = next->pos.x - prev->pos.x;

Variable Documentation

◆ kBadPriority

const double kBadPriority = 999.0

Definition at line 37 of file split.cpp.

◆ kCenterGradeCap

const int kCenterGradeCap = 25

Definition at line 35 of file split.cpp.

◆ wordrec_display_splits

bool wordrec_display_splits = 0

"Display splits"

Definition at line 39 of file split.cpp.

EDGEPT::src_outline
C_OUTLINE * src_outline
Definition: blobs.h:192
EDGEPT::step_count
int step_count
Definition: blobs.h:195
ICOORD
integer coordinate
Definition: points.h:30
ICOORD::length
float length() const
find length
Definition: points.h:77
FCOORD
Definition: points.h:187
C_OUTLINE
Definition: coutln.h:71
EDGEPT::prev
EDGEPT * prev
Definition: blobs.h:191
EDGEPT::start_step
int start_step
Definition: blobs.h:194
C_OUTLINE::position_at_index
ICOORD position_at_index(int index) const
Definition: coutln.h:152
TPOINT::x
int16_t x
Definition: blobs.h:91
TPOINT::y
int16_t y
Definition: blobs.h:92
EDGEPT::vec
VECTOR vec
Definition: blobs.h:185
EDGEPT
Definition: blobs.h:97
C_OUTLINE::pathlength
int32_t pathlength() const
Definition: coutln.h:134
C_OUTLINE::step
ICOORD step(int index) const
Definition: coutln.h:143
EDGEPT::pos
TPOINT pos
Definition: blobs.h:184
EDGEPT::next
EDGEPT * next
Definition: blobs.h:190