Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FPCUTPT Class Reference

#include <pithsync.h>

Public Member Functions

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

Public Attributes

BOOL8 faked
 
BOOL8 terminal
 
inT16 fake_count
 

Detailed Description

Definition at line 30 of file pithsync.h.

Constructor & Destructor Documentation

FPCUTPT::FPCUTPT ( )
inline

Definition at line 33 of file pithsync.h.

33  { //empty
34  }

Member Function Documentation

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

Definition at line 99 of file pithsync.cpp.

111  {
112  int index; //test index
113  int balance_index; //for balance factor
114  inT16 balance_count; //ding factor
115  inT16 r_index; //test cut number
116  FPCUTPT *segpt; //segment point
117  inT32 dist; //from prev segment
118  double sq_dist; //squared distance
119  double mean; //mean pitch
120  double total; //total dists
121  double factor; //cost function
122  //half of pitch
123  inT16 half_pitch = pitch / 2 - 1;
124  uinT32 lead_flag; //new flag
125 
126  if (half_pitch > 31)
127  half_pitch = 31;
128  else if (half_pitch < 0)
129  half_pitch = 0;
130  lead_flag = 1 << half_pitch;
131 
132  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
133  back_balance &= lead_flag + lead_flag - 1;
134  if (projection->pile_count (x) > zero_count)
135  back_balance |= 1;
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  xpos = x;
141  cost = MAX_FLOAT32;
142  pred = NULL;
143  faked = faking;
144  terminal = FALSE;
145  region_index = 0;
147  for (index = x - pitch - pitch_error; index <= x - pitch + pitch_error;
148  index++) {
149  if (index >= array_origin) {
150  segpt = &cutpts[index - array_origin];
151  dist = x - segpt->xpos;
152  if (!segpt->terminal && segpt->fake_count < MAX_INT16) {
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  }
163  else {
164  for (balance_index = 0;
165  index + balance_index < x - balance_index;
166  balance_index++)
167  balance_count +=
168  (projection->pile_count (index + balance_index) <=
169  zero_count) ^ (projection->pile_count (x -
170  balance_index)
171  <= zero_count);
172  }
173  balance_count =
174  (inT16) (balance_count * textord_balance_factor /
175  projection_scale);
176  }
177  r_index = segpt->region_index + 1;
178  total = segpt->mean_sum + dist;
179  balance_count += offset;
180  sq_dist =
181  dist * dist + segpt->sq_sum + balance_count * balance_count;
182  mean = total / r_index;
183  factor = mean - pitch;
184  factor *= factor;
185  factor += sq_dist / (r_index) - mean * mean;
186  if (factor < cost && segpt->fake_count + faked <= fake_count) {
187  cost = factor; //find least cost
188  pred = segpt; //save path
189  mean_sum = total;
190  sq_sum = sq_dist;
191  fake_count = segpt->fake_count + faked;
192  mid_cuts = segpt->mid_cuts + mid_cut;
193  region_index = r_index;
194  }
195  }
196  }
197  }
198 }
BOOL8 faked
Definition: pithsync.h:92
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
#define FALSE
Definition: capi.h:28
inT16 fake_count
Definition: pithsync.h:94
inT32 pile_count(inT32 value) const
Definition: statistc.h:74
BOOL8 terminal
Definition: pithsync.h:93
EXTERN double textord_balance_factor
Definition: topitch.cpp:61
#define MAX_FLOAT32
Definition: host.h:124
EXTERN bool textord_fast_pitch_test
Definition: topitch.cpp:50
short inT16
Definition: host.h:100
#define MAX_INT16
Definition: host.h:119
inT16 index() const
Definition: pithsync.h:88
unsigned int uinT32
Definition: host.h:103
void FPCUTPT::assign_cheap ( FPCUTPT  cutpts[],
inT16  array_origin,
inT16  x,
BOOL8  faking,
BOOL8  mid_cut,
inT16  offset,
STATS projection,
float  projection_scale,
inT16  zero_count,
inT16  pitch,
inT16  pitch_error 
)

Definition at line 207 of file pithsync.cpp.

219  {
220  int index; //test index
221  inT16 balance_count; //ding factor
222  inT16 r_index; //test cut number
223  FPCUTPT *segpt; //segment point
224  inT32 dist; //from prev segment
225  double sq_dist; //squared distance
226  double mean; //mean pitch
227  double total; //total dists
228  double factor; //cost function
229  //half of pitch
230  inT16 half_pitch = pitch / 2 - 1;
231  uinT32 lead_flag; //new flag
232 
233  if (half_pitch > 31)
234  half_pitch = 31;
235  else if (half_pitch < 0)
236  half_pitch = 0;
237  lead_flag = 1 << half_pitch;
238 
239  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
240  back_balance &= lead_flag + lead_flag - 1;
241  if (projection->pile_count (x) > zero_count)
242  back_balance |= 1;
243  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
244  if (projection->pile_count (x + half_pitch) > zero_count)
245  fwd_balance |= lead_flag;
246 
247  xpos = x;
248  cost = MAX_FLOAT32;
249  pred = NULL;
250  faked = faking;
251  terminal = FALSE;
252  region_index = 0;
254  index = x - pitch;
255  if (index >= array_origin) {
256  segpt = &cutpts[index - array_origin];
257  dist = x - segpt->xpos;
258  if (!segpt->terminal && segpt->fake_count < MAX_INT16) {
259  balance_count = 0;
260  if (textord_balance_factor > 0) {
261  lead_flag = back_balance ^ segpt->fwd_balance;
262  balance_count = 0;
263  while (lead_flag != 0) {
264  balance_count++;
265  lead_flag &= lead_flag - 1;
266  }
267  balance_count = (inT16) (balance_count * textord_balance_factor
268  / projection_scale);
269  }
270  r_index = segpt->region_index + 1;
271  total = segpt->mean_sum + dist;
272  balance_count += offset;
273  sq_dist =
274  dist * dist + segpt->sq_sum + balance_count * balance_count;
275  mean = total / r_index;
276  factor = mean - pitch;
277  factor *= factor;
278  factor += sq_dist / (r_index) - mean * mean;
279  cost = factor; //find least cost
280  pred = segpt; //save path
281  mean_sum = total;
282  sq_sum = sq_dist;
283  fake_count = segpt->fake_count + faked;
284  mid_cuts = segpt->mid_cuts + mid_cut;
285  region_index = r_index;
286  }
287  }
288 }
BOOL8 faked
Definition: pithsync.h:92
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
#define FALSE
Definition: capi.h:28
inT16 fake_count
Definition: pithsync.h:94
inT32 pile_count(inT32 value) const
Definition: statistc.h:74
BOOL8 terminal
Definition: pithsync.h:93
EXTERN double textord_balance_factor
Definition: topitch.cpp:61
#define MAX_FLOAT32
Definition: host.h:124
short inT16
Definition: host.h:100
#define MAX_INT16
Definition: host.h:119
inT16 index() const
Definition: pithsync.h:88
unsigned int uinT32
Definition: host.h:103
inT16 FPCUTPT::cheap_cuts ( ) const
inline

Definition at line 85 of file pithsync.h.

85  { //no of mi cuts
86  return mid_cuts;
87  }
double FPCUTPT::cost_function ( )
inline

Definition at line 73 of file pithsync.h.

73  {
74  return cost;
75  }
inT16 FPCUTPT::index ( ) const
inline

Definition at line 88 of file pithsync.h.

88  {
89  return region_index;
90  }
inT32 FPCUTPT::position ( )
inline

Definition at line 70 of file pithsync.h.

70  { //acces func
71  return xpos;
72  }
FPCUTPT* FPCUTPT::previous ( )
inline

Definition at line 82 of file pithsync.h.

82  {
83  return pred;
84  }
void FPCUTPT::setup ( FPCUTPT  cutpts[],
inT16  array_origin,
STATS projection,
inT16  zero_count,
inT16  pitch,
inT16  x,
inT16  offset 
)

Definition at line 42 of file pithsync.cpp.

50  {
51  //half of pitch
52  inT16 half_pitch = pitch / 2 - 1;
53  uinT32 lead_flag; //new flag
54  inT32 ind; //current position
55 
56  if (half_pitch > 31)
57  half_pitch = 31;
58  else if (half_pitch < 0)
59  half_pitch = 0;
60  lead_flag = 1 << half_pitch;
61 
62  pred = NULL;
63  mean_sum = 0;
64  sq_sum = offset * offset;
65  cost = sq_sum;
66  faked = FALSE;
67  terminal = FALSE;
68  fake_count = 0;
69  xpos = x;
70  region_index = 0;
71  mid_cuts = 0;
72  if (x == array_origin) {
73  back_balance = 0;
74  fwd_balance = 0;
75  for (ind = 0; ind <= half_pitch; ind++) {
76  fwd_balance >>= 1;
77  if (projection->pile_count (ind) > zero_count)
78  fwd_balance |= lead_flag;
79  }
80  }
81  else {
82  back_balance = cutpts[x - 1 - array_origin].back_balance << 1;
83  back_balance &= lead_flag + lead_flag - 1;
84  if (projection->pile_count (x) > zero_count)
85  back_balance |= 1;
86  fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1;
87  if (projection->pile_count (x + half_pitch) > zero_count)
88  fwd_balance |= lead_flag;
89  }
90 }
BOOL8 faked
Definition: pithsync.h:92
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
#define FALSE
Definition: capi.h:28
inT16 fake_count
Definition: pithsync.h:94
inT32 pile_count(inT32 value) const
Definition: statistc.h:74
BOOL8 terminal
Definition: pithsync.h:93
short inT16
Definition: host.h:100
unsigned int uinT32
Definition: host.h:103
double FPCUTPT::squares ( )
inline

Definition at line 76 of file pithsync.h.

76  {
77  return sq_sum;
78  }
double FPCUTPT::sum ( )
inline

Definition at line 79 of file pithsync.h.

79  {
80  return mean_sum;
81  }

Member Data Documentation

inT16 FPCUTPT::fake_count

Definition at line 94 of file pithsync.h.

BOOL8 FPCUTPT::faked

Definition at line 92 of file pithsync.h.

BOOL8 FPCUTPT::terminal

Definition at line 93 of file pithsync.h.


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