tesseract  4.00.00dev
BLOCK Class Reference

#include <ocrblock.h>

Inheritance diagram for BLOCK:
ELIST_LINK PDBLK

Public Member Functions

 BLOCK ()
 
 BLOCK (const char *name, BOOL8 prop, inT16 kern, inT16 space, inT16 xmin, inT16 ymin, inT16 xmax, inT16 ymax)
 
 ~BLOCK ()
 
void set_stats (BOOL8 prop, inT16 kern, inT16 space, inT16 ch_pitch)
 
void set_xheight (inT32 height)
 set char size More...
 
void set_font_class (inT16 font)
 set font class More...
 
BOOL8 prop () const
 return proportional More...
 
bool right_to_left () const
 
void set_right_to_left (bool value)
 
inT32 fixed_pitch () const
 return pitch More...
 
inT16 kern () const
 return kerning More...
 
inT16 font () const
 return font class More...
 
inT16 space () const
 return spacing More...
 
const char * name () const
 return filename More...
 
inT32 x_height () const
 return xheight More...
 
float cell_over_xheight () const
 
void set_cell_over_xheight (float ratio)
 
ROW_LIST * row_list ()
 get rows More...
 
void compute_row_margins ()
 
PARA_LIST * para_list ()
 
C_BLOB_LIST * blob_list ()
 get blobs More...
 
C_BLOB_LIST * reject_blobs ()
 
FCOORD re_rotation () const
 
void set_re_rotation (const FCOORD &rotation)
 
FCOORD classify_rotation () const
 
void set_classify_rotation (const FCOORD &rotation)
 
FCOORD skew () const
 
void set_skew (const FCOORD &skew)
 
const ICOORDmedian_size () const
 
void set_median_size (int x, int y)
 
Pix * render_mask (TBOX *mask_box)
 
TBOX restricted_bounding_box (bool upper_dots, bool lower_dots) const
 
void reflect_polygon_in_y_axis ()
 
void rotate (const FCOORD &rotation)
 
void sort_rows ()
 decreasing y order More...
 
void compress ()
 shrink white space More...
 
void check_pitch ()
 check proportional More...
 
void compress (const ICOORD vec)
 shrink white space and move by vector More...
 
void print (FILE *fp, BOOL8 dump)
 dump whole table More...
 
BLOCKoperator= (const BLOCK &source)
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 
- Public Member Functions inherited from PDBLK
 PDBLK ()
 empty constructor More...
 
 PDBLK (inT16 xmin, inT16 ymin, inT16 xmax, inT16 ymax)
 simple constructor More...
 
void set_sides (ICOORDELT_LIST *left, ICOORDELT_LIST *right)
 
 ~PDBLK ()
 destructor More...
 
POLY_BLOCKpoly_block () const
 
void set_poly_block (POLY_BLOCK *blk)
 set the poly block More...
 
void bounding_box (ICOORD &bottom_left, ICOORD &top_right) const
 get box More...
 
const TBOXbounding_box () const
 get real box More...
 
int index () const
 
void set_index (int value)
 
BOOL8 contains (ICOORD pt)
 is pt inside block More...
 
void move (const ICOORD vec)
 reposition block More...
 
Pix * render_mask (const FCOORD &rerotation, TBOX *mask_box)
 
void plot (ScrollView *window, inT32 serial, ScrollView::Color colour)
 
PDBLKoperator= (const PDBLK &source)
 

Friends

class BLOCK_RECT_IT
 

Additional Inherited Members

- Protected Attributes inherited from PDBLK
POLY_BLOCKhand_poly
 
ICOORDELT_LIST leftside
 
ICOORDELT_LIST rightside
 
TBOX box
 
int index_
 

Detailed Description

Definition at line 30 of file ocrblock.h.

Constructor & Destructor Documentation

◆ BLOCK() [1/2]

BLOCK::BLOCK ( )
inline

Definition at line 36 of file ocrblock.h.

37  : re_rotation_(1.0f, 0.0f),
38  classify_rotation_(1.0f, 0.0f),
39  skew_(1.0f, 0.0f) {
40  right_to_left_ = false;
41  hand_poly = NULL;
42  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95

◆ BLOCK() [2/2]

BLOCK::BLOCK ( const char *  name,
BOOL8  prop,
inT16  kern,
inT16  space,
inT16  xmin,
inT16  ymin,
inT16  xmax,
inT16  ymax 
)

BLOCK::BLOCK

Constructor for a simple rectangular block.

Definition at line 35 of file ocrblock.cpp.

42  : PDBLK (xmin, ymin, xmax, ymax),
43  filename(name),
44  re_rotation_(1.0f, 0.0f),
45  classify_rotation_(1.0f, 0.0f),
46  skew_(1.0f, 0.0f) {
47  ICOORDELT_IT left_it = &leftside;
48  ICOORDELT_IT right_it = &rightside;
49 
50  proportional = prop;
51  right_to_left_ = false;
52  kerning = kern;
53  spacing = space;
54  font_class = -1; //not assigned
55  cell_over_xheight_ = 2.0f;
56  hand_poly = NULL;
57  left_it.set_to_list (&leftside);
58  right_it.set_to_list (&rightside);
59  //make default box
60  left_it.add_to_end (new ICOORDELT (xmin, ymin));
61  left_it.add_to_end (new ICOORDELT (xmin, ymax));
62  right_it.add_to_end (new ICOORDELT (xmax, ymin));
63  right_it.add_to_end (new ICOORDELT (xmax, ymax));
64 }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95
inT16 kern() const
return kerning
Definition: ocrblock.h:94
BOOL8 prop() const
return proportional
Definition: ocrblock.h:80
const char * filename
Definition: ioapi.h:38
ICOORDELT_LIST leftside
Definition: pdblock.h:96
const char * name() const
return filename
Definition: ocrblock.h:106
inT16 space() const
return spacing
Definition: ocrblock.h:102
ICOORDELT_LIST rightside
Definition: pdblock.h:97
PDBLK()
empty constructor
Definition: pdblock.h:37

◆ ~BLOCK()

BLOCK::~BLOCK ( )
inline

Definition at line 52 of file ocrblock.h.

52  {
53  }

Member Function Documentation

◆ blob_list()

C_BLOB_LIST* BLOCK::blob_list ( )
inline

get blobs

Definition at line 132 of file ocrblock.h.

132  {
133  return &c_blobs;
134  }

◆ cell_over_xheight()

float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 113 of file ocrblock.h.

113  {
114  return cell_over_xheight_;
115  }

◆ check_pitch()

void BLOCK::check_pitch ( )

check proportional

BLOCK::check_pitch

Check whether the block is fixed or prop, set the flag, and set the pitch if it is fixed.

Definition at line 171 of file ocrblock.cpp.

171  { // check prop
172  // tprintf("Missing FFT fixed pitch stuff!\n");
173  pitch = -1;
174 }

◆ classify_rotation()

FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 144 of file ocrblock.h.

144  {
145  return classify_rotation_; // Apply this before classifying.
146  }

◆ compress() [1/2]

void BLOCK::compress ( )

shrink white space

BLOCK::compress

Delete space between the rows. (And maybe one day, compress the rows) Fill space of block from top down, left aligning rows.

Definition at line 133 of file ocrblock.cpp.

133  { // squash it up
134  #define ROW_SPACING 5
135 
136  ROW_IT row_it(&rows);
137  ROW *row;
138  ICOORD row_spacing (0, ROW_SPACING);
139 
140  ICOORDELT_IT icoordelt_it;
141 
142  sort_rows();
143 
144  box = TBOX (box.topleft (), box.topleft ());
146  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
147  row = row_it.data ();
148  row->move (box.botleft () - row_spacing -
149  row->bounding_box ().topleft ());
150  box += row->bounding_box ();
151  }
152 
153  leftside.clear ();
154  icoordelt_it.set_to_list (&leftside);
155  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.bottom ()));
156  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.top ()));
157  rightside.clear ();
158  icoordelt_it.set_to_list (&rightside);
159  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.bottom ()));
160  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.top ()));
161 }
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:119
void move(const ICOORD vec)
Definition: ocrrow.cpp:148
inT16 left() const
Definition: rect.h:68
ICOORD topleft() const
Definition: rect.h:96
TBOX bounding_box() const
Definition: ocrrow.h:85
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
void move_bottom_edge(const inT16 y)
Definition: rect.h:133
inT16 bottom() const
Definition: rect.h:61
const ICOORD & botleft() const
Definition: rect.h:88
ICOORDELT_LIST leftside
Definition: pdblock.h:96
#define ROW_SPACING
Definition: ocrrow.h:32
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97
integer coordinate
Definition: points.h:30

◆ compress() [2/2]

void BLOCK::compress ( const ICOORD  vec)

shrink white space and move by vector

BLOCK::compress

Compress and move in a single operation.

Definition at line 183 of file ocrblock.cpp.

185  {
186  box.move (vec);
187  compress();
188 }
void compress()
shrink white space
Definition: ocrblock.cpp:133
void move(const ICOORD vec)
Definition: rect.h:153
TBOX box
Definition: pdblock.h:98

◆ compute_row_margins()

void BLOCK::compute_row_margins ( )

Definition at line 334 of file ocrblock.cpp.

334  {
335  if (row_list()->empty() || row_list()->singleton()) {
336  return;
337  }
338 
339  // If Layout analysis was not called, default to this.
340  POLY_BLOCK rect_block(bounding_box(), PT_FLOWING_TEXT);
341  POLY_BLOCK *pblock = &rect_block;
342  if (poly_block() != NULL) {
343  pblock = poly_block();
344  }
345 
346  // Step One: Determine if there is a drop-cap.
347  // TODO(eger): Fix up drop cap code for RTL languages.
348  ROW_IT r_it(row_list());
349  ROW *first_row = r_it.data();
350  ROW *second_row = r_it.data_relative(1);
351 
352  // initialize the bottom of a fictitious drop cap far above the first line.
353  int drop_cap_bottom = first_row->bounding_box().top() +
354  first_row->bounding_box().height();
355  int drop_cap_right = first_row->bounding_box().left();
356  int mid_second_line = second_row->bounding_box().top() -
357  second_row->bounding_box().height() / 2;
358  WERD_IT werd_it(r_it.data()->word_list()); // words of line one
359  if (!werd_it.empty()) {
360  C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
361  for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
362  cblob_it.forward()) {
363  TBOX bbox = cblob_it.data()->bounding_box();
364  if (bbox.bottom() <= mid_second_line) {
365  // we found a real drop cap
366  first_row->set_has_drop_cap(true);
367  if (drop_cap_bottom > bbox.bottom())
368  drop_cap_bottom = bbox.bottom();
369  if (drop_cap_right < bbox.right())
370  drop_cap_right = bbox.right();
371  }
372  }
373  }
374 
375  // Step Two: Calculate the margin from the text of each row to the block
376  // (or drop-cap) boundaries.
377  PB_LINE_IT lines(pblock);
378  r_it.set_to_list(row_list());
379  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
380  ROW *row = r_it.data();
381  TBOX row_box = row->bounding_box();
382  int left_y = row->base_line(row_box.left()) + row->x_height();
383  int left_margin;
384  const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments_left(lines.get_line(left_y));
385  LeftMargin(segments_left.get(), row_box.left(), &left_margin);
386 
387  if (row_box.top() >= drop_cap_bottom) {
388  int drop_cap_distance = row_box.left() - row->space() - drop_cap_right;
389  if (drop_cap_distance < 0)
390  drop_cap_distance = 0;
391  if (drop_cap_distance < left_margin)
392  left_margin = drop_cap_distance;
393  }
394 
395  int right_y = row->base_line(row_box.right()) + row->x_height();
396  int right_margin;
397  const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments_right(lines.get_line(right_y));
398  RightMargin(segments_right.get(), row_box.right(), &right_margin);
399  row->set_lmargin(left_margin);
400  row->set_rmargin(right_margin);
401  }
402 }
void set_has_drop_cap(bool has)
Definition: ocrrow.h:105
float x_height() const
Definition: ocrrow.h:61
inT16 left() const
Definition: rect.h:68
void set_rmargin(inT16 rmargin)
Definition: ocrrow.h:95
bool LeftMargin(ICOORDELT_LIST *segments, int x, int *margin)
Definition: ocrblock.cpp:256
TBOX bounding_box() const
Definition: ocrrow.h:85
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
inT16 height() const
Definition: rect.h:104
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61
void set_lmargin(inT16 lmargin)
Definition: ocrrow.h:92
float base_line(float xpos) const
Definition: ocrrow.h:56
const TBOX & bounding_box() const
get real box
Definition: pdblock.h:65
Definition: ocrrow.h:32
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
bool RightMargin(ICOORDELT_LIST *segments, int x, int *margin)
Definition: ocrblock.cpp:286
inT32 space() const
Definition: ocrrow.h:76

◆ fixed_pitch()

inT32 BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 90 of file ocrblock.h.

90  {
91  return pitch;
92  }

◆ font()

inT16 BLOCK::font ( ) const
inline

return font class

Definition at line 98 of file ocrblock.h.

98  {
99  return font_class;
100  }

◆ kern()

inT16 BLOCK::kern ( ) const
inline

return kerning

Definition at line 94 of file ocrblock.h.

94  {
95  return kerning;
96  }

◆ median_size()

const ICOORD& BLOCK::median_size ( ) const
inline

Definition at line 156 of file ocrblock.h.

156  {
157  return median_size_;
158  }

◆ name()

const char* BLOCK::name ( ) const
inline

return filename

Definition at line 106 of file ocrblock.h.

106  {
107  return filename.string ();
108  }
const char * filename
Definition: ioapi.h:38

◆ operator=()

BLOCK & BLOCK::operator= ( const BLOCK source)

BLOCK::operator=

Assignment - duplicate the block structure, but with an EMPTY row list.

Definition at line 229 of file ocrblock.cpp.

231  {
232  this->ELIST_LINK::operator= (source);
233  this->PDBLK::operator= (source);
234  proportional = source.proportional;
235  kerning = source.kerning;
236  spacing = source.spacing;
237  filename = source.filename; //STRINGs assign ok
238  if (!rows.empty ())
239  rows.clear ();
240  re_rotation_ = source.re_rotation_;
241  classify_rotation_ = source.classify_rotation_;
242  skew_ = source.skew_;
243  return *this;
244 }
PDBLK & operator=(const PDBLK &source)
Definition: pdblock.cpp:238
const char * filename
Definition: ioapi.h:38
void operator=(const ELIST_LINK &)
Definition: elst.h:101

◆ para_list()

PARA_LIST* BLOCK::para_list ( )
inline

Definition at line 128 of file ocrblock.h.

128  {
129  return &paras_;
130  }

◆ print()

void BLOCK::print ( FILE *  fp,
BOOL8  dump 
)

dump whole table

BLOCK::print

Print the info on a block

Definition at line 197 of file ocrblock.cpp.

200  {
201  ICOORDELT_IT it = &leftside; //iterator
202 
203  box.print ();
204  tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
205  tprintf ("Kerning= %d\n", kerning);
206  tprintf ("Spacing= %d\n", spacing);
207  tprintf ("Fixed_pitch=%d\n", pitch);
208  tprintf ("Filename= %s\n", filename.string ());
209 
210  if (dump) {
211  tprintf ("Left side coords are:\n");
212  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
213  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
214  tprintf ("\n");
215  tprintf ("Right side coords are:\n");
216  it.set_to_list (&rightside);
217  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
218  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
219  tprintf ("\n");
220  }
221 }
#define tprintf(...)
Definition: tprintf.h:31
const char * filename
Definition: ioapi.h:38
void print() const
Definition: rect.h:270
ICOORDELT_LIST leftside
Definition: pdblock.h:96
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97

◆ prop()

BOOL8 BLOCK::prop ( ) const
inline

return proportional

Definition at line 80 of file ocrblock.h.

80  {
81  return proportional;
82  }

◆ re_rotation()

FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 138 of file ocrblock.h.

138  {
139  return re_rotation_; // How to transform coords back to image.
140  }

◆ reflect_polygon_in_y_axis()

void BLOCK::reflect_polygon_in_y_axis ( )

BLOCK::reflect_polygon_in_y_axis

Reflects the polygon in the y-axis and recompute the bounding_box. Does nothing to any contained rows/words/blobs etc.

Definition at line 108 of file ocrblock.cpp.

108  {
110  box = *poly_block()->bounding_box();
111 }
void reflect_in_y_axis()
Definition: polyblk.cpp:210
TBOX * bounding_box()
Definition: polyblk.h:38
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
TBOX box
Definition: pdblock.h:98

◆ reject_blobs()

C_BLOB_LIST* BLOCK::reject_blobs ( )
inline

Definition at line 135 of file ocrblock.h.

135  {
136  return &rej_blobs;
137  }

◆ render_mask()

Pix* BLOCK::render_mask ( TBOX mask_box)
inline

Definition at line 164 of file ocrblock.h.

164  {
165  return PDBLK::render_mask(re_rotation_, mask_box);
166  }
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:129

◆ restricted_bounding_box()

TBOX BLOCK::restricted_bounding_box ( bool  upper_dots,
bool  lower_dots 
) const

Definition at line 92 of file ocrblock.cpp.

92  {
93  TBOX box;
94  // This is a read-only iteration of the rows in the block.
95  ROW_IT it(const_cast<ROW_LIST*>(&rows));
96  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
97  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
98  }
99  return box;
100 }
Definition: rect.h:30
TBOX box
Definition: pdblock.h:98

◆ right_to_left()

bool BLOCK::right_to_left ( ) const
inline

Definition at line 83 of file ocrblock.h.

83  {
84  return right_to_left_;
85  }

◆ rotate()

void BLOCK::rotate ( const FCOORD rotation)

BLOCK::rotate

Rotate the polygon by the given rotation and recompute the bounding_box.

Definition at line 85 of file ocrblock.cpp.

85  {
86  poly_block()->rotate(rotation);
87  box = *poly_block()->bounding_box();
88 }
void rotate(FCOORD rotation)
Definition: polyblk.cpp:186
TBOX * bounding_box()
Definition: polyblk.h:38
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
TBOX box
Definition: pdblock.h:98

◆ row_list()

ROW_LIST* BLOCK::row_list ( )
inline

get rows

Definition at line 120 of file ocrblock.h.

120  {
121  return &rows;
122  }

◆ set_cell_over_xheight()

void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 116 of file ocrblock.h.

116  {
117  cell_over_xheight_ = ratio;
118  }

◆ set_classify_rotation()

void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 147 of file ocrblock.h.

147  {
148  classify_rotation_ = rotation;
149  }

◆ set_font_class()

void BLOCK::set_font_class ( inT16  font)
inline

set font class

Definition at line 76 of file ocrblock.h.

76  {
77  font_class = font;
78  }
inT16 font() const
return font class
Definition: ocrblock.h:98

◆ set_median_size()

void BLOCK::set_median_size ( int  x,
int  y 
)
inline

Definition at line 159 of file ocrblock.h.

159  {
160  median_size_.set_x(x);
161  median_size_.set_y(y);
162  }
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void set_y(inT16 yin)
rewrite function
Definition: points.h:65

◆ set_re_rotation()

void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 141 of file ocrblock.h.

141  {
142  re_rotation_ = rotation;
143  }

◆ set_right_to_left()

void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 86 of file ocrblock.h.

86  {
87  right_to_left_ = value;
88  }

◆ set_skew()

void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 153 of file ocrblock.h.

153  {
154  skew_ = skew;
155  }
FCOORD skew() const
Definition: ocrblock.h:150

◆ set_stats()

void BLOCK::set_stats ( BOOL8  prop,
inT16  kern,
inT16  space,
inT16  ch_pitch 
)
inline

set space size etc.

Parameters
propproportional
kerninter char size
spaceinter word size
ch_pitchpitch if fixed

Definition at line 62 of file ocrblock.h.

65  {
66  proportional = prop;
67  kerning = (inT8) kern;
68  spacing = space;
69  pitch = ch_pitch;
70  }
inT16 kern() const
return kerning
Definition: ocrblock.h:94
int8_t inT8
Definition: host.h:34
BOOL8 prop() const
return proportional
Definition: ocrblock.h:80
inT16 space() const
return spacing
Definition: ocrblock.h:102

◆ set_xheight()

void BLOCK::set_xheight ( inT32  height)
inline

set char size

Definition at line 72 of file ocrblock.h.

72  {
73  xheight = height;
74  }

◆ skew()

FCOORD BLOCK::skew ( ) const
inline

Definition at line 150 of file ocrblock.h.

150  {
151  return skew_; // Direction of true horizontal.
152  }

◆ sort_rows()

void BLOCK::sort_rows ( )

decreasing y order

BLOCK::sort_rows

Order rows so that they are in order of decreasing Y coordinate

Definition at line 119 of file ocrblock.cpp.

119  { // order on "top"
120  ROW_IT row_it(&rows);
121 
122  row_it.sort (decreasing_top_order);
123 }
int decreasing_top_order(const void *row1, const void *row2)
Definition: ocrblock.cpp:72

◆ space()

inT16 BLOCK::space ( ) const
inline

return spacing

Definition at line 102 of file ocrblock.h.

102  {
103  return spacing;
104  }

◆ x_height()

inT32 BLOCK::x_height ( ) const
inline

return xheight

Definition at line 110 of file ocrblock.h.

110  {
111  return xheight;
112  }

Friends And Related Function Documentation

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

Definition at line 33 of file ocrblock.h.


The documentation for this class was generated from the following files: