tesseract  4.0.0-1-g2a2b
drawtord.cpp File Reference
#include "pithsync.h"
#include "topitch.h"
#include "drawtord.h"

Go to the source code of this file.

Macros

#define TO_WIN_XPOS   0
 
#define TO_WIN_YPOS   0
 
#define TO_WIN_NAME   "Textord"
 
#define EXTERN
 

Functions

ScrollViewcreate_to_win (ICOORD page_tr)
 
void close_to_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

EXTERN bool textord_show_fixed_cuts = FALSE
 
EXTERN ScrollViewto_win = nullptr
 

Macro Definition Documentation

◆ EXTERN

#define EXTERN

Definition at line 32 of file drawtord.cpp.

◆ TO_WIN_NAME

#define TO_WIN_NAME   "Textord"

Definition at line 29 of file drawtord.cpp.

◆ TO_WIN_XPOS

#define TO_WIN_XPOS   0

Definition at line 27 of file drawtord.cpp.

◆ TO_WIN_YPOS

#define TO_WIN_YPOS   0

Definition at line 28 of file drawtord.cpp.

Function Documentation

◆ close_to_win()

void close_to_win ( )

Definition at line 55 of file drawtord.cpp.

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

◆ create_to_win()

ScrollView* create_to_win ( ICOORD  page_tr)

Definition at line 46 of file drawtord.cpp.

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

◆ draw_meanlines()

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

Definition at line 209 of file drawtord.cpp.

215  {
216  FCOORD plot_pt; //point to plot
217  //rows
218  TO_ROW_IT row_it = block->get_rows ();
219  TO_ROW *row; //current row
220  BLOBNBOX_IT blob_it; //blobs
221  float right; //end of row
222  to_win->Pen(colour);
223  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
224  row = row_it.data ();
225  blob_it.set_to_list (row->blob_list ());
226  blob_it.move_to_last ();
227  right = blob_it.data ()->bounding_box ().right ();
228  plot_pt =
229  FCOORD ((float) left,
230  gradient * left + row->parallel_c () + row->xheight);
231  plot_pt.rotate (rotation);
232  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
233  plot_pt =
234  FCOORD ((float) right,
235  gradient * right + row->parallel_c () + row->xheight);
236  plot_pt.rotate (rotation);
237  to_win->DrawTo (plot_pt.x (), plot_pt.y ());
238  }
239 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
void rotate(const FCOORD vec)
Definition: points.h:764
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
TO_ROW_LIST * get_rows()
Definition: blobbox.h:717
float xheight
Definition: blobbox.h:670
float parallel_c() const
Definition: blobbox.h:592
EXTERN ScrollView * to_win
Definition: drawtord.cpp:37
Definition: points.h:189
float x() const
Definition: points.h:208
void Pen(Color color)
Definition: scrollview.cpp:722
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:612
float y() const
Definition: points.h:211

◆ 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 165 of file drawtord.cpp.

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

◆ plot_box_list()

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

Definition at line 69 of file drawtord.cpp.

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

◆ 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 319 of file drawtord.cpp.

328  {
329  int16_t occupation; //occupied cells
330  TBOX word_box; //bounding box
331  FPSEGPT_LIST seg_list; //list of cuts
332  FPSEGPT_IT seg_it;
333  FPSEGPT *segpt; //current point
334 
335  if (pitsync_linear_version)
336  check_pitch_sync2 (blob_it, blob_count, pitch, 2, projection,
337  projection_left, projection_right,
338  projection_scale, occupation, &seg_list, 0, 0);
339  else
340  check_pitch_sync (blob_it, blob_count, pitch, 2, projection, &seg_list);
341  word_box = blob_it->data ()->bounding_box ();
342  for (; blob_count > 0; blob_count--)
343  word_box += box_next (blob_it);
344  seg_it.set_to_list (&seg_list);
345  for (seg_it.mark_cycle_pt (); !seg_it.cycled_list (); seg_it.forward ()) {
346  segpt = seg_it.data ();
347  if (segpt->faked) {
348  colour = ScrollView::WHITE;
349  win->Pen(colour); }
350  else {
351  win->Pen(colour); }
352  win->Line(segpt->position (), word_box.bottom (),segpt->position (), word_box.top ());
353  }
354 }
Definition: rect.h:34
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:144
TBOX box_next(BLOBNBOX_IT *it)
Definition: blobbox.cpp:637
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:294
int16_t top() const
Definition: rect.h:58
int32_t position()
Definition: pitsync1.h:48
BOOL8 faked
Definition: pitsync1.h:68
void Pen(Color color)
Definition: scrollview.cpp:722
int16_t bottom() const
Definition: rect.h:65
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:534

◆ plot_fp_cells2()

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

Definition at line 363 of file drawtord.cpp.

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

◆ plot_parallel_row()

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

Definition at line 124 of file drawtord.cpp.

130  {
131  FCOORD plot_pt; //point to plot
132  //blobs
133  BLOBNBOX_IT it = row->blob_list ();
134  float fleft = (float) left; //floating version
135  float right; //end of row
136 
137  // left=it.data()->bounding_box().left();
138  it.move_to_last ();
139  right = it.data ()->bounding_box ().right ();
140  plot_blob_list (to_win, row->blob_list (), colour, ScrollView::BROWN);
141  to_win->Pen(colour);
142  plot_pt = FCOORD (fleft, gradient * left + row->max_y ());
143  plot_pt.rotate (rotation);
144  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
145  plot_pt = FCOORD (fleft, gradient * left + row->min_y ());
146  plot_pt.rotate (rotation);
147  to_win->DrawTo(plot_pt.x (), plot_pt.y ());
148  plot_pt = FCOORD (fleft, gradient * left + row->parallel_c ());
149  plot_pt.rotate (rotation);
150  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
151  plot_pt = FCOORD (right, gradient * right + row->parallel_c ());
152  plot_pt.rotate (rotation);
153  to_win->DrawTo(plot_pt.x (), plot_pt.y ());
154 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
void rotate(const FCOORD vec)
Definition: points.h:764
void plot_blob_list(ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:1087
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
float parallel_c() const
Definition: blobbox.h:592
float min_y() const
Definition: blobbox.h:574
EXTERN ScrollView * to_win
Definition: drawtord.cpp:37
Definition: points.h:189
float x() const
Definition: points.h:208
void Pen(Color color)
Definition: scrollview.cpp:722
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:612
float y() const
Definition: points.h:211
float max_y() const
Definition: blobbox.h:571

◆ plot_row_cells()

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

Definition at line 396 of file drawtord.cpp.

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

◆ plot_to_row()

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

Definition at line 90 of file drawtord.cpp.

94  {
95  FCOORD plot_pt; //point to plot
96  //blobs
97  BLOBNBOX_IT it = row->blob_list ();
98  float left, right; //end of row
99 
100  if (it.empty ()) {
101  tprintf ("No blobs in row at %g\n", row->parallel_c ());
102  return;
103  }
104  left = it.data ()->bounding_box ().left ();
105  it.move_to_last ();
106  right = it.data ()->bounding_box ().right ();
107  plot_blob_list (to_win, row->blob_list (), colour, ScrollView::BROWN);
108  to_win->Pen(colour);
109  plot_pt = FCOORD (left, row->line_m () * left + row->line_c ());
110  plot_pt.rotate (rotation);
111  to_win->SetCursor(plot_pt.x (), plot_pt.y ());
112  plot_pt = FCOORD (right, row->line_m () * right + row->line_c ());
113  plot_pt.rotate (rotation);
114  to_win->DrawTo(plot_pt.x (), plot_pt.y ());
115 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
float line_m() const
Definition: blobbox.h:583
void rotate(const FCOORD vec)
Definition: points.h:764
void plot_blob_list(ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)
Definition: blobbox.cpp:1087
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
float line_c() const
Definition: blobbox.h:586
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
float parallel_c() const
Definition: blobbox.h:592
EXTERN ScrollView * to_win
Definition: drawtord.cpp:37
Definition: points.h:189
float x() const
Definition: points.h:208
void Pen(Color color)
Definition: scrollview.cpp:722
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:612
float y() const
Definition: points.h:211

◆ plot_word_decisions()

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

Definition at line 249 of file drawtord.cpp.

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

Variable Documentation

◆ textord_show_fixed_cuts

EXTERN bool textord_show_fixed_cuts = FALSE

"Draw fixed pitch cell boundaries"

Definition at line 35 of file drawtord.cpp.

◆ to_win

EXTERN ScrollView* to_win = nullptr

Definition at line 37 of file drawtord.cpp.