Tesseract
3.02
|
#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 () |
FPCUTPT * | previous () |
inT16 | cheap_cuts () const |
inT16 | index () const |
Public Attributes | |
BOOL8 | faked |
BOOL8 | terminal |
inT16 | fake_count |
Definition at line 30 of file pithsync.h.
FPCUTPT::FPCUTPT | ( | ) | [inline] |
Definition at line 33 of file pithsync.h.
{ //empty
}
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.
{ int index; //test index int balance_index; //for balance factor inT16 balance_count; //ding factor inT16 r_index; //test cut number FPCUTPT *segpt; //segment point inT32 dist; //from prev segment double sq_dist; //squared distance double mean; //mean pitch double total; //total dists double factor; //cost function //half of pitch inT16 half_pitch = pitch / 2 - 1; uinT32 lead_flag; //new flag if (half_pitch > 31) half_pitch = 31; else if (half_pitch < 0) half_pitch = 0; lead_flag = 1 << half_pitch; back_balance = cutpts[x - 1 - array_origin].back_balance << 1; back_balance &= lead_flag + lead_flag - 1; if (projection->pile_count (x) > zero_count) back_balance |= 1; fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1; if (projection->pile_count (x + half_pitch) > zero_count) fwd_balance |= lead_flag; xpos = x; cost = MAX_FLOAT32; pred = NULL; faked = faking; terminal = FALSE; region_index = 0; fake_count = MAX_INT16; for (index = x - pitch - pitch_error; index <= x - pitch + pitch_error; index++) { if (index >= array_origin) { segpt = &cutpts[index - array_origin]; dist = x - segpt->xpos; if (!segpt->terminal && segpt->fake_count < MAX_INT16) { balance_count = 0; if (textord_balance_factor > 0) { if (textord_fast_pitch_test) { lead_flag = back_balance ^ segpt->fwd_balance; balance_count = 0; while (lead_flag != 0) { balance_count++; lead_flag &= lead_flag - 1; } } else { for (balance_index = 0; index + balance_index < x - balance_index; balance_index++) balance_count += (projection->pile_count (index + balance_index) <= zero_count) ^ (projection->pile_count (x - balance_index) <= zero_count); } balance_count = (inT16) (balance_count * textord_balance_factor / projection_scale); } r_index = segpt->region_index + 1; total = segpt->mean_sum + dist; balance_count += offset; sq_dist = dist * dist + segpt->sq_sum + balance_count * balance_count; mean = total / r_index; factor = mean - pitch; factor *= factor; factor += sq_dist / (r_index) - mean * mean; if (factor < cost && segpt->fake_count + faked <= fake_count) { cost = factor; //find least cost pred = segpt; //save path mean_sum = total; sq_sum = sq_dist; fake_count = segpt->fake_count + faked; mid_cuts = segpt->mid_cuts + mid_cut; region_index = r_index; } } } } }
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.
{ int index; //test index inT16 balance_count; //ding factor inT16 r_index; //test cut number FPCUTPT *segpt; //segment point inT32 dist; //from prev segment double sq_dist; //squared distance double mean; //mean pitch double total; //total dists double factor; //cost function //half of pitch inT16 half_pitch = pitch / 2 - 1; uinT32 lead_flag; //new flag if (half_pitch > 31) half_pitch = 31; else if (half_pitch < 0) half_pitch = 0; lead_flag = 1 << half_pitch; back_balance = cutpts[x - 1 - array_origin].back_balance << 1; back_balance &= lead_flag + lead_flag - 1; if (projection->pile_count (x) > zero_count) back_balance |= 1; fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1; if (projection->pile_count (x + half_pitch) > zero_count) fwd_balance |= lead_flag; xpos = x; cost = MAX_FLOAT32; pred = NULL; faked = faking; terminal = FALSE; region_index = 0; fake_count = MAX_INT16; index = x - pitch; if (index >= array_origin) { segpt = &cutpts[index - array_origin]; dist = x - segpt->xpos; if (!segpt->terminal && segpt->fake_count < MAX_INT16) { balance_count = 0; if (textord_balance_factor > 0) { lead_flag = back_balance ^ segpt->fwd_balance; balance_count = 0; while (lead_flag != 0) { balance_count++; lead_flag &= lead_flag - 1; } balance_count = (inT16) (balance_count * textord_balance_factor / projection_scale); } r_index = segpt->region_index + 1; total = segpt->mean_sum + dist; balance_count += offset; sq_dist = dist * dist + segpt->sq_sum + balance_count * balance_count; mean = total / r_index; factor = mean - pitch; factor *= factor; factor += sq_dist / (r_index) - mean * mean; cost = factor; //find least cost pred = segpt; //save path mean_sum = total; sq_sum = sq_dist; fake_count = segpt->fake_count + faked; mid_cuts = segpt->mid_cuts + mid_cut; region_index = r_index; } } }
inT16 FPCUTPT::cheap_cuts | ( | ) | const [inline] |
Definition at line 85 of file pithsync.h.
{ //no of mi cuts return mid_cuts; }
double FPCUTPT::cost_function | ( | ) | [inline] |
Definition at line 73 of file pithsync.h.
{
return cost;
}
inT16 FPCUTPT::index | ( | ) | const [inline] |
Definition at line 88 of file pithsync.h.
{
return region_index;
}
inT32 FPCUTPT::position | ( | ) | [inline] |
Definition at line 70 of file pithsync.h.
{ //acces func return xpos; }
FPCUTPT* FPCUTPT::previous | ( | ) | [inline] |
Definition at line 82 of file pithsync.h.
{
return pred;
}
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.
{ //half of pitch inT16 half_pitch = pitch / 2 - 1; uinT32 lead_flag; //new flag inT32 ind; //current position if (half_pitch > 31) half_pitch = 31; else if (half_pitch < 0) half_pitch = 0; lead_flag = 1 << half_pitch; pred = NULL; mean_sum = 0; sq_sum = offset * offset; cost = sq_sum; faked = FALSE; terminal = FALSE; fake_count = 0; xpos = x; region_index = 0; mid_cuts = 0; if (x == array_origin) { back_balance = 0; fwd_balance = 0; for (ind = 0; ind <= half_pitch; ind++) { fwd_balance >>= 1; if (projection->pile_count (ind) > zero_count) fwd_balance |= lead_flag; } } else { back_balance = cutpts[x - 1 - array_origin].back_balance << 1; back_balance &= lead_flag + lead_flag - 1; if (projection->pile_count (x) > zero_count) back_balance |= 1; fwd_balance = cutpts[x - 1 - array_origin].fwd_balance >> 1; if (projection->pile_count (x + half_pitch) > zero_count) fwd_balance |= lead_flag; } }
double FPCUTPT::squares | ( | ) | [inline] |
Definition at line 76 of file pithsync.h.
{
return sq_sum;
}
double FPCUTPT::sum | ( | ) | [inline] |
Definition at line 79 of file pithsync.h.
{
return mean_sum;
}
Definition at line 94 of file pithsync.h.
Definition at line 92 of file pithsync.h.
Definition at line 93 of file pithsync.h.