tesseract  5.0.0
tesseract::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 30 of file pithsync.h.

Constructor & Destructor Documentation

◆ FPCUTPT()

tesseract::FPCUTPT::FPCUTPT ( )
default

Member Function Documentation

◆ assign()

void tesseract::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 97 of file pithsync.cpp.

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

◆ assign_cheap()

void tesseract::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 199 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  }
230  lead_flag = 1 << half_pitch;
231 
232  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
233  back_balance &= lead_flag + (lead_flag - 1);
234  if (projection->pile_count(x) > zero_count) {
235  back_balance |= 1;
236  }
237  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
238  if (projection->pile_count(x + half_pitch) > zero_count) {
239  fwd_balance |= lead_flag;
240  }
241 
242  xpos = x;
243  cost = FLT_MAX;
244  pred = nullptr;
245  faked = faking;
246  terminal = false;
247  region_index = 0;
248  fake_count = INT16_MAX;
249  index = x - pitch;
250  if (index >= array_origin) {
251  segpt = &cutpts[index - array_origin];
252  dist = x - segpt->xpos;
253  if (!segpt->terminal && segpt->fake_count < INT16_MAX) {
254  balance_count = 0;
255  if (textord_balance_factor > 0) {
256  lead_flag = back_balance ^ segpt->fwd_balance;
257  balance_count = 0;
258  while (lead_flag != 0) {
259  balance_count++;
260  lead_flag &= lead_flag - 1;
261  }
262  balance_count =
263  static_cast<int16_t>(balance_count * textord_balance_factor / projection_scale);
264  }
265  r_index = segpt->region_index + 1;
266  total = segpt->mean_sum + dist;
267  balance_count += offset;
268  sq_dist = dist * dist + segpt->sq_sum + balance_count * balance_count;
269  mean = total / r_index;
270  factor = mean - pitch;
271  factor *= factor;
272  factor += sq_dist / (r_index)-mean * mean;
273  cost = factor; // find least cost
274  pred = segpt; // save path
275  mean_sum = total;
276  sq_sum = sq_dist;
277  fake_count = segpt->fake_count + faked;
278  mid_cuts = segpt->mid_cuts + mid_cut;
279  region_index = r_index;
280  }
281  }
282 }

◆ cheap_cuts()

int16_t tesseract::FPCUTPT::cheap_cuts ( ) const
inline

Definition at line 83 of file pithsync.h.

83  { // no of mi cuts
84  return mid_cuts;
85  }

◆ cost_function()

double tesseract::FPCUTPT::cost_function ( )
inline

Definition at line 71 of file pithsync.h.

71  {
72  return cost;
73  }

◆ index()

int16_t tesseract::FPCUTPT::index ( ) const
inline

Definition at line 86 of file pithsync.h.

86  {
87  return region_index;
88  }

◆ position()

int32_t tesseract::FPCUTPT::position ( )
inline

Definition at line 68 of file pithsync.h.

68  { // access func
69  return xpos;
70  }

◆ previous()

FPCUTPT* tesseract::FPCUTPT::previous ( )
inline

Definition at line 80 of file pithsync.h.

80  {
81  return pred;
82  }

◆ setup()

void tesseract::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 38 of file pithsync.cpp.

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

◆ squares()

double tesseract::FPCUTPT::squares ( )
inline

Definition at line 74 of file pithsync.h.

74  {
75  return sq_sum;
76  }

◆ sum()

double tesseract::FPCUTPT::sum ( )
inline

Definition at line 77 of file pithsync.h.

77  {
78  return mean_sum;
79  }

Member Data Documentation

◆ fake_count

int16_t tesseract::FPCUTPT::fake_count

Definition at line 92 of file pithsync.h.

◆ faked

bool tesseract::FPCUTPT::faked

Definition at line 90 of file pithsync.h.

◆ terminal

bool tesseract::FPCUTPT::terminal

Definition at line 91 of file pithsync.h.


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