30 INT_VAR (pitsync_linear_version, 6,
"Use new fast algorithm");
33 "Dist inside big blob for chopping");
36 "Fraction of cut for free cuts");
51 mean_sum = cutpt->
sum ();
95 FPSEGPT_LIST * prev_list
104 FPSEGPT_IT pred_it = prev_list;
112 for (pred_it.mark_cycle_pt (); !pred_it.cycled_list (); pred_it.forward ()) {
113 segpt = pred_it.data ();
116 dist = x - segpt->xpos;
117 if (dist >= pitch - pitch_error && dist <= pitch + pitch_error
119 total = segpt->mean_sum + dist;
120 sq_dist = dist * dist + segpt->sq_sum + offset * offset;
122 mean = total / region_index;
123 factor = mean - pitch;
125 factor += sq_dist / (region_index) - mean * mean;
149 BLOBNBOX_IT *blob_it,
154 FPSEGPT_LIST *seg_list
165 inT16 best_region_index = 0;
173 FPSEGPT_LIST *segpts;
181 FPSEGPT_IT outseg_it = seg_list;
182 FPSEGPT_LIST_CLIST lattice;
184 FPSEGPT_LIST_C_IT lattice_it = &lattice;
192 if ((pitch - 3) / 2 < pitch_error)
193 pitch_error = (pitch - 3) / 2;
201 left_edge = min_box.
left () + pitch_error;
202 for (min_index = 1; min_index < blob_count; min_index++) {
209 right_edge = min_box.
right ();
212 min_x = max_x - pitch + pitch_error * 2 + 1;
213 right_max = right_edge + pitch - pitch_error - 1;
214 segpts =
new FPSEGPT_LIST;
215 segpt_it.set_to_list (segpts);
216 for (x = min_x; x <= max_x; x++) {
219 segpt_it.add_after_then_move (segpt);
222 lattice_it.add_before_then_move (segpts);
232 segpts =
new FPSEGPT_LIST;
233 segpt_it.set_to_list (segpts);
234 min_x += pitch - pitch_error;
235 max_x += pitch + pitch_error;
236 while (min_box.
right () < min_x && min_index < blob_count) {
241 max_index = min_index;
244 for (x = min_x; x <= max_x && x <= right_max; x++) {
245 while (x < right_edge && max_index < blob_count
246 && x > max_box.
right ()) {
251 if (x <= max_box.
left () + pitch_error
252 || x >= max_box.
right () - pitch_error || x >= right_edge
253 || (max_index < blob_count - 1 && x >= next_box.
left ())
257 if (x - max_box.
left () > 0
258 && x - max_box.
left () <= pitch_error)
260 offset = x - max_box.
left ();
261 else if (max_box.
right () - x > 0
262 && max_box.
right () - x <= pitch_error
263 && (max_index >= blob_count - 1
264 || x < next_box.
left ()))
265 offset = max_box.
right () - x;
270 pitch, pitch_error, lattice_it.data ());
274 segpt =
new FPSEGPT (x,
TRUE, offset, region_index,
275 pitch, pitch_error, lattice_it.data ());
278 segpt_it.add_after_then_move (segpt);
279 if (x >= right_edge - pitch_error) {
285 best_region_index = region_index;
290 && right_best_x == x - 1)
298 if (segpts->empty ()) {
299 if (best_end != NULL)
302 region_index, pitch, pitch_error, segpts);
305 if (right_best_x > left_best_x + 1) {
306 left_best_x = (left_best_x + right_best_x + 1) / 2;
307 for (segpt_it.mark_cycle_pt (); !segpt_it.cycled_list ()
308 && segpt_it.data ()->position () != left_best_x;
309 segpt_it.forward ());
310 if (segpt_it.data ()->position () == left_best_x)
312 best_end = segpt_it.data ();
316 lattice_it.add_before_then_move (segpts);
319 while (min_x < right_edge);
322 for (lattice_it.mark_cycle_pt (); !lattice_it.cycled_list ();
323 lattice_it.forward ()) {
324 segpts = lattice_it.data ();
325 segpt_it.set_to_list (segpts);
337 for (segpt_it.mark_cycle_pt (); !segpt_it.cycled_list ()
338 && segpt_it.data () != best_end; segpt_it.forward ());
339 if (segpt_it.data () == best_end) {
341 segpt = segpt_it.extract ();
342 outseg_it.add_before_then_move (segpt);
348 outseg_it.move_to_last ();
349 mean_sum = outseg_it.data ()->sum ();
350 mean_sum = mean_sum * mean_sum / best_region_index;
351 if (outseg_it.data ()->squares () - mean_sum < 0)
352 tprintf (
"Impossible sqsum=%g, mean=%g, total=%d\n",
353 outseg_it.data ()->squares (), outseg_it.data ()->sum (),
355 lattice.deep_clear ();
356 return outseg_it.data ()->squares () - mean_sum;
367 FPSEGPT_LIST *prev_list,
373 FPSEGPT_LIST *seg_list
382 FPSEGPT_IT segpt_it = seg_list;
384 FPSEGPT_IT prevpt_it = prev_list;
387 for (prevpt_it.mark_cycle_pt (); !prevpt_it.cycled_list ();
388 prevpt_it.forward ()) {
389 prevpt = prevpt_it.data ();
400 min_x += pitch - pitch_error;
401 max_x += pitch + pitch_error;
402 for (x = min_x; x <= max_x; x++) {
403 while (x > blob_box.
right ()) {
406 offset = x - blob_box.
left ();
407 if (blob_box.
right () - x < offset)
408 offset = blob_box.
right () - x;
410 region_index, pitch, pitch_error, prev_list);
413 fprintf (stderr,
"made fake at %d\n", x);
415 segpt_it.add_after_then_move (segpt);
EXTERN int pitsync_fake_depth
double check_pitch_sync(BLOBNBOX_IT *blob_it, inT16 blob_count, inT16 pitch, inT16 pitch_error, STATS *projection, FPSEGPT_LIST *seg_list)
void make_illegal_segment(FPSEGPT_LIST *prev_list, TBOX blob_box, BLOBNBOX_IT blob_it, inT16 region_index, inT16 pitch, inT16 pitch_error, FPSEGPT_LIST *seg_list)
EXTERN double pitsync_joined_edge
EXTERN double pitsync_offset_freecut_fraction
ELISTIZE(FPSEGPT) CLISTIZE(FPSEGPT_LIST) EXTERN int pitsync_linear_version
TBOX box_next(BLOBNBOX_IT *it)
inT32 pile_count(inT32 value) const
#define double_VAR(name, val, comment)
#define CLISTIZE(CLASSNAME)
#define INT_VAR(name, val, comment)