tesseract  5.0.0-alpha-619-ge9db
FPCUTPT Class Reference

#include <pithsync.h>

Public Member Functions

 FPCUTPT ()=default
 
void setup (FPCUTPT cutpts[], int16_t array_origin, STATS *projection, int16_t zero_count, int16_t pitch, int16_t x, int16_t offset)
 
void assign (FPCUTPT cutpts[], int16_t array_origin, int16_t x, bool faking, bool mid_cut, int16_t offset, STATS *projection, float projection_scale, int16_t zero_count, int16_t pitch, int16_t pitch_error)
 
void assign_cheap (FPCUTPT cutpts[], int16_t array_origin, int16_t x, bool faking, bool mid_cut, int16_t offset, STATS *projection, float projection_scale, int16_t zero_count, int16_t pitch, int16_t pitch_error)
 
int32_t position ()
 
double cost_function ()
 
double squares ()
 
double sum ()
 
FPCUTPTprevious ()
 
int16_t cheap_cuts () const
 
int16_t index () const
 

Public Attributes

bool faked
 
bool terminal
 
int16_t fake_count
 

Detailed Description

Definition at line 27 of file pithsync.h.

Constructor & Destructor Documentation

◆ FPCUTPT()

FPCUTPT::FPCUTPT ( )
default

Member Function Documentation

◆ assign()

void FPCUTPT::assign ( FPCUTPT  cutpts[],
int16_t  array_origin,
int16_t  x,
bool  faking,
bool  mid_cut,
int16_t  offset,
STATS projection,
float  projection_scale,
int16_t  zero_count,
int16_t  pitch,
int16_t  pitch_error 
)

Definition at line 88 of file pithsync.cpp.

103  {
104  int index; //test index
105  int balance_index; //for balance factor
106  int16_t balance_count; //ding factor
107  int16_t r_index; //test cut number
108  FPCUTPT *segpt; //segment point
109  int32_t dist; //from prev segment
110  double sq_dist; //squared distance
111  double mean; //mean pitch
112  double total; //total dists
113  double factor; //cost function
114  //half of pitch
115  int16_t half_pitch = pitch / 2 - 1;
116  uint32_t lead_flag; //new flag
117 
118  if (half_pitch > 31)
119  half_pitch = 31;
120  else if (half_pitch < 0)
121  half_pitch = 0;
122  lead_flag = 1 << half_pitch;
123 
124  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
125  back_balance &= lead_flag + lead_flag - 1;
126  if (projection->pile_count (x) > zero_count)
127  back_balance |= 1;
128  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
129  if (projection->pile_count (x + half_pitch) > zero_count)
130  fwd_balance |= lead_flag;
131 
132  xpos = x;
133  cost = FLT_MAX;
134  pred = nullptr;
135  faked = faking;
136  terminal = false;
137  region_index = 0;
138  fake_count = INT16_MAX;
139  for (index = x - pitch - pitch_error; index <= x - pitch + pitch_error;
140  index++) {
141  if (index >= array_origin) {
142  segpt = &cutpts[index - array_origin];
143  dist = x - segpt->xpos;
144  if (!segpt->terminal && segpt->fake_count < INT16_MAX) {
145  balance_count = 0;
146  if (textord_balance_factor > 0) {
148  lead_flag = back_balance ^ segpt->fwd_balance;
149  balance_count = 0;
150  while (lead_flag != 0) {
151  balance_count++;
152  lead_flag &= lead_flag - 1;
153  }
154  }
155  else {
156  for (balance_index = 0;
157  index + balance_index < x - balance_index;
158  balance_index++)
159  balance_count +=
160  (projection->pile_count (index + balance_index) <=
161  zero_count) ^ (projection->pile_count (x -
162  balance_index)
163  <= zero_count);
164  }
165  balance_count =
166  static_cast<int16_t>(balance_count * textord_balance_factor /
167  projection_scale);
168  }
169  r_index = segpt->region_index + 1;
170  total = segpt->mean_sum + dist;
171  balance_count += offset;
172  sq_dist =
173  dist * dist + segpt->sq_sum + balance_count * balance_count;
174  mean = total / r_index;
175  factor = mean - pitch;
176  factor *= factor;
177  factor += sq_dist / (r_index) - mean * mean;
178  if (factor < cost && segpt->fake_count + faked <= fake_count) {
179  cost = factor; //find least cost
180  pred = segpt; //save path
181  mean_sum = total;
182  sq_sum = sq_dist;
183  fake_count = segpt->fake_count + faked;
184  mid_cuts = segpt->mid_cuts + mid_cut;
185  region_index = r_index;
186  }
187  }

◆ assign_cheap()

void FPCUTPT::assign_cheap ( FPCUTPT  cutpts[],
int16_t  array_origin,
int16_t  x,
bool  faking,
bool  mid_cut,
int16_t  offset,
STATS projection,
float  projection_scale,
int16_t  zero_count,
int16_t  pitch,
int16_t  pitch_error 
)

Definition at line 195 of file pithsync.cpp.

211  {
212  int index; //test index
213  int16_t balance_count; //ding factor
214  int16_t r_index; //test cut number
215  FPCUTPT *segpt; //segment point
216  int32_t dist; //from prev segment
217  double sq_dist; //squared distance
218  double mean; //mean pitch
219  double total; //total dists
220  double factor; //cost function
221  //half of pitch
222  int16_t half_pitch = pitch / 2 - 1;
223  uint32_t lead_flag; //new flag
224 
225  if (half_pitch > 31)
226  half_pitch = 31;
227  else if (half_pitch < 0)
228  half_pitch = 0;
229  lead_flag = 1 << half_pitch;
230 
231  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
232  back_balance &= lead_flag + lead_flag - 1;
233  if (projection->pile_count (x) > zero_count)
234  back_balance |= 1;
235  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
236  if (projection->pile_count (x + half_pitch) > zero_count)
237  fwd_balance |= lead_flag;
238 
239  xpos = x;
240  cost = FLT_MAX;
241  pred = nullptr;
242  faked = faking;
243  terminal = false;
244  region_index = 0;
245  fake_count = INT16_MAX;
246  index = x - pitch;
247  if (index >= array_origin) {
248  segpt = &cutpts[index - array_origin];
249  dist = x - segpt->xpos;
250  if (!segpt->terminal && segpt->fake_count < INT16_MAX) {
251  balance_count = 0;
252  if (textord_balance_factor > 0) {
253  lead_flag = back_balance ^ segpt->fwd_balance;
254  balance_count = 0;
255  while (lead_flag != 0) {
256  balance_count++;
257  lead_flag &= lead_flag - 1;
258  }
259  balance_count = static_cast<int16_t>(balance_count * textord_balance_factor
260  / projection_scale);
261  }
262  r_index = segpt->region_index + 1;
263  total = segpt->mean_sum + dist;
264  balance_count += offset;
265  sq_dist =
266  dist * dist + segpt->sq_sum + balance_count * balance_count;
267  mean = total / r_index;
268  factor = mean - pitch;
269  factor *= factor;
270  factor += sq_dist / (r_index) - mean * mean;
271  cost = factor; //find least cost
272  pred = segpt; //save path
273  mean_sum = total;
274  sq_sum = sq_dist;
275  fake_count = segpt->fake_count + faked;
276  mid_cuts = segpt->mid_cuts + mid_cut;

◆ cheap_cuts()

int16_t FPCUTPT::cheap_cuts ( ) const
inline

Definition at line 81 of file pithsync.h.

82  { //no of mi cuts
83  return mid_cuts;

◆ cost_function()

double FPCUTPT::cost_function ( )
inline

Definition at line 69 of file pithsync.h.

70  {
71  return cost;

◆ index()

int16_t FPCUTPT::index ( ) const
inline

Definition at line 84 of file pithsync.h.

85  {
86  return region_index;

◆ position()

int32_t FPCUTPT::position ( )
inline

Definition at line 66 of file pithsync.h.

67  { // access func
68  return xpos;

◆ previous()

FPCUTPT* FPCUTPT::previous ( )
inline

Definition at line 78 of file pithsync.h.

79  {
80  return pred;

◆ setup()

void FPCUTPT::setup ( FPCUTPT  cutpts[],
int16_t  array_origin,
STATS projection,
int16_t  zero_count,
int16_t  pitch,
int16_t  x,
int16_t  offset 
)

Definition at line 32 of file pithsync.cpp.

42  {
43  //half of pitch
44  int16_t half_pitch = pitch / 2 - 1;
45  uint32_t lead_flag; //new flag
46  int32_t ind; //current position
47 
48  if (half_pitch > 31)
49  half_pitch = 31;
50  else if (half_pitch < 0)
51  half_pitch = 0;
52  lead_flag = 1 << half_pitch;
53 
54  pred = nullptr;
55  mean_sum = 0;
56  sq_sum = offset * offset;
57  cost = sq_sum;
58  faked = false;
59  terminal = false;
60  fake_count = 0;
61  xpos = x;
62  region_index = 0;
63  mid_cuts = 0;
64  if (x == array_origin) {
65  back_balance = 0;
66  fwd_balance = 0;
67  for (ind = 0; ind <= half_pitch; ind++) {
68  fwd_balance >>= 1;
69  if (projection->pile_count (ind) > zero_count)
70  fwd_balance |= lead_flag;
71  }
72  }
73  else {
74  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
75  back_balance &= lead_flag + lead_flag - 1;
76  if (projection->pile_count (x) > zero_count)
77  back_balance |= 1;
78  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
79  if (projection->pile_count (x + half_pitch) > zero_count)
80  fwd_balance |= lead_flag;

◆ squares()

double FPCUTPT::squares ( )
inline

Definition at line 72 of file pithsync.h.

73  {
74  return sq_sum;

◆ sum()

double FPCUTPT::sum ( )
inline

Definition at line 75 of file pithsync.h.

76  {
77  return mean_sum;

Member Data Documentation

◆ fake_count

int16_t FPCUTPT::fake_count

Definition at line 90 of file pithsync.h.

◆ faked

bool FPCUTPT::faked

Definition at line 88 of file pithsync.h.

◆ terminal

bool FPCUTPT::terminal

Definition at line 89 of file pithsync.h.


The documentation for this class was generated from the following files:
textord_balance_factor
double textord_balance_factor
Definition: topitch.cpp:53
FPCUTPT::fake_count
int16_t fake_count
Definition: pithsync.h:90
STATS::pile_count
int32_t pile_count(int32_t value) const
Definition: statistc.h:75
textord_fast_pitch_test
bool textord_fast_pitch_test
Definition: topitch.cpp:42
FPCUTPT
Definition: pithsync.h:27
FPCUTPT::terminal
bool terminal
Definition: pithsync.h:89
FPCUTPT::faked
bool faked
Definition: pithsync.h:88
FPCUTPT::index
int16_t index() const
Definition: pithsync.h:84