Tesseract  3.02
BLOCK Class Reference

#include <ocrblock.h>

Inheritance diagram for BLOCK:
ELIST_LINK PDBLK

List of all members.

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
void set_font_class (inT16 font)
 set font class
BOOL8 prop () const
 return proportional
bool right_to_left () const
void set_right_to_left (bool value)
inT32 fixed_pitch () const
 return pitch
inT16 kern () const
 return kerning
inT16 font () const
 return font class
inT16 space () const
 return spacing
const char * name () const
 return filename
inT32 x_height () const
 return xheight
float cell_over_xheight () const
void set_cell_over_xheight (float ratio)
ROW_LIST * row_list ()
 get rows
void compute_row_margins ()
PARA_LIST * para_list ()
C_BLOB_LIST * blob_list ()
 get blobs
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
void compress ()
 shrink white space
void check_pitch ()
 check proportional
void compress (const ICOORD vec)
 shrink white space and move by vector
void print (FILE *fp, BOOL8 dump)
 dump whole table
BLOCKoperator= (const BLOCK &source)

Friends

class BLOCK_RECT_IT

Detailed Description

Definition at line 31 of file ocrblock.h.


Constructor & Destructor Documentation

BLOCK::BLOCK ( ) [inline]

Definition at line 37 of file ocrblock.h.

    : re_rotation_(1.0f, 0.0f),
      classify_rotation_(1.0f, 0.0f),
      skew_(1.0f, 0.0f) {
    right_to_left_ = false;
    hand_poly = NULL;
  }
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.

  : PDBLK (xmin, ymin, xmax, ymax),
    filename(name),
    re_rotation_(1.0f, 0.0f),
    classify_rotation_(1.0f, 0.0f),
    skew_(1.0f, 0.0f) {
  ICOORDELT_IT left_it = &leftside;
  ICOORDELT_IT right_it = &rightside;

  proportional = prop;
  right_to_left_ = false;
  kerning = kern;
  spacing = space;
  font_class = -1;               //not assigned
  cell_over_xheight_ = 2.0f;
  hand_poly = NULL;
  left_it.set_to_list (&leftside);
  right_it.set_to_list (&rightside);
                                 //make default box
  left_it.add_to_end (new ICOORDELT (xmin, ymin));
  left_it.add_to_end (new ICOORDELT (xmin, ymax));
  right_it.add_to_end (new ICOORDELT (xmax, ymin));
  right_it.add_to_end (new ICOORDELT (xmax, ymax));
}
BLOCK::~BLOCK ( ) [inline]

Definition at line 53 of file ocrblock.h.

            {
  }

Member Function Documentation

C_BLOB_LIST* BLOCK::blob_list ( ) [inline]

get blobs

Definition at line 133 of file ocrblock.h.

                           {
    return &c_blobs;
  }
float BLOCK::cell_over_xheight ( ) const [inline]

Definition at line 114 of file ocrblock.h.

                                  {
    return cell_over_xheight_;
  }
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.

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

Definition at line 145 of file ocrblock.h.

                                   {
    return classify_rotation_;   // Apply this before classifying.
  }
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.

                     {  // squash it up
  #define           ROW_SPACING 5

  ROW_IT row_it(&rows);
  ROW *row;
  ICOORD row_spacing (0, ROW_SPACING);

  ICOORDELT_IT icoordelt_it;

  sort_rows();

  box = TBOX (box.topleft (), box.topleft ());
  box.move_bottom_edge (ROW_SPACING);
  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
    row = row_it.data ();
    row->move (box.botleft () - row_spacing -
      row->bounding_box ().topleft ());
    box += row->bounding_box ();
  }

  leftside.clear ();
  icoordelt_it.set_to_list (&leftside);
  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.bottom ()));
  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.top ()));
  rightside.clear ();
  icoordelt_it.set_to_list (&rightside);
  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.bottom ()));
  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.top ()));
}
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.

                      {
  box.move (vec);
  compress();
}
void BLOCK::compute_row_margins ( )

Definition at line 322 of file ocrblock.cpp.

                                {
  if (row_list()->empty() || row_list()->singleton()) {
    return;
  }

  // If Layout analysis was not called, default to this.
  POLY_BLOCK rect_block(bounding_box(), PT_FLOWING_TEXT);
  POLY_BLOCK *pblock = &rect_block;
  if (poly_block() != NULL) {
    pblock = poly_block();
  }

  // Step One: Determine if there is a drop-cap.
  //           TODO(eger): Fix up drop cap code for RTL languages.
  ROW_IT r_it(row_list());
  ROW *first_row = r_it.data();
  ROW *second_row = r_it.data_relative(1);

  // initialize the bottom of a fictitious drop cap far above the first line.
  int drop_cap_bottom = first_row->bounding_box().top() +
                        first_row->bounding_box().height();
  int drop_cap_right = first_row->bounding_box().left();
  int mid_second_line = second_row->bounding_box().top() -
                        second_row->bounding_box().height() / 2;
  WERD_IT werd_it(r_it.data()->word_list());  // words of line one
  if (!werd_it.empty()) {
    C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
    for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
         cblob_it.forward()) {
      TBOX bbox = cblob_it.data()->bounding_box();
      if (bbox.bottom() <= mid_second_line) {
        // we found a real drop cap
        first_row->set_has_drop_cap(true);
        if (drop_cap_bottom >  bbox.bottom())
          drop_cap_bottom = bbox.bottom();
        if (drop_cap_right < bbox.right())
          drop_cap_right = bbox.right();
      }
    }
  }

  // Step Two: Calculate the margin from the text of each row to the block
  //           (or drop-cap) boundaries.
  PB_LINE_IT lines(pblock);
  r_it.set_to_list(row_list());
  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
    ROW *row = r_it.data();
    TBOX row_box = row->bounding_box();
    int left_y = row->base_line(row_box.left()) + row->x_height();
    int left_margin;
    ICOORDELT_LIST *segments = lines.get_line(left_y);
    LeftMargin(segments, row_box.left(), &left_margin);
    delete segments;

    if (row_box.top() >= drop_cap_bottom) {
      int drop_cap_distance = row_box.left() - row->space() - drop_cap_right;
      if (drop_cap_distance < 0)
        drop_cap_distance = 0;
      if (drop_cap_distance < left_margin)
        left_margin = drop_cap_distance;
    }

    int right_y = row->base_line(row_box.right()) + row->x_height();
    int right_margin;
    segments = lines.get_line(right_y);
    RightMargin(segments, row_box.right(), &right_margin);
    delete segments;
    row->set_lmargin(left_margin);
    row->set_rmargin(right_margin);
  }
}
inT32 BLOCK::fixed_pitch ( ) const [inline]

return pitch

Definition at line 91 of file ocrblock.h.

                            {
    return pitch;
  }
inT16 BLOCK::font ( ) const [inline]

return font class

Definition at line 99 of file ocrblock.h.

                     {
    return font_class;
  }
inT16 BLOCK::kern ( ) const [inline]

return kerning

Definition at line 95 of file ocrblock.h.

                     {
    return kerning;
  }
const ICOORD& BLOCK::median_size ( ) const [inline]

Definition at line 157 of file ocrblock.h.

                                    {
    return median_size_;
  }
const char* BLOCK::name ( ) const [inline]

return filename

Definition at line 107 of file ocrblock.h.

                           {
    return filename.string ();
  }
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.

  {
  this->ELIST_LINK::operator= (source);
  this->PDBLK::operator= (source);
  proportional = source.proportional;
  kerning = source.kerning;
  spacing = source.spacing;
  filename = source.filename;    //STRINGs assign ok
  if (!rows.empty ())
    rows.clear ();
  re_rotation_ = source.re_rotation_;
  classify_rotation_ = source.classify_rotation_;
  skew_ = source.skew_;
  return *this;
}
PARA_LIST* BLOCK::para_list ( ) [inline]

Definition at line 129 of file ocrblock.h.

                         {
    return &paras_;
  }
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.

                   {
  ICOORDELT_IT it = &leftside;   //iterator

  box.print ();
  tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
  tprintf ("Kerning= %d\n", kerning);
  tprintf ("Spacing= %d\n", spacing);
  tprintf ("Fixed_pitch=%d\n", pitch);
  tprintf ("Filename= %s\n", filename.string ());

  if (dump) {
    tprintf ("Left side coords are:\n");
    for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
      tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
    tprintf ("\n");
    tprintf ("Right side coords are:\n");
    it.set_to_list (&rightside);
    for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
      tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
    tprintf ("\n");
  }
}
BOOL8 BLOCK::prop ( ) const [inline]

return proportional

Definition at line 81 of file ocrblock.h.

                     {
    return proportional;
  }
FCOORD BLOCK::re_rotation ( ) const [inline]

Definition at line 139 of file ocrblock.h.

                             {
    return re_rotation_;         // How to transform coords back to image.
  }
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.

C_BLOB_LIST* BLOCK::reject_blobs ( ) [inline]

Definition at line 136 of file ocrblock.h.

                              {
    return &rej_blobs;
  }
Pix* BLOCK::render_mask ( ) [inline]

Definition at line 165 of file ocrblock.h.

                     {
    return PDBLK::render_mask(re_rotation_);
  }
bool BLOCK::right_to_left ( ) const [inline]

Definition at line 84 of file ocrblock.h.

                             {
    return right_to_left_;
  }
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.

                                         {
  poly_block()->rotate(rotation);
  box = *poly_block()->bounding_box();
}
ROW_LIST* BLOCK::row_list ( ) [inline]

get rows

Definition at line 121 of file ocrblock.h.

                       {
    return &rows;
  }
void BLOCK::set_cell_over_xheight ( float  ratio) [inline]

Definition at line 117 of file ocrblock.h.

                                          {
    cell_over_xheight_ = ratio;
  }
void BLOCK::set_classify_rotation ( const FCOORD rotation) [inline]

Definition at line 148 of file ocrblock.h.

                                                     {
    classify_rotation_ = rotation;
  }
void BLOCK::set_font_class ( inT16  font) [inline]

set font class

Definition at line 77 of file ocrblock.h.

                                  {
    font_class = font;
  }
void BLOCK::set_median_size ( int  x,
int  y 
) [inline]

Definition at line 160 of file ocrblock.h.

                                     {
    median_size_.set_x(x);
    median_size_.set_y(y);
  }
void BLOCK::set_re_rotation ( const FCOORD rotation) [inline]

Definition at line 142 of file ocrblock.h.

                                               {
    re_rotation_ = rotation;
  }
void BLOCK::set_right_to_left ( bool  value) [inline]

Definition at line 87 of file ocrblock.h.

                                     {
    right_to_left_ = value;
  }
void BLOCK::set_skew ( const FCOORD skew) [inline]

Definition at line 154 of file ocrblock.h.

                                    {
    skew_ = skew;
  }
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.

                                 {
    proportional = prop;
    kerning = (inT8) kern;
    spacing = space;
    pitch = ch_pitch;
  }
void BLOCK::set_xheight ( inT32  height) [inline]

set char size

Definition at line 73 of file ocrblock.h.

                                 {
    xheight = height;
  }
FCOORD BLOCK::skew ( ) const [inline]

Definition at line 151 of file ocrblock.h.

                      {
    return skew_;                // Direction of true horizontal.
  }
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.

                      {  // order on "top"
  ROW_IT row_it(&rows);

  row_it.sort (decreasing_top_order);
}
inT16 BLOCK::space ( ) const [inline]

return spacing

Definition at line 103 of file ocrblock.h.

                      {
    return spacing;
  }
inT32 BLOCK::x_height ( ) const [inline]

return xheight

Definition at line 111 of file ocrblock.h.

                         {
    return xheight;
  }

Friends And Related Function Documentation

friend class BLOCK_RECT_IT [friend]

Reimplemented from PDBLK.

Definition at line 34 of file ocrblock.h.


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