Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 ()
 
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)
 
void plot (ScrollView *window, inT32 serial, ScrollView::Color colour)
 
void show (IMAGE *image, ScrollView *window)
 
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 31 of file ocrblock.h.

Constructor & Destructor Documentation

BLOCK::BLOCK ( )
inline

Definition at line 37 of file ocrblock.h.

38  : re_rotation_(1.0f, 0.0f),
39  classify_rotation_(1.0f, 0.0f),
40  skew_(1.0f, 0.0f) {
41  right_to_left_ = false;
42  hand_poly = NULL;
43  }
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
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 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
PDBLK()
empty constructor
Definition: pdblock.h:41
ICOORDELT_LIST leftside
Definition: pdblock.h:118
const char * name() const
return filename
Definition: ocrblock.h:107
inT16 kern() const
return kerning
Definition: ocrblock.h:95
inT16 space() const
return spacing
Definition: ocrblock.h:103
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
BOOL8 prop() const
return proportional
Definition: ocrblock.h:81
BLOCK::~BLOCK ( )
inline

Definition at line 53 of file ocrblock.h.

53  {
54  }

Member Function Documentation

C_BLOB_LIST* BLOCK::blob_list ( )
inline

get blobs

Definition at line 133 of file ocrblock.h.

133  {
134  return &c_blobs;
135  }
float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 114 of file ocrblock.h.

114  {
115  return cell_over_xheight_;
116  }
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 159 of file ocrblock.cpp.

159  { // check prop
160  // tprintf("Missing FFT fixed pitch stuff!\n");
161  pitch = -1;
162 }
FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 145 of file ocrblock.h.

145  {
146  return classify_rotation_; // Apply this before classifying.
147  }
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 121 of file ocrblock.cpp.

121  { // squash it up
122  #define ROW_SPACING 5
123 
124  ROW_IT row_it(&rows);
125  ROW *row;
126  ICOORD row_spacing (0, ROW_SPACING);
127 
128  ICOORDELT_IT icoordelt_it;
129 
130  sort_rows();
131 
132  box = TBOX (box.topleft (), box.topleft ());
134  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
135  row = row_it.data ();
136  row->move (box.botleft () - row_spacing -
137  row->bounding_box ().topleft ());
138  box += row->bounding_box ();
139  }
140 
141  leftside.clear ();
142  icoordelt_it.set_to_list (&leftside);
143  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.bottom ()));
144  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.top ()));
145  rightside.clear ();
146  icoordelt_it.set_to_list (&rightside);
147  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.bottom ()));
148  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.top ()));
149 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
ICOORD topleft() const
Definition: rect.h:89
inT16 left() const
Definition: rect.h:67
Definition: rect.h:29
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:107
inT16 right() const
Definition: rect.h:74
ICOORDELT_LIST leftside
Definition: pdblock.h:118
void move_bottom_edge(const inT16 y)
Definition: rect.h:126
Definition: ocrrow.h:32
void move(const ICOORD vec)
Definition: ocrrow.cpp:138
inT16 top() const
Definition: rect.h:53
const ICOORD & botleft() const
Definition: rect.h:81
#define ROW_SPACING
integer coordinate
Definition: points.h:30
TBOX bounding_box() const
Definition: ocrrow.h:85
TBOX box
Definition: pdblock.h:120
inT16 bottom() const
Definition: rect.h:60
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 171 of file ocrblock.cpp.

173  {
174  box.move (vec);
175  compress();
176 }
void move(const ICOORD vec)
Definition: rect.h:146
void compress()
shrink white space
Definition: ocrblock.cpp:121
TBOX box
Definition: pdblock.h:120
void BLOCK::compute_row_margins ( )

Definition at line 322 of file ocrblock.cpp.

322  {
323  if (row_list()->empty() || row_list()->singleton()) {
324  return;
325  }
326 
327  // If Layout analysis was not called, default to this.
328  POLY_BLOCK rect_block(bounding_box(), PT_FLOWING_TEXT);
329  POLY_BLOCK *pblock = &rect_block;
330  if (poly_block() != NULL) {
331  pblock = poly_block();
332  }
333 
334  // Step One: Determine if there is a drop-cap.
335  // TODO(eger): Fix up drop cap code for RTL languages.
336  ROW_IT r_it(row_list());
337  ROW *first_row = r_it.data();
338  ROW *second_row = r_it.data_relative(1);
339 
340  // initialize the bottom of a fictitious drop cap far above the first line.
341  int drop_cap_bottom = first_row->bounding_box().top() +
342  first_row->bounding_box().height();
343  int drop_cap_right = first_row->bounding_box().left();
344  int mid_second_line = second_row->bounding_box().top() -
345  second_row->bounding_box().height() / 2;
346  WERD_IT werd_it(r_it.data()->word_list()); // words of line one
347  if (!werd_it.empty()) {
348  C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
349  for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
350  cblob_it.forward()) {
351  TBOX bbox = cblob_it.data()->bounding_box();
352  if (bbox.bottom() <= mid_second_line) {
353  // we found a real drop cap
354  first_row->set_has_drop_cap(true);
355  if (drop_cap_bottom > bbox.bottom())
356  drop_cap_bottom = bbox.bottom();
357  if (drop_cap_right < bbox.right())
358  drop_cap_right = bbox.right();
359  }
360  }
361  }
362 
363  // Step Two: Calculate the margin from the text of each row to the block
364  // (or drop-cap) boundaries.
365  PB_LINE_IT lines(pblock);
366  r_it.set_to_list(row_list());
367  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
368  ROW *row = r_it.data();
369  TBOX row_box = row->bounding_box();
370  int left_y = row->base_line(row_box.left()) + row->x_height();
371  int left_margin;
372  ICOORDELT_LIST *segments = lines.get_line(left_y);
373  LeftMargin(segments, row_box.left(), &left_margin);
374  delete segments;
375 
376  if (row_box.top() >= drop_cap_bottom) {
377  int drop_cap_distance = row_box.left() - row->space() - drop_cap_right;
378  if (drop_cap_distance < 0)
379  drop_cap_distance = 0;
380  if (drop_cap_distance < left_margin)
381  left_margin = drop_cap_distance;
382  }
383 
384  int right_y = row->base_line(row_box.right()) + row->x_height();
385  int right_margin;
386  segments = lines.get_line(right_y);
387  RightMargin(segments, row_box.right(), &right_margin);
388  delete segments;
389  row->set_lmargin(left_margin);
390  row->set_rmargin(right_margin);
391  }
392 }
void set_rmargin(inT16 rmargin)
Definition: ocrrow.h:92
bool LeftMargin(ICOORDELT_LIST *segments, int x, int *margin)
Definition: ocrblock.cpp:244
void set_has_drop_cap(bool has)
Definition: ocrrow.h:102
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:121
Definition: rect.h:29
inT16 right() const
Definition: rect.h:74
bool RightMargin(ICOORDELT_LIST *segments, int x, int *margin)
Definition: ocrblock.cpp:274
inT32 space() const
Definition: ocrrow.h:76
float base_line(float xpos) const
Definition: ocrrow.h:56
Definition: ocrrow.h:32
POLY_BLOCK * poly_block() const
Definition: pdblock.h:62
inT16 top() const
Definition: rect.h:53
void set_lmargin(inT16 lmargin)
Definition: ocrrow.h:89
float x_height() const
Definition: ocrrow.h:61
TBOX bounding_box() const
Definition: ocrrow.h:85
const TBOX & bounding_box() const
get real box
Definition: pdblock.h:76
inT16 height() const
Definition: rect.h:97
inT16 bottom() const
Definition: rect.h:60
inT32 BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 91 of file ocrblock.h.

91  {
92  return pitch;
93  }
inT16 BLOCK::font ( ) const
inline

return font class

Definition at line 99 of file ocrblock.h.

99  {
100  return font_class;
101  }
inT16 BLOCK::kern ( ) const
inline

return kerning

Definition at line 95 of file ocrblock.h.

95  {
96  return kerning;
97  }
const ICOORD& BLOCK::median_size ( ) const
inline

Definition at line 157 of file ocrblock.h.

157  {
158  return median_size_;
159  }
const char* BLOCK::name ( ) const
inline

return filename

Definition at line 107 of file ocrblock.h.

107  {
108  return filename.string ();
109  }
BLOCK & BLOCK::operator= ( const BLOCK source)

BLOCK::operator=

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

Definition at line 217 of file ocrblock.cpp.

219  {
220  this->ELIST_LINK::operator= (source);
221  this->PDBLK::operator= (source);
222  proportional = source.proportional;
223  kerning = source.kerning;
224  spacing = source.spacing;
225  filename = source.filename; //STRINGs assign ok
226  if (!rows.empty ())
227  rows.clear ();
228  re_rotation_ = source.re_rotation_;
229  classify_rotation_ = source.classify_rotation_;
230  skew_ = source.skew_;
231  return *this;
232 }
PDBLK & operator=(const PDBLK &source)
Definition: pdblock.cpp:269
void operator=(const ELIST_LINK &)
Definition: elst.h:102
PARA_LIST* BLOCK::para_list ( )
inline

Definition at line 129 of file ocrblock.h.

129  {
130  return &paras_;
131  }
void BLOCK::print ( FILE *  fp,
BOOL8  dump 
)

dump whole table

BLOCK::print

Print the info on a block

Definition at line 185 of file ocrblock.cpp.

188  {
189  ICOORDELT_IT it = &leftside; //iterator
190 
191  box.print ();
192  tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
193  tprintf ("Kerning= %d\n", kerning);
194  tprintf ("Spacing= %d\n", spacing);
195  tprintf ("Fixed_pitch=%d\n", pitch);
196  tprintf ("Filename= %s\n", filename.string ());
197 
198  if (dump) {
199  tprintf ("Left side coords are:\n");
200  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
201  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
202  tprintf ("\n");
203  tprintf ("Right side coords are:\n");
204  it.set_to_list (&rightside);
205  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
206  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
207  tprintf ("\n");
208  }
209 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
ICOORDELT_LIST leftside
Definition: pdblock.h:118
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
TBOX box
Definition: pdblock.h:120
void print() const
Definition: rect.h:263
BOOL8 BLOCK::prop ( ) const
inline

return proportional

Definition at line 81 of file ocrblock.h.

81  {
82  return proportional;
83  }
FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 139 of file ocrblock.h.

139  {
140  return re_rotation_; // How to transform coords back to image.
141  }
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 96 of file ocrblock.cpp.

96  {
98  box = *poly_block()->bounding_box();
99 }
void reflect_in_y_axis()
Definition: polyblk.cpp:212
POLY_BLOCK * poly_block() const
Definition: pdblock.h:62
TBOX box
Definition: pdblock.h:120
TBOX * bounding_box()
Definition: polyblk.h:40
C_BLOB_LIST* BLOCK::reject_blobs ( )
inline

Definition at line 136 of file ocrblock.h.

136  {
137  return &rej_blobs;
138  }
Pix* BLOCK::render_mask ( )
inline

Definition at line 165 of file ocrblock.h.

165  {
166  return PDBLK::render_mask(re_rotation_);
167  }
Pix * render_mask(const FCOORD &rerotation)
Definition: pdblock.cpp:133
bool BLOCK::right_to_left ( ) const
inline

Definition at line 84 of file ocrblock.h.

84  {
85  return right_to_left_;
86  }
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:188
POLY_BLOCK * poly_block() const
Definition: pdblock.h:62
TBOX box
Definition: pdblock.h:120
TBOX * bounding_box()
Definition: polyblk.h:40
ROW_LIST* BLOCK::row_list ( )
inline

get rows

Definition at line 121 of file ocrblock.h.

121  {
122  return &rows;
123  }
void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 117 of file ocrblock.h.

117  {
118  cell_over_xheight_ = ratio;
119  }
void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 148 of file ocrblock.h.

148  {
149  classify_rotation_ = rotation;
150  }
void BLOCK::set_font_class ( inT16  font)
inline

set font class

Definition at line 77 of file ocrblock.h.

77  {
78  font_class = font;
79  }
inT16 font() const
return font class
Definition: ocrblock.h:99
void BLOCK::set_median_size ( int  x,
int  y 
)
inline

Definition at line 160 of file ocrblock.h.

160  {
161  median_size_.set_x(x);
162  median_size_.set_y(y);
163  }
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 142 of file ocrblock.h.

142  {
143  re_rotation_ = rotation;
144  }
void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 87 of file ocrblock.h.

87  {
88  right_to_left_ = value;
89  }
void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 154 of file ocrblock.h.

154  {
155  skew_ = skew;
156  }
FCOORD skew() const
Definition: ocrblock.h:151
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 63 of file ocrblock.h.

66  {
67  proportional = prop;
68  kerning = (inT8) kern;
69  spacing = space;
70  pitch = ch_pitch;
71  }
inT16 kern() const
return kerning
Definition: ocrblock.h:95
inT16 space() const
return spacing
Definition: ocrblock.h:103
SIGNED char inT8
Definition: host.h:98
BOOL8 prop() const
return proportional
Definition: ocrblock.h:81
void BLOCK::set_xheight ( inT32  height)
inline

set char size

Definition at line 73 of file ocrblock.h.

73  {
74  xheight = height;
75  }
FCOORD BLOCK::skew ( ) const
inline

Definition at line 151 of file ocrblock.h.

151  {
152  return skew_; // Direction of true horizontal.
153  }
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 107 of file ocrblock.cpp.

107  { // order on "top"
108  ROW_IT row_it(&rows);
109 
110  row_it.sort (decreasing_top_order);
111 }
int decreasing_top_order(const void *row1, const void *row2)
Definition: ocrblock.cpp:72
inT16 BLOCK::space ( ) const
inline

return spacing

Definition at line 103 of file ocrblock.h.

103  {
104  return spacing;
105  }
inT32 BLOCK::x_height ( ) const
inline

return xheight

Definition at line 111 of file ocrblock.h.

111  {
112  return xheight;
113  }

Friends And Related Function Documentation

friend class BLOCK_RECT_IT
friend

Definition at line 34 of file ocrblock.h.


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