tesseract  4.0.0-1-g2a2b
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 145 of file split.cpp.

145  {
146  EDGEPT *this_edgept;
147  /* Create point */
148  this_edgept = new EDGEPT;
149  this_edgept->pos.x = x;
150  this_edgept->pos.y = y;
151  // Now deal with the src_outline steps.
152  C_OUTLINE* prev_ol = prev->src_outline;
153  if (prev_ol != nullptr && prev->next == next) {
154  // Compute the fraction of the segment that is being cut.
155  FCOORD segment_vec(next->pos.x - prev->pos.x, next->pos.y - prev->pos.y);
156  FCOORD target_vec(x - prev->pos.x, y - prev->pos.y);
157  double cut_fraction = target_vec.length() / segment_vec.length();
158  // Get the start and end at the step level.
159  ICOORD step_start = prev_ol->position_at_index(prev->start_step);
160  int end_step = prev->start_step + prev->step_count;
161  int step_length = prev_ol->pathlength();
162  ICOORD step_end = prev_ol->position_at_index(end_step % step_length);
163  ICOORD step_vec = step_end - step_start;
164  double target_length = step_vec.length() * cut_fraction;
165  // Find the point on the segment that gives the length nearest to target.
166  int best_step = prev->start_step;
167  ICOORD total_step(0, 0);
168  double best_dist = target_length;
169  for (int s = prev->start_step; s < end_step; ++s) {
170  total_step += prev_ol->step(s % step_length);
171  double dist = fabs(target_length - total_step.length());
172  if (dist < best_dist) {
173  best_dist = dist;
174  best_step = s + 1;
175  }
176  }
177  // The new point is an intermediate point.
178  this_edgept->src_outline = prev_ol;
179  this_edgept->step_count = end_step - best_step;
180  this_edgept->start_step = best_step % step_length;
181  prev->step_count = best_step - prev->start_step;
182  } else {
183  // The new point is poly only.
184  this_edgept->src_outline = nullptr;
185  this_edgept->step_count = 0;
186  this_edgept->start_step = 0;
187  }
188  /* Hook it up */
189  this_edgept->next = next;
190  this_edgept->prev = prev;
191  prev->next = this_edgept;
192  next->prev = this_edgept;
193  /* Set up vec entries */
194  this_edgept->vec.x = this_edgept->next->pos.x - x;
195  this_edgept->vec.y = this_edgept->next->pos.y - y;
196  this_edgept->prev->vec.x = x - this_edgept->prev->pos.x;
197  this_edgept->prev->vec.y = y - this_edgept->prev->pos.y;
198  return this_edgept;
199 }
int step_count
Definition: blobs.h:181
TPOINT pos
Definition: blobs.h:170
int start_step
Definition: blobs.h:180
integer coordinate
Definition: points.h:32
ICOORD position_at_index(int index) const
Definition: coutln.h:153
VECTOR vec
Definition: blobs.h:171
Definition: blobs.h:83
int32_t pathlength() const
Definition: coutln.h:135
EDGEPT * prev
Definition: blobs.h:177
int16_t x
Definition: blobs.h:78
C_OUTLINE * src_outline
Definition: blobs.h:178
Definition: points.h:189
float length() const
find length
Definition: points.h:79
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176
ICOORD step(int index) const
Definition: coutln.h:144

◆ remove_edgept()

void remove_edgept ( EDGEPT point)

Definition at line 206 of file split.cpp.

206  {
207  EDGEPT *prev = point->prev;
208  EDGEPT *next = point->next;
209  // Add point's steps onto prev's steps if they are from the same outline.
210  if (prev->src_outline == point->src_outline && prev->src_outline != nullptr) {
211  prev->step_count += point->step_count;
212  }
213  prev->next = next;
214  next->prev = prev;
215  prev->vec.x = next->pos.x - prev->pos.x;
216  prev->vec.y = next->pos.y - prev->pos.y;
217  delete point;
218 }
int step_count
Definition: blobs.h:181
TPOINT pos
Definition: blobs.h:170
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

Variable Documentation

◆ kBadPriority

const double kBadPriority = 999.0

Definition at line 45 of file split.cpp.

◆ kCenterGradeCap

const int kCenterGradeCap = 25

Definition at line 43 of file split.cpp.

◆ wordrec_display_splits

bool wordrec_display_splits = 0

"Display splits"

Definition at line 47 of file split.cpp.