tesseract  4.1.1
drawtord.h File Reference
#include "params.h"
#include "scrollview.h"
#include "pitsync1.h"
#include "blobbox.h"

Go to the source code of this file.

Macros

#define NO_SMD   "none"
 

Functions

ScrollViewcreate_to_win (ICOORD page_tr)
 
void close_to_win ()
 
void create_todebug_win ()
 
void plot_box_list (ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour)
 
void plot_to_row (TO_ROW *row, ScrollView::Color colour, FCOORD rotation)
 
void plot_parallel_row (TO_ROW *row, float gradient, int32_t left, ScrollView::Color colour, FCOORD rotation)
 
void draw_occupation (int32_t xleft, int32_t ybottom, int32_t min_y, int32_t max_y, int32_t occupation[], int32_t thresholds[])
 
void draw_meanlines (TO_BLOCK *block, float gradient, int32_t left, ScrollView::Color colour, FCOORD rotation)
 
void plot_word_decisions (ScrollView *win, int16_t pitch, TO_ROW *row)
 
void plot_fp_cells (ScrollView *win, ScrollView::Color colour, BLOBNBOX_IT *blob_it, int16_t pitch, int16_t blob_count, STATS *projection, int16_t projection_left, int16_t projection_right, float projection_scale)
 
void plot_fp_cells2 (ScrollView *win, ScrollView::Color colour, TO_ROW *row, FPSEGPT_LIST *seg_list)
 
void plot_row_cells (ScrollView *win, ScrollView::Color colour, TO_ROW *row, float xshift, ICOORDELT_LIST *cells)
 

Variables

bool textord_show_fixed_cuts = false
 
char * to_debugfile = DEBUG_WIN_NAME
 
char * to_smdfile = "none"
 
ScrollViewto_win
 
FILE * to_debug
 

Macro Definition Documentation

◆ NO_SMD

#define NO_SMD   "none"

Definition at line 27 of file drawtord.h.

Function Documentation

◆ close_to_win()

void close_to_win ( )

Definition at line 53 of file drawtord.cpp.

53  {
54  // to_win is leaked, but this enables the user to view the contents.
55  if (to_win != nullptr) {
56  to_win->Update();
57  }
58 }
static void Update()
Definition: scrollview.cpp:709
ScrollView * to_win
Definition: drawtord.cpp:35

◆ create_to_win()

ScrollView* create_to_win ( ICOORD  page_tr)

Definition at line 44 of file drawtord.cpp.

44  {
45  if (to_win != nullptr) return to_win;
47  page_tr.x() + 1, page_tr.y() + 1,
48  page_tr.x(), page_tr.y(), true);
49  return to_win;
50 }
#define TO_WIN_YPOS
Definition: drawtord.cpp:28
int16_t x() const
access function
Definition: points.h:52
ScrollView * to_win
Definition: drawtord.cpp:35
int16_t y() const
access_function
Definition: points.h:56
#define TO_WIN_XPOS
Definition: drawtord.cpp:27
#define TO_WIN_NAME
Definition: drawtord.cpp:29

◆ create_todebug_win()

void create_todebug_win ( )

◆ draw_meanlines()

void draw_meanlines ( TO_BLOCK block,
float  gradient,
int32_t  left,
ScrollView::Color  colour,
FCOORD  rotation 
)

Definition at line 207 of file drawtord.cpp.

213  {
214  FCOORD plot_pt; //point to plot
215  //rows
216  TO_ROW_IT row_it = block->get_rows ();
217  TO_ROW *row; //current row
218  BLOBNBOX_IT blob_it; //blobs
219  float right; //end of row
220  to_win->Pen(colour);
221  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
222  row = row_it.data ();
223  blob_it.set_to_list (row->blob_list ());
224  blob_it.move_to_last ();
225  right = blob_it.data ()->bounding_box ().right ();
226  plot_pt =
227  FCOORD (static_cast<float>(left),
228  gradient * left + row->parallel_c () + row->xheight);
229  plot_pt.rotate (rotation);
230  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
231  plot_pt =
232  FCOORD (right,
233  gradient * right + row->parallel_c () + row->xheight);
234  plot_pt.rotate (rotation);
235  to_win->DrawTo (plot_pt.x (), plot_pt.y ());
236  }
237 }
TO_ROW_LIST * get_rows()
Definition: blobbox.h:704
Definition: points.h:188
float xheight
Definition: blobbox.h:657
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:600
float y() const
Definition: points.h:210
float x() const
Definition: points.h:207
ScrollView * to_win
Definition: drawtord.cpp:35
void rotate(const FCOORD vec)
Definition: points.h:763
float parallel_c() const
Definition: blobbox.h:580
void Pen(Color color)
Definition: scrollview.cpp:719
void SetCursor(int x, int y)
Definition: scrollview.cpp:519

◆ draw_occupation()

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

Definition at line 163 of file drawtord.cpp.

169  {
170  int32_t line_index; //pixel coord
171  ScrollView::Color colour; //of histogram
172  auto fleft = static_cast<float>(xleft); //float version
173 
174  colour = ScrollView::WHITE;
175  to_win->Pen(colour);
176  to_win->SetCursor(fleft, static_cast<float>(ybottom));
177  for (line_index = min_y; line_index <= max_y; line_index++) {
178  if (occupation[line_index - min_y] < thresholds[line_index - min_y]) {
179  if (colour != ScrollView::BLUE) {
180  colour = ScrollView::BLUE;
181  to_win->Pen(colour);
182  }
183  }
184  else {
185  if (colour != ScrollView::WHITE) {
186  colour = ScrollView::WHITE;
187  to_win->Pen(colour);
188  }
189  }
190  to_win->DrawTo(fleft + occupation[line_index - min_y] / 10.0, static_cast<float>(line_index));
191  }
192  colour=ScrollView::STEEL_BLUE;
193  to_win->Pen(colour);
194  to_win->SetCursor(fleft, static_cast<float>(ybottom));
195  for (line_index = min_y; line_index <= max_y; line_index++) {
196  to_win->DrawTo(fleft + thresholds[line_index - min_y] / 10.0, static_cast<float>(line_index));
197  }
198 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
ScrollView * to_win
Definition: drawtord.cpp:35
void Pen(Color color)
Definition: scrollview.cpp:719
void SetCursor(int x, int y)
Definition: scrollview.cpp:519

◆ plot_box_list()

void plot_box_list ( ScrollView win,
BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour 
)

Definition at line 67 of file drawtord.cpp.

71  {
72  BLOBNBOX_IT it = list; //iterator
73 
74  win->Pen(body_colour);
75  win->Brush(ScrollView::NONE);
76  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
77  it.data ()->bounding_box ().plot (win);
78  }
79 }
void Brush(Color color)
Definition: scrollview.cpp:725
void Pen(Color color)
Definition: scrollview.cpp:719

◆ plot_fp_cells()

void plot_fp_cells ( ScrollView win,
ScrollView::Color  colour,
BLOBNBOX_IT *  blob_it,
int16_t  pitch,
int16_t  blob_count,
STATS projection,
int16_t  projection_left,
int16_t  projection_right,
float  projection_scale 
)

Definition at line 317 of file drawtord.cpp.

326  {
327  int16_t occupation; //occupied cells
328  TBOX word_box; //bounding box
329  FPSEGPT_LIST seg_list; //list of cuts
330  FPSEGPT_IT seg_it;
331  FPSEGPT *segpt; //current point
332 
333  if (pitsync_linear_version)
334  check_pitch_sync2 (blob_it, blob_count, pitch, 2, projection,
335  projection_left, projection_right,
336  projection_scale, occupation, &seg_list, 0, 0);
337  else
338  check_pitch_sync (blob_it, blob_count, pitch, 2, projection, &seg_list);
339  word_box = blob_it->data ()->bounding_box ();
340  for (; blob_count > 0; blob_count--)
341  word_box += box_next (blob_it);
342  seg_it.set_to_list (&seg_list);
343  for (seg_it.mark_cycle_pt (); !seg_it.cycled_list (); seg_it.forward ()) {
344  segpt = seg_it.data ();
345  if (segpt->faked) {
346  colour = ScrollView::WHITE;
347  win->Pen(colour); }
348  else {
349  win->Pen(colour); }
350  win->Line(segpt->position (), word_box.bottom (),segpt->position (), word_box.top ());
351  }
352 }
int32_t position()
Definition: pitsync1.h:48
double check_pitch_sync2(BLOBNBOX_IT *blob_it, int16_t blob_count, int16_t pitch, int16_t pitch_error, STATS *projection, int16_t projection_left, int16_t projection_right, float projection_scale, int16_t &occupation_count, FPSEGPT_LIST *seg_list, int16_t start, int16_t end)
Definition: pithsync.cpp:291
double check_pitch_sync(BLOBNBOX_IT *blob_it, int16_t blob_count, int16_t pitch, int16_t pitch_error, STATS *projection, FPSEGPT_LIST *seg_list)
Definition: pitsync1.cpp:143
TBOX box_next(BLOBNBOX_IT *it)
Definition: blobbox.cpp:636
int16_t bottom() const
Definition: rect.h:65
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:532
Definition: rect.h:34
void Pen(Color color)
Definition: scrollview.cpp:719
int16_t top() const
Definition: rect.h:58
bool faked
Definition: pitsync1.h:67

◆ plot_fp_cells2()

void plot_fp_cells2 ( ScrollView win,
ScrollView::Color  colour,
TO_ROW row,
FPSEGPT_LIST *  seg_list 
)

Definition at line 361 of file drawtord.cpp.

366  {
367  TBOX word_box; //bounding box
368  FPSEGPT_IT seg_it = seg_list;
369  //blobs in row
370  BLOBNBOX_IT blob_it = row->blob_list ();
371  FPSEGPT *segpt; //current point
372 
373  word_box = blob_it.data ()->bounding_box ();
374  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();)
375  word_box += box_next (&blob_it);
376  for (seg_it.mark_cycle_pt (); !seg_it.cycled_list (); seg_it.forward ()) {
377  segpt = seg_it.data ();
378  if (segpt->faked) {
379  colour = ScrollView::WHITE;
380  win->Pen(colour); }
381  else {
382  win->Pen(colour); }
383  win->Line(segpt->position (), word_box.bottom (),segpt->position (), word_box.top ());
384  }
385 }
int32_t position()
Definition: pitsync1.h:48
TBOX box_next(BLOBNBOX_IT *it)
Definition: blobbox.cpp:636
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:600
int16_t bottom() const
Definition: rect.h:65
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:532
Definition: rect.h:34
void Pen(Color color)
Definition: scrollview.cpp:719
int16_t top() const
Definition: rect.h:58
bool faked
Definition: pitsync1.h:67

◆ plot_parallel_row()

void plot_parallel_row ( TO_ROW row,
float  gradient,
int32_t  left,
ScrollView::Color  colour,
FCOORD  rotation 
)

Definition at line 122 of file drawtord.cpp.

128  {
129  FCOORD plot_pt; //point to plot
130  //blobs
131  BLOBNBOX_IT it = row->blob_list ();
132  auto fleft = static_cast<float>(left); //floating version
133  float right; //end of row
134 
135  // left=it.data()->bounding_box().left();
136  it.move_to_last ();
137  right = it.data ()->bounding_box ().right ();
138  plot_blob_list (to_win, row->blob_list (), colour, ScrollView::BROWN);
139  to_win->Pen(colour);
140  plot_pt = FCOORD (fleft, gradient * left + row->max_y ());
141  plot_pt.rotate (rotation);
142  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
143  plot_pt = FCOORD (fleft, gradient * left + row->min_y ());
144  plot_pt.rotate (rotation);
145  to_win->DrawTo(plot_pt.x (), plot_pt.y ());
146  plot_pt = FCOORD (fleft, gradient * left + row->parallel_c ());
147  plot_pt.rotate (rotation);
148  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
149  plot_pt = FCOORD (right, gradient * right + row->parallel_c ());
150  plot_pt.rotate (rotation);
151  to_win->DrawTo(plot_pt.x (), plot_pt.y ());
152 }
Definition: points.h:188
float min_y() const
Definition: blobbox.h:562
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:600
float y() const
Definition: points.h:210
float x() const
Definition: points.h:207
ScrollView * to_win
Definition: drawtord.cpp:35
float max_y() const
Definition: blobbox.h:559
void rotate(const FCOORD vec)
Definition: points.h:763
float parallel_c() const
Definition: blobbox.h:580
void Pen(Color color)
Definition: scrollview.cpp:719
void SetCursor(int x, int y)
Definition: scrollview.cpp:519
void plot_blob_list(ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:1086

◆ plot_row_cells()

void plot_row_cells ( ScrollView win,
ScrollView::Color  colour,
TO_ROW row,
float  xshift,
ICOORDELT_LIST *  cells 
)

Definition at line 394 of file drawtord.cpp.

400  {
401  TBOX word_box; //bounding box
402  ICOORDELT_IT cell_it = cells;
403  //blobs in row
404  BLOBNBOX_IT blob_it = row->blob_list ();
405  ICOORDELT *cell; //current cell
406 
407  word_box = blob_it.data ()->bounding_box ();
408  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();)
409  word_box += box_next (&blob_it);
410  win->Pen(colour);
411  for (cell_it.mark_cycle_pt (); !cell_it.cycled_list (); cell_it.forward ()) {
412  cell = cell_it.data ();
413  win->Line(cell->x () + xshift, word_box.bottom (), cell->x () + xshift, word_box.top ());
414  }
415 }
TBOX box_next(BLOBNBOX_IT *it)
Definition: blobbox.cpp:636
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:600
int16_t x() const
access function
Definition: points.h:52
int16_t bottom() const
Definition: rect.h:65
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:532
Definition: rect.h:34
void Pen(Color color)
Definition: scrollview.cpp:719
int16_t top() const
Definition: rect.h:58

◆ plot_to_row()

void plot_to_row ( TO_ROW row,
ScrollView::Color  colour,
FCOORD  rotation 
)

Definition at line 88 of file drawtord.cpp.

92  {
93  FCOORD plot_pt; //point to plot
94  //blobs
95  BLOBNBOX_IT it = row->blob_list ();
96  float left, right; //end of row
97 
98  if (it.empty ()) {
99  tprintf ("No blobs in row at %g\n", row->parallel_c ());
100  return;
101  }
102  left = it.data ()->bounding_box ().left ();
103  it.move_to_last ();
104  right = it.data ()->bounding_box ().right ();
105  plot_blob_list (to_win, row->blob_list (), colour, ScrollView::BROWN);
106  to_win->Pen(colour);
107  plot_pt = FCOORD (left, row->line_m () * left + row->line_c ());
108  plot_pt.rotate (rotation);
109  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
110  plot_pt = FCOORD (right, row->line_m () * right + row->line_c ());
111  plot_pt.rotate (rotation);
112  to_win->DrawTo(plot_pt.x (), plot_pt.y ());
113 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
Definition: points.h:188
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
float line_m() const
Definition: blobbox.h:571
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:600
float y() const
Definition: points.h:210
float x() const
Definition: points.h:207
ScrollView * to_win
Definition: drawtord.cpp:35
void rotate(const FCOORD vec)
Definition: points.h:763
float parallel_c() const
Definition: blobbox.h:580
float line_c() const
Definition: blobbox.h:574
void Pen(Color color)
Definition: scrollview.cpp:719
void SetCursor(int x, int y)
Definition: scrollview.cpp:519
void plot_blob_list(ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:1086

◆ plot_word_decisions()

void plot_word_decisions ( ScrollView win,
int16_t  pitch,
TO_ROW row 
)

Definition at line 247 of file drawtord.cpp.

251  {
252  ScrollView::Color colour = ScrollView::MAGENTA; //current colour
253  ScrollView::Color rect_colour; //fuzzy colour
254  int32_t prev_x; //end of prev blob
255  int16_t blob_count; //blobs in word
256  BLOBNBOX *blob; //current blob
257  TBOX blob_box; //bounding box
258  //iterator
259  BLOBNBOX_IT blob_it = row->blob_list ();
260  BLOBNBOX_IT start_it = blob_it;//word start
261 
262  rect_colour = ScrollView::BLACK;
263  prev_x = -INT16_MAX;
264  blob_count = 0;
265  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
266  blob = blob_it.data ();
267  blob_box = blob->bounding_box ();
268  if (!blob->joined_to_prev ()
269  && blob_box.left () - prev_x > row->max_nonspace) {
270  if ((blob_box.left () - prev_x >= row->min_space
271  || blob_box.left () - prev_x > row->space_threshold)
272  && blob_count > 0) {
273  if (pitch > 0 && textord_show_fixed_cuts)
274  plot_fp_cells (win, colour, &start_it, pitch, blob_count,
275  &row->projection, row->projection_left,
276  row->projection_right,
278  blob_count = 0;
279  start_it = blob_it;
280  }
281  if (colour == ScrollView::MAGENTA)
282  colour = ScrollView::RED;
283  else
284  colour = static_cast<ScrollView::Color>(colour + 1);
285  if (blob_box.left () - prev_x < row->min_space) {
286  if (blob_box.left () - prev_x > row->space_threshold)
287  rect_colour = ScrollView::GOLDENROD;
288  else
289  rect_colour = ScrollView::CORAL;
290  //fill_color_index(win, rect_colour);
291  win->Brush(rect_colour);
292  win->Rectangle (prev_x, blob_box.bottom (),
293  blob_box.left (), blob_box.top ());
294  }
295  }
296  if (!blob->joined_to_prev())
297  prev_x = blob_box.right();
298  if (blob->cblob () != nullptr)
299  blob->cblob ()->plot (win, colour, colour);
300  if (!blob->joined_to_prev() && blob->cblob() != nullptr)
301  blob_count++;
302  }
303  if (pitch > 0 && textord_show_fixed_cuts && blob_count > 0)
304  plot_fp_cells (win, colour, &start_it, pitch, blob_count,
305  &row->projection, row->projection_left,
306  row->projection_right,
308 }
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:600
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
Definition: stepblob.cpp:536
double textord_projection_scale
Definition: topitch.cpp:52
void Brush(Color color)
Definition: scrollview.cpp:725
float xheight
Definition: blobbox.h:657
const TBOX & bounding_box() const
Definition: blobbox.h:230
STATS projection
Definition: blobbox.h:671
bool joined_to_prev() const
Definition: blobbox.h:256
int16_t left() const
Definition: rect.h:72
int16_t projection_left
Definition: blobbox.h:648
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:600
int32_t min_space
Definition: blobbox.h:663
int16_t bottom() const
Definition: rect.h:65
int32_t max_nonspace
Definition: blobbox.h:664
C_BLOB * cblob() const
Definition: blobbox.h:268
Definition: rect.h:34
void plot_fp_cells(ScrollView *win, ScrollView::Color colour, BLOBNBOX_IT *blob_it, int16_t pitch, int16_t blob_count, STATS *projection, int16_t projection_left, int16_t projection_right, float projection_scale)
Definition: drawtord.cpp:317
int32_t space_threshold
Definition: blobbox.h:665
int16_t projection_right
Definition: blobbox.h:649
int16_t right() const
Definition: rect.h:79
int16_t top() const
Definition: rect.h:58
bool textord_show_fixed_cuts
Definition: drawtord.cpp:33

Variable Documentation

◆ textord_show_fixed_cuts

bool textord_show_fixed_cuts = false

"Draw fixed pitch cell boundaries"

Definition at line 33 of file drawtord.cpp.

◆ to_debug

FILE* to_debug

◆ to_debugfile

char* to_debugfile = DEBUG_WIN_NAME

"Name of debugfile"

◆ to_smdfile

char* to_smdfile = "none"

"Name of SMD file"

◆ to_win

ScrollView* to_win

Definition at line 35 of file drawtord.cpp.