tesseract  4.0.0-1-g2a2b
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, BOOL8 faking, BOOL8 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 29 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 94 of file pithsync.cpp.

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

◆ assign_cheap()

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

Definition at line 202 of file pithsync.cpp.

214  {
215  int index; //test index
216  int16_t balance_count; //ding factor
217  int16_t r_index; //test cut number
218  FPCUTPT *segpt; //segment point
219  int32_t dist; //from prev segment
220  double sq_dist; //squared distance
221  double mean; //mean pitch
222  double total; //total dists
223  double factor; //cost function
224  //half of pitch
225  int16_t half_pitch = pitch / 2 - 1;
226  uint32_t lead_flag; //new flag
227 
228  if (half_pitch > 31)
229  half_pitch = 31;
230  else if (half_pitch < 0)
231  half_pitch = 0;
232  lead_flag = 1 << half_pitch;
233 
234  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
235  back_balance &= lead_flag + lead_flag - 1;
236  if (projection->pile_count (x) > zero_count)
237  back_balance |= 1;
238  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
239  if (projection->pile_count (x + half_pitch) > zero_count)
240  fwd_balance |= lead_flag;
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 = (int16_t) (balance_count * textord_balance_factor
263  / projection_scale);
264  }
265  r_index = segpt->region_index + 1;
266  total = segpt->mean_sum + dist;
267  balance_count += offset;
268  sq_dist =
269  dist * dist + segpt->sq_sum + balance_count * balance_count;
270  mean = total / r_index;
271  factor = mean - pitch;
272  factor *= factor;
273  factor += sq_dist / (r_index) - mean * mean;
274  cost = factor; //find least cost
275  pred = segpt; //save path
276  mean_sum = total;
277  sq_sum = sq_dist;
278  fake_count = segpt->fake_count + faked;
279  mid_cuts = segpt->mid_cuts + mid_cut;
280  region_index = r_index;
281  }
282  }
283 }
int32_t pile_count(int32_t value) const
Definition: statistc.h:78
bool terminal
Definition: pithsync.h:91
EXTERN double textord_balance_factor
Definition: topitch.cpp:57
int16_t index() const
Definition: pithsync.h:86
int16_t fake_count
Definition: pithsync.h:92
bool faked
Definition: pithsync.h:90

◆ cheap_cuts()

int16_t 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 FPCUTPT::cost_function ( )
inline

Definition at line 71 of file pithsync.h.

71  {
72  return cost;
73  }

◆ index()

int16_t FPCUTPT::index ( ) const
inline

Definition at line 86 of file pithsync.h.

86  {
87  return region_index;
88  }

◆ position()

int32_t FPCUTPT::position ( )
inline

Definition at line 68 of file pithsync.h.

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

◆ previous()

FPCUTPT* FPCUTPT::previous ( )
inline

Definition at line 80 of file pithsync.h.

80  {
81  return pred;
82  }

◆ 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 37 of file pithsync.cpp.

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

◆ squares()

double FPCUTPT::squares ( )
inline

Definition at line 74 of file pithsync.h.

74  {
75  return sq_sum;
76  }

◆ sum()

double FPCUTPT::sum ( )
inline

Definition at line 77 of file pithsync.h.

77  {
78  return mean_sum;
79  }

Member Data Documentation

◆ fake_count

int16_t FPCUTPT::fake_count

Definition at line 92 of file pithsync.h.

◆ faked

bool FPCUTPT::faked

Definition at line 90 of file pithsync.h.

◆ terminal

bool FPCUTPT::terminal

Definition at line 91 of file pithsync.h.


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