drawtord.cpp

来自「一个google的OCR源码」· C++ 代码 · 共 469 行 · 第 1/2 页

CPP
469
字号
/********************************************************************** * File:        drawtord.cpp  (Formerly drawto.c) * Description: Draw things to do with textord. * Author:		Ray Smith * Created:		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. * **********************************************************************/#include "mfcpch.h"#include          "pithsync.h"#include          "topitch.h"#include          "drawtord.h"#include          "debugwin.h"#define TO_WIN_XPOS     -1       //default window pos#define TO_WIN_YPOS     0#define TO_WIN_NAME     "Textord"                                 //title of window#define DEBUG_WIN_NAME    "TODebug"#define DEBUG_XPOS      0#define DEBUG_YPOS      120#define DEBUG_XSIZE     80#define DEBUG_YSIZE     32#define YMAX        3508#define XMAX        2550#define EXTERNEXTERN BOOL_VAR (textord_show_fixed_cuts, FALSE,"Draw fixed pitch cell boundaries");EXTERN STRING_VAR (to_debugfile, DEBUG_WIN_NAME, "Name of debugfile");EXTERN STRING_VAR (to_smdfile, NO_SMD, "Name of SMD file");EXTERN ScrollView* to_win = NULL;EXTERN FILE *to_debug = NULL;/********************************************************************** * create_to_win * * Create the to window used to show the fit. **********************************************************************/void create_to_win(                //make features win                   ICOORD page_tr  //size of page                  ) {  if (strcmp (to_smdfile.string (), NO_SMD)) {    to_win = new ScrollView (to_smdfile.string (),      0, 0, page_tr.x () + 1, page_tr.y () + 1,      page_tr.x (), page_tr.y ());  }  else {    to_win = new ScrollView (TO_WIN_NAME,      TO_WIN_XPOS, TO_WIN_YPOS, 0, 0,      page_tr.x (),  page_tr.y ());  }}void close_to_win() {  //make features win  if (to_win != NULL && strcmp (to_smdfile.string (), NO_SMD)) {    delete to_win;  }}/********************************************************************** * create_todebug_win * * Create the to window used to show the fit. **********************************************************************/void create_todebug_win() {  //make gradients win  if (strcmp (to_debugfile.string (), DEBUG_WIN_NAME) != 0)    //              create_debug_window();    //      else    to_debug = fopen (to_debugfile.string (), "w");}/********************************************************************** * plot_blob_list * * Draw a list of blobs. **********************************************************************/void plot_blob_list(                      //make gradients win                    ScrollView* win,           //window to draw in                    BLOBNBOX_LIST *list,  //blob list                    ScrollView::Color body_colour,   //colour to draw                    ScrollView::Color child_colour   //colour of child                   ) {  BLOBNBOX_IT it = list;         //iterator  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {    it.data ()->plot (win, body_colour, child_colour);  }}/********************************************************************** * plot_box_list * * Draw a list of blobs. **********************************************************************/void plot_box_list(                      //make gradients win                   ScrollView* win,           //window to draw in                   BLOBNBOX_LIST *list,  //blob list                   ScrollView::Color body_colour    //colour to draw                  ) {  BLOBNBOX_IT it = list;         //iterator  win->Pen(body_colour);  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {    it.data ()->bounding_box ().plot (win);  }}/********************************************************************** * plot_to_row * * Draw the blobs of a row in a given colour and draw the line fit. **********************************************************************/void plot_to_row(                 //draw a row                 TO_ROW *row,     //row to draw                 ScrollView::Color colour,   //colour to draw in                 FCOORD rotation  //rotation for line                ) {  FCOORD plot_pt;                //point to plot                                 //blobs  BLOBNBOX_IT it = row->blob_list ();  float left, right;             //end of row  if (it.empty ()) {    tprintf ("No blobs in row at %g\n", row->parallel_c ());    return;  }  left = it.data ()->bounding_box ().left ();  it.move_to_last ();  right = it.data ()->bounding_box ().right ();  plot_blob_list (to_win, row->blob_list (), colour, ScrollView::BROWN);  to_win->Pen(colour);  plot_pt = FCOORD (left, row->line_m () * left + row->line_c ());  plot_pt.rotate (rotation);  to_win->SetCursor(plot_pt.x (), plot_pt.y ());  plot_pt = FCOORD (right, row->line_m () * right + row->line_c ());  plot_pt.rotate (rotation);  to_win->DrawTo(plot_pt.x (), plot_pt.y ());}/********************************************************************** * plot_parallel_row * * Draw the blobs of a row in a given colour and draw the line fit. **********************************************************************/void plot_parallel_row(                 //draw a row                       TO_ROW *row,     //row to draw                       float gradient,  //gradients of lines                       inT32 left,      //edge of block                       ScrollView::Color colour,   //colour to draw in                       FCOORD rotation  //rotation for line                      ) {  FCOORD plot_pt;                //point to plot                                 //blobs  BLOBNBOX_IT it = row->blob_list ();  float fleft = (float) left;    //floating version  float right;                   //end of row  //      left=it.data()->bounding_box().left();  it.move_to_last ();  right = it.data ()->bounding_box ().right ();  plot_blob_list (to_win, row->blob_list (), colour, ScrollView::BROWN);  to_win->Pen(colour);  plot_pt = FCOORD (fleft, gradient * left + row->max_y ());  plot_pt.rotate (rotation);  to_win->SetCursor(plot_pt.x (), plot_pt.y ());  plot_pt = FCOORD (fleft, gradient * left + row->min_y ());  plot_pt.rotate (rotation);  to_win->DrawTo(plot_pt.x (), plot_pt.y ());  plot_pt = FCOORD (fleft, gradient * left + row->parallel_c ());  plot_pt.rotate (rotation);  to_win->SetCursor(plot_pt.x (), plot_pt.y ());  plot_pt = FCOORD (right, gradient * right + row->parallel_c ());  plot_pt.rotate (rotation);  to_win->DrawTo(plot_pt.x (), plot_pt.y ());}/********************************************************************** * draw_occupation * * Draw the row occupation with points above the threshold in white * and points below the threshold in black. **********************************************************************/voiddraw_occupation (                //draw projectioninT32 xleft,                     //edge of blockinT32 ybottom,                   //bottom of blockinT32 min_y,                     //coordinate limitsinT32 max_y, inT32 occupation[], //projection countsinT32 thresholds[]               //for drop out) {  inT32 line_index;              //pixel coord  ScrollView::Color colour;                 //of histogram  float fleft = (float) xleft;   //float version  colour = ScrollView::WHITE;  to_win->Pen(colour);  to_win->SetCursor(fleft, (float) ybottom);  for (line_index = min_y; line_index <= max_y; line_index++) {    if (occupation[line_index - min_y] < thresholds[line_index - min_y]) {      if (colour != ScrollView::BLUE) {        colour = ScrollView::BLUE;	to_win->Pen(colour);      }    }    else {      if (colour != ScrollView::WHITE) {        colour = ScrollView::WHITE;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?