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;
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
TBOX box_next(BLOBNBOX_IT *it)
inT32 pile_count(inT32 value) const