ccstruct/ocrblock.h

Go to the documentation of this file.
00001 
00020 #ifndef           OCRBLOCK_H
00021 #define           OCRBLOCK_H
00022 
00023 #include          "img.h"
00024 #include          "ocrrow.h"
00025 #include          "pageblk.h"
00026 #include          "pdblock.h"
00027 
00028 class BLOCK;                     //forward decl
00029 
00030 ELISTIZEH_S (BLOCK)
00035 class BLOCK:public ELIST_LINK, public PDBLK
00036 {
00037   friend class BLOCK_RECT_IT;    //block iterator
00038 
00039                                  //block label
00040   friend void scan_hpd_blocks(const char *name,
00041                               PAGE_BLOCK_LIST *page_blocks,  //head of full pag
00042                               INT32 &block_no,               //no of blocks
00043                               BLOCK_IT *block_it);
00044   friend BOOL8 read_vec_file(              //read uscan output
00045                              STRING name,  //basename of file
00046                              INT32 xsize,  //page size //output list
00047                              INT32 ysize,
00048                              BLOCK_LIST *blocks);
00049   friend BOOL8 read_pd_file(              //read uscan output
00050                             STRING name,  //basename of file
00051                             INT32 xsize,  //page size //output list
00052                             INT32 ysize,
00053                             BLOCK_LIST *blocks);
00054 
00055   public:
00056     BLOCK() {  //empty constructor
00057       hand_block = NULL;
00058       hand_poly = NULL;
00059     }
00060     BLOCK(                   //simple constructor
00061           const char *name,  //filename
00062           BOOL8 prop,        //proportional
00063           INT16 kern,        //kerning
00064           INT16 space,       //spacing
00065           INT16 xmin,        //bottom left
00066           INT16 ymin,
00067           INT16 xmax,        //top right
00068           INT16 ymax);
00069 
00070     //    void               set_sides(               //set vertex lists
00071     //    ICOORDELT_LIST     *left,                   //list of left vertices
00072     //    ICOORDELT_LIST     *right);                 //list of right vertices
00073 
00074     ~BLOCK () {                  //destructor
00075     }
00076 
00077     void set_stats(                   //set space size etc.
00078                    BOOL8 prop,        //proportional
00079                    INT16 kern,        //inter char size
00080                    INT16 space,       //inter word size
00081                    INT16 ch_pitch) {  //pitch if fixed
00082       proportional = prop;
00083       kerning = (INT8) kern;
00084       spacing = space;
00085       pitch = ch_pitch;
00086     }
00087     void set_xheight(  //set char size
00088                      INT32 height) {
00089       xheight = height;
00090     }
00091     void set_font_class(  //set font class
00092                         INT16 font) {
00093       font_class = font;
00094     }
00095     //      TEXT_REGION*                   text_region()
00096     //      {
00097     //              return hand_block;
00098     //      }
00099     //      POLY_BLOCK*                    poly_block()
00100     //      {
00101     //              return hand_poly;
00102     //      }
00103     BOOL8 prop() const {  //return proportional
00104       return proportional;
00105     }
00106     INT32 fixed_pitch() const {  //return pitch
00107       return pitch;
00108     }
00109     INT16 kern() const {  //return kerning
00110       return kerning;
00111     }
00112     INT16 font() const {  //return font class
00113       return font_class;
00114     }
00115     INT16 space() const {  //return spacing
00116       return spacing;
00117     }
00118     const char *name() const {  //return filename
00119       return filename.string ();
00120     }
00121     INT32 x_height() const {  //return xheight
00122       return xheight;
00123     }
00124     ROW_LIST *row_list() {  //get rows
00125       return &rows;
00126     }
00127     C_BLOB_LIST *blob_list() {  //get blobs
00128       return &c_blobs;
00129     }
00130     C_BLOB_LIST *reject_blobs() { 
00131       return &rej_blobs;
00132     }
00133     //      void               bounding_box(         //get box
00134     //      ICOORD&            bottom_left,          //bottom left
00135     //      ICOORD&            top_right) const      //topright
00136     //      {
00137     //              bottom_left=box.botleft();
00138     //              top_right=box.topright();
00139     //      }
00140     //      const BOX&         bounding_box() const   //get real box
00141     //      {
00142     //              return box;
00143     //      }
00144 
00145     //      BOOL8              contains(              //is pt inside block
00146     //      ICOORD             pt);
00147 
00148     //      void               move(                  // reposition block
00149     //      const ICOORD       vec);                  // by vector
00150 
00151     void sort_rows();  //decreasing y order
00152 
00153     void compress();  //shrink white space
00154 
00155     void check_pitch();  //check proportional
00156 
00157     void compress(                    //shrink white space
00158                   const ICOORD vec);  //and move by vector
00159 
00160     void print(              //print summary/table
00161                FILE *fp,     //file to print on
00162                BOOL8 dump);  //dump whole table
00163 
00164     //      void             plot(                  //draw histogram
00165     //      WINDOW           window,                //window to draw in
00166     //      INT32            serial,                //serial number
00167     //      COLOUR           colour);               //colour to draw in
00168 
00169     //      void             show(                  //show image
00170     //      IMAGE            *image,                //image to show
00171     //      WINDOW           window);               //window to show in
00172 
00173     void prep_serialise() {  //set ptrs to counts
00174       filename.prep_serialise ();
00175       rows.prep_serialise ();
00176       c_blobs.prep_serialise ();
00177       rej_blobs.prep_serialise ();
00178       leftside.prep_serialise ();
00179       rightside.prep_serialise ();
00180     }
00181 
00182     void dump(  //write external bits
00183               FILE *f) {
00184       filename.dump (f);
00185       rows.dump (f);
00186       c_blobs.dump (f);
00187       rej_blobs.dump (f);
00188       leftside.dump (f);
00189       rightside.dump (f);
00190       if (hand_block != NULL)
00191         hand_block->serialise (f);
00192     }
00193 
00194     void de_dump(  //read external bits
00195                  FILE *f) {
00196       filename.de_dump (f);
00197       rows.de_dump (f);
00198       c_blobs.de_dump (f);
00199       rej_blobs.de_dump (f);
00200       leftside.de_dump (f);
00201       rightside.de_dump (f);
00202       if (hand_block != NULL)
00203         hand_block = TEXT_REGION::de_serialise (f);
00204     }
00205 
00206                                  //assignment
00207     make_serialise (BLOCK) BLOCK & operator= (
00208       const BLOCK & source);     //from this
00209 
00210   private:
00212     BOOL8 proportional;
00214     INT8 kerning;
00216     INT16 spacing;
00218     INT16 pitch;
00220     INT16 font_class;
00222     INT32 xheight;
00224     STRING filename;
00225 
00226     //   TEXT_REGION*           hand_block;              //if it exists
00227     //   POLY_BLOCK*            hand_poly;               //wierd as well
00228 
00230     ROW_LIST rows;
00232     C_BLOB_LIST c_blobs;
00234     C_BLOB_LIST rej_blobs;
00235 
00236     //   ICOORDELT_LIST         leftside;                //left side vertices
00237     //   ICOORDELT_LIST         rightside;               //right side vertices
00238     //   BOX                    box;                     //bounding box
00239 };
00240 
00241 int decreasing_top_order(  //
00242                          const void *row1,
00243                          const void *row2);
00244 #endif

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1