textord/drawtord.cpp File Reference

#include "mfcpch.h"
#include "pithsync.h"
#include "topitch.h"
#include "drawtord.h"
#include "debugwin.h"

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define DEBUG_WIN_NAME   "TODebug"

Definition at line 30 of file drawtord.cpp.

Referenced by create_todebug_win().

#define DEBUG_XPOS   0

Definition at line 31 of file drawtord.cpp.

#define DEBUG_XSIZE   80

Definition at line 33 of file drawtord.cpp.

#define DEBUG_YPOS   120

Definition at line 32 of file drawtord.cpp.

#define DEBUG_YSIZE   32

Definition at line 34 of file drawtord.cpp.

#define EXTERN

Definition at line 38 of file drawtord.cpp.

#define TO_WIN_NAME   "Textord"

Definition at line 28 of file drawtord.cpp.

Referenced by create_to_win().

#define TO_WIN_XPOS   -1

Note:
File: drawtord.cpp (Formerly drawto.c)
Draw things to do with textord.
Author:
Ray Smith
Date:
Thu Jul 30 15:40:57 BST 1992
 * (C) Copyright 1992, Hewlett-Packard Ltd.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Definition at line 26 of file drawtord.cpp.

Referenced by create_to_win().

#define TO_WIN_YPOS   0

Definition at line 27 of file drawtord.cpp.

Referenced by create_to_win().

#define XMAX   2550

Definition at line 36 of file drawtord.cpp.

#define YMAX   3508

Definition at line 35 of file drawtord.cpp.


Function Documentation

void close_to_win (  ) 

Close features win

Definition at line 75 of file drawtord.cpp.

References destroy_window, NO_SMD, NO_WINDOW, overlap_picture_ops, to_win, and TRUE.

Referenced by textord_page().

00075                     {  //make features 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 }

void create_to_win ( ICOORD  page_tr  ) 

Create the to window used to show the fit.

Definition at line 54 of file drawtord.cpp.

References create_window, FALSE, NO_SMD, SCROLLINGWIN, SMDWINDOW, to_win, TO_WIN_NAME, TO_WIN_XPOS, TO_WIN_YPOS, TRUE, and ICOORD::y().

Referenced by cleanup_rows(), compute_fixed_pitch(), expand_rows(), filter_blobs(), make_initial_textrows(), and pre_associate_blobs().

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 }

void create_todebug_win (  ) 

Create the to window used to show the fit.

Definition at line 86 of file drawtord.cpp.

References DEBUG_WIN_NAME, and to_debug.

00086                           {  //make gradients win
00087   if (strcmp (to_debugfile.string (), DEBUG_WIN_NAME) != 0)
00088     //              create_debug_window();
00089     //      else
00090     to_debug = fopen (to_debugfile.string (), "w");
00091 }

void draw_meanlines ( TO_BLOCK block,
float  gradient,
INT32  left,
COLOUR  colour,
FCOORD  rotation 
)

Draw the meanlines of the given block in the given colour.

Definition at line 245 of file drawtord.cpp.

References TO_ROW::blob_list(), draw2d, line_color_index, move2d, TO_ROW::parallel_c(), rotation, to_win, and TO_ROW::xheight.

Referenced by cleanup_rows().

00251                      {
00252   FCOORD plot_pt;                //point to plot
00253                                  //rows
00254   TO_ROW_IT row_it = block->get_rows ();
00255   TO_ROW *row;                   //current row
00256   BLOBNBOX_IT blob_it;           //blobs
00257   float right;                   //end of row
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 }

void draw_occupation ( INT32  xleft,
INT32  ybottom,
INT32  min_y,
INT32  max_y,
INT32  occupation[],
INT32  thresholds[] 
)

Draw projection

Draw the row occupation with points above the threshold in white and points below the threshold in black.

Definition at line 203 of file drawtord.cpp.

References BLUE, draw2d, line_color_index, move2d, STEEL_BLUE, to_win, and WHITE.

Referenced by delete_non_dropout_rows().

00209   {
00210   INT32 line_index;              //pixel coord
00211   COLOUR colour;                 //of histogram
00212   float fleft = (float) xleft;   //float version
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 }

void plot_blob_list ( WINDOW  win,
BLOBNBOX_LIST *  list,
COLOUR  body_colour,
COLOUR  child_colour 
)

Draw a list of blobs.

Definition at line 97 of file drawtord.cpp.

Referenced by cleanup_rows(), filter_blobs(), plot_parallel_row(), and plot_to_row().

00102                      {
00103   BLOBNBOX_IT it = list;         //iterator
00104 
00105   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00106     it.data ()->plot (win, body_colour, child_colour);
00107   }
00108 }

void plot_box_list ( WINDOW  win,
BLOBNBOX_LIST *  list,
COLOUR  body_colour 
)

Draw a list of bounding boxes for blobs.

Definition at line 114 of file drawtord.cpp.

References INT_HOLLOW, interior_style, perimeter_color_index, and TRUE.

Referenced by filter_blobs().

00118                     {
00119   BLOBNBOX_IT it = list;         //iterator
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 }

void plot_fp_cells ( WINDOW  win,
COLOUR  colour,
BLOBNBOX_IT *  blob_it,
INT16  pitch,
INT16  blob_count,
STATS projection,
INT16  projection_left,
INT16  projection_right,
float  projection_scale 
)

Make a list of fixed pitch cuts and draw them.

Definition at line 354 of file drawtord.cpp.

References BOX::bottom(), box_next(), check_pitch_sync(), check_pitch_sync2(), draw2d, line_color_index, move2d, FPSEGPT::position(), projection, seg_list, BOX::top(), and WHITE.

Referenced by plot_word_decisions().

00363                                            {
00364   INT16 occupation;              //occupied cells
00365   BOX word_box;                  //bounding box
00366   FPSEGPT_LIST seg_list;         //list of cuts
00367   FPSEGPT_IT seg_it;
00368   FPSEGPT *segpt;                //current point
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 }

void plot_fp_cells2 ( WINDOW  win,
COLOUR  colour,
TO_ROW row,
FPSEGPT_LIST *  seg_list 
)

Make a list of fixed pitch cuts and draw them.

Definition at line 395 of file drawtord.cpp.

References TO_ROW::blob_list(), BOX::bottom(), box_next(), draw2d, line_color_index, move2d, FPSEGPT::position(), BOX::top(), and WHITE.

Referenced by compute_pitch_sd(), compute_pitch_sd2(), and print_pitch_sd().

00400                      {
00401   BOX word_box;                  //bounding box
00402   FPSEGPT_IT seg_it = seg_list;
00403                                  //blobs in row
00404   BLOBNBOX_IT blob_it = row->blob_list ();
00405   FPSEGPT *segpt;                //current point
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 }

void plot_parallel_row ( TO_ROW row,
float  gradient,
INT32  left,
COLOUR  colour,
FCOORD  rotation 
)

Draw the blobs of a row in a given colour and draw the line fit.

Definition at line 163 of file drawtord.cpp.

References TO_ROW::blob_list(), BROWN, draw2d, line_color_index, TO_ROW::max_y(), TO_ROW::min_y(), move2d, TO_ROW::parallel_c(), plot_blob_list(), rotation, and to_win.

Referenced by delete_non_dropout_rows(), expand_rows(), and fit_parallel_rows().

00169                         {
00170   FCOORD plot_pt;                //point to plot
00171                                  //blobs
00172   BLOBNBOX_IT it = row->blob_list ();
00173   float fleft = (float) left;    //floating version
00174   float right;                   //end of row
00175 
00176   //      left=it.data()->bounding_box().left();
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 }

void plot_row_cells ( WINDOW  win,
COLOUR  colour,
TO_ROW row,
float  xshift,
ICOORDELT_LIST *  cells 
)

Make a list of fixed pitch cuts and draw them.

Definition at line 425 of file drawtord.cpp.

References TO_ROW::blob_list(), BOX::bottom(), box_next(), draw2d, line_color_index, move2d, and BOX::top().

Referenced by try_doc_fixed().

00431                      {
00432   BOX word_box;                  //bounding box
00433   ICOORDELT_IT cell_it = cells;
00434                                  //blobs in row
00435   BLOBNBOX_IT blob_it = row->blob_list ();
00436   ICOORDELT *cell;               //current 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 }

void plot_to_row ( TO_ROW row,
COLOUR  colour,
FCOORD  rotation 
)

Draw the blobs of a row in a given colour and draw the line fit.

Definition at line 132 of file drawtord.cpp.

References TO_ROW::blob_list(), BROWN, draw2d, TO_ROW::line_c(), line_color_index, TO_ROW::line_m(), move2d, TO_ROW::parallel_c(), plot_blob_list(), rotation, to_win, and tprintf().

Referenced by make_initial_textrows().

00136                   {
00137   FCOORD plot_pt;                //point to plot
00138                                  //blobs
00139   BLOBNBOX_IT it = row->blob_list ();
00140   float left, right;             //end of row
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 }

void plot_word_decisions ( WINDOW  win,
INT16  pitch,
TO_ROW row 
)

Plot a row with words in different colours and fuzzy spaces highlighted.

Definition at line 283 of file drawtord.cpp.

References BLACK, blob_count, TO_ROW::blob_list(), BOX::bottom(), CORAL, FALSE, fill_color_index, GOLDENROD, INT_SOLID, interior_style, BOX::left(), MAGENTA, MAX_INT16, TO_ROW::max_nonspace, TO_ROW::min_space, NULL, plot_fp_cells(), TO_ROW::projection, TO_ROW::projection_left, TO_ROW::projection_right, rectangle, RED, BOX::right(), TO_ROW::space_threshold, BOX::top(), and TO_ROW::xheight.

Referenced by plot_fp_word(), set_row_spaces(), and to_spacing().

00287                           {
00288   COLOUR colour = MAGENTA;       //current colour
00289   COLOUR rect_colour;            //fuzzy colour
00290   INT32 prev_x;                  //end of prev blob
00291   INT16 blob_count;              //blobs in word
00292   BLOBNBOX *blob;                //current blob
00293   BOX blob_box;                  //bounding box
00294                                  //iterator
00295   BLOBNBOX_IT blob_it = row->blob_list ();
00296   BLOBNBOX_IT start_it = blob_it;//word start
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                                  //draw it
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 }


Variable Documentation

EXTERN FILE* to_debug = NULL

Definition at line 49 of file drawtord.cpp.

Referenced by create_todebug_win().

EXTERN WINDOW to_win = NO_WINDOW

Definition at line 48 of file drawtord.cpp.

Referenced by assign_blobs_to_rows(), cleanup_rows(), close_to_win(), compute_fixed_pitch(), compute_pitch_sd(), compute_pitch_sd2(), create_to_win(), draw_meanlines(), draw_occupation(), expand_rows(), filter_blobs(), find_repeated_chars(), find_textlines(), make_initial_textrows(), make_spline_rows(), mark_gap(), plot_fp_word(), plot_parallel_row(), plot_to_row(), pre_associate_blobs(), print_pitch_sd(), reduced_box_next(), set_row_spaces(), to_spacing(), and try_doc_fixed().


Generated on Wed Feb 28 19:49:24 2007 for Tesseract by  doxygen 1.5.1