tesseract  4.0.0-1-g2a2b
BLOCK Class Reference

#include <ocrblock.h>

Inheritance diagram for BLOCK:
ELIST_LINK

Public Member Functions

 BLOCK ()
 
 BLOCK (const char *name, BOOL8 prop, int16_t kern, int16_t space, int16_t xmin, int16_t ymin, int16_t xmax, int16_t ymax)
 
 ~BLOCK ()=default
 
void set_stats (BOOL8 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...
 
BOOL8 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
 

Friends

class BLOCK_RECT_IT
 

Detailed Description

Definition at line 30 of file ocrblock.h.

Constructor & Destructor Documentation

◆ BLOCK() [1/2]

BLOCK::BLOCK ( )
inline

Definition at line 35 of file ocrblock.h.

36  : re_rotation_(1.0f, 0.0f),
37  classify_rotation_(1.0f, 0.0f),
38  skew_(1.0f, 0.0f) {
39  right_to_left_ = false;
40  pdblk.hand_poly = nullptr;
41  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:96
PDBLK pdblk
Definition: ocrblock.h:192

◆ BLOCK() [2/2]

BLOCK::BLOCK ( const char *  name,
BOOL8  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.

Definition at line 34 of file ocrblock.cpp.

41  : pdblk(xmin, ymin, xmax, ymax),
42  filename(name),
43  re_rotation_(1.0f, 0.0f),
44  classify_rotation_(1.0f, 0.0f),
45  skew_(1.0f, 0.0f) {
46  ICOORDELT_IT left_it = &pdblk.leftside;
47  ICOORDELT_IT right_it = &pdblk.rightside;
48 
49  proportional = prop;
50  right_to_left_ = false;
51  kerning = kern;
52  spacing = space;
53  font_class = -1; //not assigned
54  cell_over_xheight_ = 2.0f;
55  pdblk.hand_poly = nullptr;
56  left_it.set_to_list (&pdblk.leftside);
57  right_it.set_to_list (&pdblk.rightside);
58  //make default box
59  left_it.add_to_end (new ICOORDELT (xmin, ymin));
60  left_it.add_to_end (new ICOORDELT (xmin, ymax));
61  right_it.add_to_end (new ICOORDELT (xmax, ymin));
62  right_it.add_to_end (new ICOORDELT (xmax, ymax));
63 }
int16_t space() const
return spacing
Definition: ocrblock.h:100
POLY_BLOCK * hand_poly
Definition: pdblock.h:96
ICOORDELT_LIST leftside
Definition: pdblock.h:97
ICOORDELT_LIST rightside
Definition: pdblock.h:98
int16_t kern() const
return kerning
Definition: ocrblock.h:92
BOOL8 prop() const
return proportional
Definition: ocrblock.h:78
PDBLK pdblk
Definition: ocrblock.h:192
const char * name() const
return filename
Definition: ocrblock.h:104

◆ ~BLOCK()

BLOCK::~BLOCK ( )
default

Member Function Documentation

◆ blob_list()

C_BLOB_LIST* BLOCK::blob_list ( )
inline

get blobs

Definition at line 130 of file ocrblock.h.

130  {
131  return &c_blobs;
132  }

◆ cell_over_xheight()

float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 111 of file ocrblock.h.

111  {
112  return cell_over_xheight_;
113  }

◆ 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 168 of file ocrblock.cpp.

168  { // check prop
169  // tprintf("Missing FFT fixed pitch stuff!\n");
170  pitch = -1;
171 }

◆ classify_rotation()

FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 142 of file ocrblock.h.

142  {
143  return classify_rotation_; // Apply this before classifying.
144  }

◆ 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 130 of file ocrblock.cpp.

130  { // squash it up
131  #define ROW_SPACING 5
132 
133  ROW_IT row_it(&rows);
134  ROW *row;
135  ICOORD row_spacing (0, ROW_SPACING);
136 
137  ICOORDELT_IT icoordelt_it;
138 
139  sort_rows();
140 
143  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
144  row = row_it.data ();
145  row->move (pdblk.box.botleft () - row_spacing -
146  row->bounding_box ().topleft ());
147  pdblk.box += row->bounding_box ();
148  }
149 
150  pdblk.leftside.clear ();
151  icoordelt_it.set_to_list (&pdblk.leftside);
152  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.left (), pdblk.box.bottom ()));
153  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.left (), pdblk.box.top ()));
154  pdblk.rightside.clear ();
155  icoordelt_it.set_to_list (&pdblk.rightside);
156  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.right (), pdblk.box.bottom ()));
157  icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.right (), pdblk.box.top ()));
158 }
ICOORDELT_LIST leftside
Definition: pdblock.h:97
TBOX box
Definition: pdblock.h:99
void move(const ICOORD vec)
Definition: ocrrow.cpp:148
Definition: rect.h:34
void move_bottom_edge(const int16_t y)
Definition: rect.h:137
int16_t left() const
Definition: rect.h:72
ICOORDELT_LIST rightside
Definition: pdblock.h:98
int16_t top() const
Definition: rect.h:58
integer coordinate
Definition: points.h:32
TBOX bounding_box() const
Definition: ocrrow.h:88
Definition: ocrrow.h:36
const ICOORD & botleft() const
Definition: rect.h:92
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:116
ICOORD topleft() const
Definition: rect.h:100
int16_t right() const
Definition: rect.h:79
#define ROW_SPACING
int16_t bottom() const
Definition: rect.h:65
PDBLK pdblk
Definition: ocrblock.h:192

◆ 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 180 of file ocrblock.cpp.

182  {
183  pdblk.box.move (vec);
184  compress();
185 }
TBOX box
Definition: pdblock.h:99
void move(const ICOORD vec)
Definition: rect.h:157
PDBLK pdblk
Definition: ocrblock.h:192
void compress()
shrink white space
Definition: ocrblock.cpp:130

◆ compute_row_margins()

void BLOCK::compute_row_margins ( )

Definition at line 331 of file ocrblock.cpp.

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

◆ fixed_pitch()

int32_t BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 88 of file ocrblock.h.

88  {
89  return pitch;
90  }

◆ font()

int16_t BLOCK::font ( ) const
inline

return font class

Definition at line 96 of file ocrblock.h.

96  {
97  return font_class;
98  }

◆ kern()

int16_t BLOCK::kern ( ) const
inline

return kerning

Definition at line 92 of file ocrblock.h.

92  {
93  return kerning;
94  }

◆ median_size()

const ICOORD& BLOCK::median_size ( ) const
inline

Definition at line 154 of file ocrblock.h.

154  {
155  return median_size_;
156  }

◆ name()

const char* BLOCK::name ( ) const
inline

return filename

Definition at line 104 of file ocrblock.h.

104  {
105  return filename.string ();
106  }
const char * string() const
Definition: strngs.cpp:196

◆ operator=()

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

BLOCK::operator=

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

Definition at line 226 of file ocrblock.cpp.

228  {
229  this->ELIST_LINK::operator= (source);
230  pdblk = source.pdblk;
231  proportional = source.proportional;
232  kerning = source.kerning;
233  spacing = source.spacing;
234  filename = source.filename; //STRINGs assign ok
235  if (!rows.empty ())
236  rows.clear ();
237  re_rotation_ = source.re_rotation_;
238  classify_rotation_ = source.classify_rotation_;
239  skew_ = source.skew_;
240  return *this;
241 }
void operator=(const ELIST_LINK &)
Definition: elst.h:101
PDBLK pdblk
Definition: ocrblock.h:192

◆ para_list()

PARA_LIST* BLOCK::para_list ( )
inline

Definition at line 126 of file ocrblock.h.

126  {
127  return &paras_;
128  }

◆ print()

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

dump whole table

BLOCK::print

Print the info on a block

Definition at line 194 of file ocrblock.cpp.

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

◆ prop()

BOOL8 BLOCK::prop ( ) const
inline

return proportional

Definition at line 78 of file ocrblock.h.

78  {
79  return proportional;
80  }

◆ re_rotation()

FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 136 of file ocrblock.h.

136  {
137  return re_rotation_; // How to transform coords back to image.
138  }

◆ 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 105 of file ocrblock.cpp.

105  {
108 }
TBOX box
Definition: pdblock.h:99
TBOX * bounding_box()
Definition: polyblk.h:35
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
void reflect_in_y_axis()
Definition: polyblk.cpp:207
PDBLK pdblk
Definition: ocrblock.h:192

◆ reject_blobs()

C_BLOB_LIST* BLOCK::reject_blobs ( )
inline

Definition at line 133 of file ocrblock.h.

133  {
134  return &rej_blobs;
135  }

◆ render_mask()

Pix* BLOCK::render_mask ( TBOX mask_box)
inline

Definition at line 162 of file ocrblock.h.

162  {
163  return pdblk.render_mask(re_rotation_, mask_box);
164  }
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:131
PDBLK pdblk
Definition: ocrblock.h:192

◆ restricted_bounding_box()

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

Definition at line 89 of file ocrblock.cpp.

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

◆ right_to_left()

bool BLOCK::right_to_left ( ) const
inline

Definition at line 81 of file ocrblock.h.

81  {
82  return right_to_left_;
83  }

◆ rotate()

void BLOCK::rotate ( const FCOORD rotation)

BLOCK::rotate

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

Definition at line 82 of file ocrblock.cpp.

82  {
83  pdblk.poly_block()->rotate(rotation);
85 }
TBOX box
Definition: pdblock.h:99
void rotate(FCOORD rotation)
Definition: polyblk.cpp:183
TBOX * bounding_box()
Definition: polyblk.h:35
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
PDBLK pdblk
Definition: ocrblock.h:192

◆ row_list()

ROW_LIST* BLOCK::row_list ( )
inline

get rows

Definition at line 118 of file ocrblock.h.

118  {
119  return &rows;
120  }

◆ set_cell_over_xheight()

void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 114 of file ocrblock.h.

114  {
115  cell_over_xheight_ = ratio;
116  }

◆ set_classify_rotation()

void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 145 of file ocrblock.h.

145  {
146  classify_rotation_ = rotation;
147  }

◆ set_font_class()

void BLOCK::set_font_class ( int16_t  font)
inline

set font class

Definition at line 74 of file ocrblock.h.

74  {
75  font_class = font;
76  }
int16_t font() const
return font class
Definition: ocrblock.h:96

◆ set_median_size()

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

Definition at line 157 of file ocrblock.h.

157  {
158  median_size_.set_x(x);
159  median_size_.set_y(y);
160  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ set_re_rotation()

void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 139 of file ocrblock.h.

139  {
140  re_rotation_ = rotation;
141  }

◆ set_right_to_left()

void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 84 of file ocrblock.h.

84  {
85  right_to_left_ = value;
86  }

◆ set_skew()

void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 151 of file ocrblock.h.

151  {
152  skew_ = skew;
153  }
FCOORD skew() const
Definition: ocrblock.h:148

◆ set_stats()

void BLOCK::set_stats ( BOOL8  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 60 of file ocrblock.h.

63  {
64  proportional = prop;
65  kerning = (int8_t) kern;
66  spacing = space;
67  pitch = ch_pitch;
68  }
int16_t space() const
return spacing
Definition: ocrblock.h:100
int16_t kern() const
return kerning
Definition: ocrblock.h:92
BOOL8 prop() const
return proportional
Definition: ocrblock.h:78

◆ set_xheight()

void BLOCK::set_xheight ( int32_t  height)
inline

set char size

Definition at line 70 of file ocrblock.h.

70  {
71  xheight = height;
72  }

◆ skew()

FCOORD BLOCK::skew ( ) const
inline

Definition at line 148 of file ocrblock.h.

148  {
149  return skew_; // Direction of true horizontal.
150  }

◆ 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 116 of file ocrblock.cpp.

116  { // order on "top"
117  ROW_IT row_it(&rows);
118 
119  row_it.sort (decreasing_top_order);
120 }

◆ space()

int16_t BLOCK::space ( ) const
inline

return spacing

Definition at line 100 of file ocrblock.h.

100  {
101  return spacing;
102  }

◆ x_height()

int32_t BLOCK::x_height ( ) const
inline

return xheight

Definition at line 108 of file ocrblock.h.

108  {
109  return xheight;
110  }

Friends And Related Function Documentation

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

Definition at line 33 of file ocrblock.h.

Member Data Documentation

◆ pdblk

PDBLK BLOCK::pdblk

Definition at line 192 of file ocrblock.h.


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