tesseract  4.1.0
BLOCK Class Reference

#include <ocrblock.h>

Inheritance diagram for BLOCK:
ELIST_LINK

Public Member Functions

 BLOCK ()
 
 BLOCK (const char *name, bool prop, int16_t kern, int16_t space, int16_t xmin, int16_t ymin, int16_t xmax, int16_t ymax)
 
 ~BLOCK ()=default
 
void set_stats (bool prop, int16_t kern, int16_t space, int16_t ch_pitch)
 
void set_xheight (int32_t height)
 set char size More...
 
void set_font_class (int16_t font)
 set font class More...
 
bool prop () const
 return proportional More...
 
bool right_to_left () const
 
void set_right_to_left (bool value)
 
int32_t fixed_pitch () const
 return pitch More...
 
int16_t kern () const
 return kerning More...
 
int16_t font () const
 return font class More...
 
int16_t space () const
 return spacing More...
 
const char * name () const
 return filename More...
 
int32_t 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, bool 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 Attributes

PDBLK pdblk
 Page Description Block. More...
 

Friends

class BLOCK_RECT_IT
 

Detailed Description

Definition at line 29 of file ocrblock.h.

Constructor & Destructor Documentation

BLOCK::BLOCK ( )
inline

Definition at line 34 of file ocrblock.h.

35  : re_rotation_(1.0f, 0.0f),
36  classify_rotation_(1.0f, 0.0f),
37  skew_(1.0f, 0.0f) {
38  right_to_left_ = false;
39  pdblk.hand_poly = nullptr;
40  }
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:96
BLOCK::BLOCK ( const char *  name,
bool  prop,
int16_t  kern,
int16_t  space,
int16_t  xmin,
int16_t  ymin,
int16_t  xmax,
int16_t  ymax 
)

BLOCK::BLOCK

Constructor for a simple rectangular block.

Parameters
namefilename
propproportional
kernkerning
spacespacing
xminbottom left
xmaxtop right

Definition at line 31 of file ocrblock.cpp.

38  : pdblk(xmin, ymin, xmax, ymax),
39  filename(name),
40  re_rotation_(1.0f, 0.0f),
41  classify_rotation_(1.0f, 0.0f),
42  skew_(1.0f, 0.0f) {
43  ICOORDELT_IT left_it = &pdblk.leftside;
44  ICOORDELT_IT right_it = &pdblk.rightside;
45 
46  proportional = prop;
47  right_to_left_ = false;
48  kerning = kern;
49  spacing = space;
50  font_class = -1; //not assigned
51  cell_over_xheight_ = 2.0f;
52  pdblk.hand_poly = nullptr;
53  left_it.set_to_list (&pdblk.leftside);
54  right_it.set_to_list (&pdblk.rightside);
55  //make default box
56  left_it.add_to_end (new ICOORDELT (xmin, ymin));
57  left_it.add_to_end (new ICOORDELT (xmin, ymax));
58  right_it.add_to_end (new ICOORDELT (xmax, ymin));
59  right_it.add_to_end (new ICOORDELT (xmax, ymax));
60 }
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:97
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:98
bool prop() const
return proportional
Definition: ocrblock.h:77
int16_t space() const
return spacing
Definition: ocrblock.h:99
const char * name() const
return filename
Definition: ocrblock.h:103
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:96
int16_t kern() const
return kerning
Definition: ocrblock.h:91
BLOCK::~BLOCK ( )
default

Member Function Documentation

C_BLOB_LIST* BLOCK::blob_list ( )
inline

get blobs

Definition at line 129 of file ocrblock.h.

129  {
130  return &c_blobs;
131  }
float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 110 of file ocrblock.h.

110  {
111  return cell_over_xheight_;
112  }
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 165 of file ocrblock.cpp.

165  { // check prop
166  // tprintf("Missing FFT fixed pitch stuff!\n");
167  pitch = -1;
168 }
FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 141 of file ocrblock.h.

141  {
142  return classify_rotation_; // Apply this before classifying.
143  }
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 127 of file ocrblock.cpp.

127  { // squash it up
128  #define ROW_SPACING 5
129 
130  ROW_IT row_it(&rows);
131  ROW *row;
132  ICOORD row_spacing (0, ROW_SPACING);
133 
134  ICOORDELT_IT icoordelt_it;
135 
136  sort_rows();
137 
140  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
141  row = row_it.data ();
142  row->move (pdblk.box.botleft () - row_spacing -
143  row->bounding_box ().topleft ());
144  pdblk.box += row->bounding_box ();
145  }
146 
147  pdblk.leftside.clear ();
148  icoordelt_it.set_to_list (&pdblk.leftside);
149  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.left (), pdblk.box.bottom ()));
150  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.left (), pdblk.box.top ()));
151  pdblk.rightside.clear ();
152  icoordelt_it.set_to_list (&pdblk.rightside);
153  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.right (), pdblk.box.bottom ()));
154  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.right (), pdblk.box.top ()));
155 }
int16_t top() const
Definition: rect.h:58
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:97
Definition: rect.h:34
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:98
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:113
integer coordinate
Definition: points.h:31
#define ROW_SPACING
void move(const ICOORD vec)
Definition: ocrrow.cpp:147
const ICOORD & botleft() const
Definition: rect.h:92
ICOORD topleft() const
Definition: rect.h:100
void move_bottom_edge(const int16_t y)
Definition: rect.h:137
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65
int16_t left() const
Definition: rect.h:72
TBOX bounding_box() const
Definition: ocrrow.h:88
Definition: ocrrow.h:36
TBOX box
bounding box
Definition: pdblock.h:99
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 177 of file ocrblock.cpp.

179  {
180  pdblk.box.move (vec);
181  compress();
182 }
void compress()
shrink white space
Definition: ocrblock.cpp:127
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
void move(const ICOORD vec)
Definition: rect.h:157
TBOX box
bounding box
Definition: pdblock.h:99
void BLOCK::compute_row_margins ( )

Definition at line 328 of file ocrblock.cpp.

328  {
329  if (row_list()->empty() || row_list()->singleton()) {
330  return;
331  }
332 
333  // If Layout analysis was not called, default to this.
335  POLY_BLOCK *pblock = &rect_block;
336  if (pdblk.poly_block() != nullptr) {
337  pblock = pdblk.poly_block();
338  }
339 
340  // Step One: Determine if there is a drop-cap.
341  // TODO(eger): Fix up drop cap code for RTL languages.
342  ROW_IT r_it(row_list());
343  ROW *first_row = r_it.data();
344  ROW *second_row = r_it.data_relative(1);
345 
346  // initialize the bottom of a fictitious drop cap far above the first line.
347  int drop_cap_bottom = first_row->bounding_box().top() +
348  first_row->bounding_box().height();
349  int drop_cap_right = first_row->bounding_box().left();
350  int mid_second_line = second_row->bounding_box().top() -
351  second_row->bounding_box().height() / 2;
352  WERD_IT werd_it(r_it.data()->word_list()); // words of line one
353  if (!werd_it.empty()) {
354  C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
355  for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
356  cblob_it.forward()) {
357  TBOX bbox = cblob_it.data()->bounding_box();
358  if (bbox.bottom() <= mid_second_line) {
359  // we found a real drop cap
360  first_row->set_has_drop_cap(true);
361  if (drop_cap_bottom > bbox.bottom())
362  drop_cap_bottom = bbox.bottom();
363  if (drop_cap_right < bbox.right())
364  drop_cap_right = bbox.right();
365  }
366  }
367  }
368 
369  // Step Two: Calculate the margin from the text of each row to the block
370  // (or drop-cap) boundaries.
371  PB_LINE_IT lines(pblock);
372  r_it.set_to_list(row_list());
373  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
374  ROW *row = r_it.data();
375  TBOX row_box = row->bounding_box();
376  int left_y = row->base_line(row_box.left()) + row->x_height();
377  int left_margin;
378  const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments_left(
379  lines.get_line(left_y));
380  LeftMargin(segments_left.get(), row_box.left(), &left_margin);
381 
382  if (row_box.top() >= drop_cap_bottom) {
383  int drop_cap_distance = row_box.left() - row->space() - drop_cap_right;
384  if (drop_cap_distance < 0)
385  drop_cap_distance = 0;
386  if (drop_cap_distance < left_margin)
387  left_margin = drop_cap_distance;
388  }
389 
390  int right_y = row->base_line(row_box.right()) + row->x_height();
391  int right_margin;
392  const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments_right(
393  lines.get_line(right_y));
394  RightMargin(segments_right.get(), row_box.right(), &right_margin);
395  row->set_lmargin(left_margin);
396  row->set_rmargin(right_margin);
397  }
398 }
int16_t top() const
Definition: rect.h:58
float x_height() const
Definition: ocrrow.h:64
Definition: rect.h:34
void set_lmargin(int16_t lmargin)
Definition: ocrrow.h:95
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
int32_t space() const
Definition: ocrrow.h:79
void set_has_drop_cap(bool has)
Definition: ocrrow.h:108
int16_t height() const
Definition: rect.h:108
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:60
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65
void set_rmargin(int16_t rmargin)
Definition: ocrrow.h:98
float base_line(float xpos) const
Definition: ocrrow.h:59
int16_t left() const
Definition: rect.h:72
TBOX bounding_box() const
Definition: ocrrow.h:88
Definition: ocrrow.h:36
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:117
int32_t BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 87 of file ocrblock.h.

87  {
88  return pitch;
89  }
int16_t BLOCK::font ( ) const
inline

return font class

Definition at line 95 of file ocrblock.h.

95  {
96  return font_class;
97  }
int16_t BLOCK::kern ( ) const
inline

return kerning

Definition at line 91 of file ocrblock.h.

91  {
92  return kerning;
93  }
const ICOORD& BLOCK::median_size ( ) const
inline

Definition at line 153 of file ocrblock.h.

153  {
154  return median_size_;
155  }
const char* BLOCK::name ( ) const
inline

return filename

Definition at line 103 of file ocrblock.h.

103  {
104  return filename.string ();
105  }
const char * string() const
Definition: strngs.cpp:194
BLOCK & BLOCK::operator= ( const BLOCK source)

BLOCK::operator=

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

Definition at line 223 of file ocrblock.cpp.

225  {
226  this->ELIST_LINK::operator= (source);
227  pdblk = source.pdblk;
228  proportional = source.proportional;
229  kerning = source.kerning;
230  spacing = source.spacing;
231  filename = source.filename; //STRINGs assign ok
232  if (!rows.empty ())
233  rows.clear ();
234  re_rotation_ = source.re_rotation_;
235  classify_rotation_ = source.classify_rotation_;
236  skew_ = source.skew_;
237  return *this;
238 }
void operator=(const ELIST_LINK &)
Definition: elst.h:99
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
PARA_LIST* BLOCK::para_list ( )
inline

Definition at line 125 of file ocrblock.h.

125  {
126  return &paras_;
127  }
void BLOCK::print ( FILE *  fp,
bool  dump 
)

dump whole table

BLOCK::print

Print the info on a block

Parameters
fpfile to print on
dumpprint full detail

Definition at line 191 of file ocrblock.cpp.

194  {
195  ICOORDELT_IT it = &pdblk.leftside; //iterator
196 
197  pdblk.box.print ();
198  tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
199  tprintf ("Kerning= %d\n", kerning);
200  tprintf ("Spacing= %d\n", spacing);
201  tprintf ("Fixed_pitch=%d\n", pitch);
202  tprintf ("Filename= %s\n", filename.string ());
203 
204  if (dump) {
205  tprintf ("Left side coords are:\n");
206  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
207  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
208  tprintf ("\n");
209  tprintf ("Right side coords are:\n");
210  it.set_to_list (&pdblk.rightside);
211  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
212  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
213  tprintf ("\n");
214  }
215 }
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:97
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:98
void print() const
Definition: rect.h:278
const char * string() const
Definition: strngs.cpp:194
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:36
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
TBOX box
bounding box
Definition: pdblock.h:99
bool BLOCK::prop ( ) const
inline

return proportional

Definition at line 77 of file ocrblock.h.

77  {
78  return proportional;
79  }
FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 135 of file ocrblock.h.

135  {
136  return re_rotation_; // How to transform coords back to image.
137  }
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 102 of file ocrblock.cpp.

102  {
105 }
TBOX * bounding_box()
Definition: polyblk.h:35
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
void reflect_in_y_axis()
Definition: polyblk.cpp:208
TBOX box
bounding box
Definition: pdblock.h:99
C_BLOB_LIST* BLOCK::reject_blobs ( )
inline

Definition at line 132 of file ocrblock.h.

132  {
133  return &rej_blobs;
134  }
Pix* BLOCK::render_mask ( TBOX mask_box)
inline

Definition at line 161 of file ocrblock.h.

161  {
162  return pdblk.render_mask(re_rotation_, mask_box);
163  }
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:131
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
TBOX BLOCK::restricted_bounding_box ( bool  upper_dots,
bool  lower_dots 
) const

Definition at line 86 of file ocrblock.cpp.

86  {
87  TBOX box;
88  // This is a read-only iteration of the rows in the block.
89  ROW_IT it(const_cast<ROW_LIST*>(&rows));
90  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
91  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
92  }
93  return box;
94 }
Definition: rect.h:34
bool BLOCK::right_to_left ( ) const
inline

Definition at line 80 of file ocrblock.h.

80  {
81  return right_to_left_;
82  }
void BLOCK::rotate ( const FCOORD rotation)

BLOCK::rotate

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

Definition at line 79 of file ocrblock.cpp.

79  {
80  pdblk.poly_block()->rotate(rotation);
82 }
void rotate(FCOORD rotation)
Definition: polyblk.cpp:184
TBOX * bounding_box()
Definition: polyblk.h:35
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:191
TBOX box
bounding box
Definition: pdblock.h:99
ROW_LIST* BLOCK::row_list ( )
inline

get rows

Definition at line 117 of file ocrblock.h.

117  {
118  return &rows;
119  }
void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 113 of file ocrblock.h.

113  {
114  cell_over_xheight_ = ratio;
115  }
void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 144 of file ocrblock.h.

144  {
145  classify_rotation_ = rotation;
146  }
void BLOCK::set_font_class ( int16_t  font)
inline

set font class

Definition at line 73 of file ocrblock.h.

73  {
74  font_class = font;
75  }
int16_t font() const
return font class
Definition: ocrblock.h:95
void BLOCK::set_median_size ( int  x,
int  y 
)
inline

Definition at line 156 of file ocrblock.h.

156  {
157  median_size_.set_x(x);
158  median_size_.set_y(y);
159  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:61
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 138 of file ocrblock.h.

138  {
139  re_rotation_ = rotation;
140  }
void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 83 of file ocrblock.h.

83  {
84  right_to_left_ = value;
85  }
void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 150 of file ocrblock.h.

150  {
151  skew_ = skew;
152  }
FCOORD skew() const
Definition: ocrblock.h:147
void BLOCK::set_stats ( bool  prop,
int16_t  kern,
int16_t  space,
int16_t  ch_pitch 
)
inline

set space size etc.

Parameters
propproportional
kerninter char size
spaceinter word size
ch_pitchpitch if fixed

Definition at line 59 of file ocrblock.h.

62  {
63  proportional = prop;
64  kerning = static_cast<int8_t>(kern);
65  spacing = space;
66  pitch = ch_pitch;
67  }
bool prop() const
return proportional
Definition: ocrblock.h:77
int16_t space() const
return spacing
Definition: ocrblock.h:99
int16_t kern() const
return kerning
Definition: ocrblock.h:91
void BLOCK::set_xheight ( int32_t  height)
inline

set char size

Definition at line 69 of file ocrblock.h.

69  {
70  xheight = height;
71  }
FCOORD BLOCK::skew ( ) const
inline

Definition at line 147 of file ocrblock.h.

147  {
148  return skew_; // Direction of true horizontal.
149  }
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 113 of file ocrblock.cpp.

113  { // order on "top"
114  ROW_IT row_it(&rows);
115 
116  row_it.sort (decreasing_top_order);
117 }
int16_t BLOCK::space ( ) const
inline

return spacing

Definition at line 99 of file ocrblock.h.

99  {
100  return spacing;
101  }
int32_t BLOCK::x_height ( ) const
inline

return xheight

Definition at line 107 of file ocrblock.h.

107  {
108  return xheight;
109  }

Friends And Related Function Documentation

friend class BLOCK_RECT_IT
friend

Definition at line 32 of file ocrblock.h.

Member Data Documentation

PDBLK BLOCK::pdblk

Page Description Block.

Definition at line 191 of file ocrblock.h.


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