00001
00020 #include "mfcpch.h"
00021 #include "pithsync.h"
00022 #include "topitch.h"
00023 #include "drawtord.h"
00024 #include "debugwin.h"
00025
00026 #define TO_WIN_XPOS -1 //default window pos
00027 #define TO_WIN_YPOS 0
00028 #define TO_WIN_NAME "Textord"
00029
00030 #define DEBUG_WIN_NAME "TODebug"
00031 #define DEBUG_XPOS 0
00032 #define DEBUG_YPOS 120
00033 #define DEBUG_XSIZE 80
00034 #define DEBUG_YSIZE 32
00035 #define YMAX 3508
00036 #define XMAX 2550
00037
00038 #define EXTERN
00039
00042 EXTERN BOOL_VAR (textord_show_fixed_cuts, FALSE,
00043 "Draw fixed pitch cell boundaries");
00044 EXTERN STRING_VAR (to_debugfile, DEBUG_WIN_NAME, "Name of debugfile");
00045 EXTERN STRING_VAR (to_smdfile, NO_SMD, "Name of SMD file");
00048 EXTERN WINDOW to_win = NO_WINDOW;
00049 EXTERN FILE *to_debug = NULL;
00050
00054 void create_to_win(
00055 ICOORD page_tr
00056 ) {
00057 if (strcmp (to_smdfile.string (), NO_SMD)) {
00058 to_win = create_window (to_smdfile.string (), SMDWINDOW,
00059 0, 0, page_tr.x () + 1, page_tr.y () + 1,
00060 0.0, page_tr.x (), 0.0, page_tr.y (),
00061 TRUE, FALSE, TRUE, TRUE);
00062 }
00063 else {
00064 to_win = create_window (TO_WIN_NAME, SCROLLINGWIN,
00065 TO_WIN_XPOS, TO_WIN_YPOS, 0, 0,
00066 0.0, page_tr.x (), 0.0, page_tr.y (),
00067 TRUE, FALSE, TRUE, TRUE);
00068 }
00069 }
00070
00071
00075 void close_to_win() {
00076 if (to_win != NO_WINDOW && strcmp (to_smdfile.string (), NO_SMD)) {
00077 destroy_window(to_win);
00078 overlap_picture_ops(TRUE);
00079 }
00080 }
00081
00082
00086 void create_todebug_win() {
00087 if (strcmp (to_debugfile.string (), DEBUG_WIN_NAME) != 0)
00088
00089
00090 to_debug = fopen (to_debugfile.string (), "w");
00091 }
00092
00093
00097 void plot_blob_list(
00098 WINDOW win,
00099 BLOBNBOX_LIST *list,
00100 COLOUR body_colour,
00101 COLOUR child_colour
00102 ) {
00103 BLOBNBOX_IT it = list;
00104
00105 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00106 it.data ()->plot (win, body_colour, child_colour);
00107 }
00108 }
00109
00110
00114 void plot_box_list(
00115 WINDOW win,
00116 BLOBNBOX_LIST *list,
00117 COLOUR body_colour
00118 ) {
00119 BLOBNBOX_IT it = list;
00120
00121 perimeter_color_index(win, body_colour);
00122 interior_style(win, INT_HOLLOW, TRUE);
00123 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00124 it.data ()->bounding_box ().plot (win);
00125 }
00126 }
00127
00128
00132 void plot_to_row(
00133 TO_ROW *row,
00134 COLOUR colour,
00135 FCOORD rotation
00136 ) {
00137 FCOORD plot_pt;
00138
00139 BLOBNBOX_IT it = row->blob_list ();
00140 float left, right;
00141
00142 if (it.empty ()) {
00143 tprintf ("No blobs in row at %g\n", row->parallel_c ());
00144 return;
00145 }
00146 left = it.data ()->bounding_box ().left ();
00147 it.move_to_last ();
00148 right = it.data ()->bounding_box ().right ();
00149 plot_blob_list (to_win, row->blob_list (), colour, BROWN);
00150 line_color_index(to_win, colour);
00151 plot_pt = FCOORD (left, row->line_m () * left + row->line_c ());
00152 plot_pt.rotate (rotation);
00153 move2d (to_win, plot_pt.x (), plot_pt.y ());
00154 plot_pt = FCOORD (right, row->line_m () * right + row->line_c ());
00155 plot_pt.rotate (rotation);
00156 draw2d (to_win, plot_pt.x (), plot_pt.y ());
00157 }
00158
00159
00163 void plot_parallel_row(
00164 TO_ROW *row,
00165 float gradient,
00166 INT32 left,
00167 COLOUR colour,
00168 FCOORD rotation
00169 ) {
00170 FCOORD plot_pt;
00171
00172 BLOBNBOX_IT it = row->blob_list ();
00173 float fleft = (float) left;
00174 float right;
00175
00176
00177 it.move_to_last ();
00178 right = it.data ()->bounding_box ().right ();
00179 plot_blob_list (to_win, row->blob_list (), colour, BROWN);
00180 line_color_index(to_win, colour);
00181 plot_pt = FCOORD (fleft, gradient * left + row->max_y ());
00182 plot_pt.rotate (rotation);
00183 move2d (to_win, plot_pt.x (), plot_pt.y ());
00184 plot_pt = FCOORD (fleft, gradient * left + row->min_y ());
00185 plot_pt.rotate (rotation);
00186 draw2d (to_win, plot_pt.x (), plot_pt.y ());
00187 plot_pt = FCOORD (fleft, gradient * left + row->parallel_c ());
00188 plot_pt.rotate (rotation);
00189 move2d (to_win, plot_pt.x (), plot_pt.y ());
00190 plot_pt = FCOORD (right, gradient * right + row->parallel_c ());
00191 plot_pt.rotate (rotation);
00192 draw2d (to_win, plot_pt.x (), plot_pt.y ());
00193 }
00194
00195
00202 void
00203 draw_occupation (
00204 INT32 xleft,
00205 INT32 ybottom,
00206 INT32 min_y,
00207 INT32 max_y, INT32 occupation[],
00208 INT32 thresholds[]
00209 ) {
00210 INT32 line_index;
00211 COLOUR colour;
00212 float fleft = (float) xleft;
00213
00214 colour = WHITE;
00215 line_color_index(to_win, colour);
00216 move2d (to_win, fleft, (float) ybottom);
00217 for (line_index = min_y; line_index <= max_y; line_index++) {
00218 if (occupation[line_index - min_y] < thresholds[line_index - min_y]) {
00219 if (colour != BLUE) {
00220 colour = BLUE;
00221 line_color_index(to_win, colour);
00222 }
00223 }
00224 else {
00225 if (colour != WHITE) {
00226 colour = WHITE;
00227 line_color_index(to_win, colour);
00228 }
00229 }
00230 draw2d (to_win, fleft + occupation[line_index - min_y] / 10.0,
00231 (float) line_index);
00232 }
00233 line_color_index(to_win, STEEL_BLUE);
00234 move2d (to_win, fleft, (float) ybottom);
00235 for (line_index = min_y; line_index <= max_y; line_index++) {
00236 draw2d (to_win, fleft + thresholds[line_index - min_y] / 10.0,
00237 (float) line_index);
00238 }
00239 }
00240
00241
00245 void draw_meanlines(
00246 TO_BLOCK *block,
00247 float gradient,
00248 INT32 left,
00249 COLOUR colour,
00250 FCOORD rotation
00251 ) {
00252 FCOORD plot_pt;
00253
00254 TO_ROW_IT row_it = block->get_rows ();
00255 TO_ROW *row;
00256 BLOBNBOX_IT blob_it;
00257 float right;
00258
00259 line_color_index(to_win, colour);
00260 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00261 row = row_it.data ();
00262 blob_it.set_to_list (row->blob_list ());
00263 blob_it.move_to_last ();
00264 right = blob_it.data ()->bounding_box ().right ();
00265 plot_pt =
00266 FCOORD ((float) left,
00267 gradient * left + row->parallel_c () + row->xheight);
00268 plot_pt.rotate (rotation);
00269 move2d (to_win, plot_pt.x (), plot_pt.y ());
00270 plot_pt =
00271 FCOORD ((float) right,
00272 gradient * right + row->parallel_c () + row->xheight);
00273 plot_pt.rotate (rotation);
00274 draw2d (to_win, plot_pt.x (), plot_pt.y ());
00275 }
00276 }
00277
00278
00283 void plot_word_decisions(
00284 WINDOW win,
00285 INT16 pitch,
00286 TO_ROW *row
00287 ) {
00288 COLOUR colour = MAGENTA;
00289 COLOUR rect_colour;
00290 INT32 prev_x;
00291 INT16 blob_count;
00292 BLOBNBOX *blob;
00293 BOX blob_box;
00294
00295 BLOBNBOX_IT blob_it = row->blob_list ();
00296 BLOBNBOX_IT start_it = blob_it;
00297
00298 interior_style(win, INT_SOLID, FALSE);
00299 rect_colour = BLACK;
00300 prev_x = -MAX_INT16;
00301 blob_count = 0;
00302 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
00303 blob = blob_it.data ();
00304 blob_box = blob->bounding_box ();
00305 if (!blob->joined_to_prev ()
00306 && blob_box.left () - prev_x > row->max_nonspace) {
00307 if ((blob_box.left () - prev_x >= row->min_space
00308 || blob_box.left () - prev_x > row->space_threshold)
00309 && blob_count > 0) {
00310 if (pitch > 0 && textord_show_fixed_cuts)
00311 plot_fp_cells (win, colour, &start_it, pitch, blob_count,
00312 &row->projection, row->projection_left,
00313 row->projection_right,
00314 row->xheight * textord_projection_scale);
00315 blob_count = 0;
00316 start_it = blob_it;
00317 }
00318 if (colour == MAGENTA)
00319 colour = RED;
00320 else
00321 colour = (COLOUR) (colour + 1);
00322 if (blob_box.left () - prev_x < row->min_space) {
00323 if (blob_box.left () - prev_x > row->space_threshold)
00324 rect_colour = GOLDENROD;
00325 else
00326 rect_colour = CORAL;
00327 fill_color_index(win, rect_colour);
00328 rectangle (win, (float) prev_x, blob_box.bottom (),
00329 blob_box.left (), blob_box.top ());
00330 }
00331 }
00332 if (!blob->joined_to_prev ())
00333 prev_x = blob_box.right ();
00334 if (blob->blob () != NULL)
00335
00336 blob->blob ()->plot (win, colour, colour);
00337 if (blob->cblob () != NULL)
00338 blob->cblob ()->plot (win, colour, colour);
00339 if (!blob->joined_to_prev ()
00340 && (blob->blob () != NULL || blob->cblob () != NULL))
00341 blob_count++;
00342 }
00343 if (pitch > 0 && textord_show_fixed_cuts && blob_count > 0)
00344 plot_fp_cells (win, colour, &start_it, pitch, blob_count,
00345 &row->projection, row->projection_left,
00346 row->projection_right,
00347 row->xheight * textord_projection_scale);
00348 }
00349
00350
00354 void plot_fp_cells(
00355 WINDOW win,
00356 COLOUR colour,
00357 BLOBNBOX_IT *blob_it,
00358 INT16 pitch,
00359 INT16 blob_count,
00360 STATS *projection,
00361 INT16 projection_left,
00362 INT16 projection_right,
00363 float projection_scale) {
00364 INT16 occupation;
00365 BOX word_box;
00366 FPSEGPT_LIST seg_list;
00367 FPSEGPT_IT seg_it;
00368 FPSEGPT *segpt;
00369
00370 if (pitsync_linear_version)
00371 check_pitch_sync2 (blob_it, blob_count, pitch, 2, projection,
00372 projection_left, projection_right,
00373 projection_scale, occupation, &seg_list, 0, 0);
00374 else
00375 check_pitch_sync (blob_it, blob_count, pitch, 2, projection, &seg_list);
00376 word_box = blob_it->data ()->bounding_box ();
00377 for (; blob_count > 0; blob_count--)
00378 word_box += box_next (blob_it);
00379 seg_it.set_to_list (&seg_list);
00380 for (seg_it.mark_cycle_pt (); !seg_it.cycled_list (); seg_it.forward ()) {
00381 segpt = seg_it.data ();
00382 if (segpt->faked)
00383 line_color_index(win, WHITE);
00384 else
00385 line_color_index(win, colour);
00386 move2d (win, segpt->position (), word_box.bottom ());
00387 draw2d (win, segpt->position (), word_box.top ());
00388 }
00389 }
00390
00391
00395 void plot_fp_cells2(
00396 WINDOW win,
00397 COLOUR colour,
00398 TO_ROW *row,
00399 FPSEGPT_LIST *seg_list
00400 ) {
00401 BOX word_box;
00402 FPSEGPT_IT seg_it = seg_list;
00403
00404 BLOBNBOX_IT blob_it = row->blob_list ();
00405 FPSEGPT *segpt;
00406
00407 word_box = blob_it.data ()->bounding_box ();
00408 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();)
00409 word_box += box_next (&blob_it);
00410 for (seg_it.mark_cycle_pt (); !seg_it.cycled_list (); seg_it.forward ()) {
00411 segpt = seg_it.data ();
00412 if (segpt->faked)
00413 line_color_index(win, WHITE);
00414 else
00415 line_color_index(win, colour);
00416 move2d (win, segpt->position (), word_box.bottom ());
00417 draw2d (win, segpt->position (), word_box.top ());
00418 }
00419 }
00420
00421
00425 void plot_row_cells(
00426 WINDOW win,
00427 COLOUR colour,
00428 TO_ROW *row,
00429 float xshift,
00430 ICOORDELT_LIST *cells
00431 ) {
00432 BOX word_box;
00433 ICOORDELT_IT cell_it = cells;
00434
00435 BLOBNBOX_IT blob_it = row->blob_list ();
00436 ICOORDELT *cell;
00437
00438 word_box = blob_it.data ()->bounding_box ();
00439 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();)
00440 word_box += box_next (&blob_it);
00441 line_color_index(win, colour);
00442 for (cell_it.mark_cycle_pt (); !cell_it.cycled_list (); cell_it.forward ()) {
00443 cell = cell_it.data ();
00444 move2d (win, cell->x () + xshift, word_box.bottom ());
00445 draw2d (win, cell->x () + xshift, word_box.top ());
00446 }
00447 }