Tesseract  3.02
tesseract-ocr/ccstruct/pdblock.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        pdblock.h  (Formerly pdblk.h)
00003  * Description: Page block class definition.
00004  * Author:      Ray Smith
00005  * Created:     Thu Mar 14 17:32:01 GMT 1991
00006  *
00007  * (C) Copyright 1991, Hewlett-Packard Ltd.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef           PDBLOCK_H
00021 #define           PDBLOCK_H
00022 
00023 #include          "clst.h"
00024 #include          "img.h"
00025 #include          "strngs.h"
00026 #include          "polyblk.h"
00027 
00028 #include          "hpddef.h"     //must be last (handpd.dll)
00029 
00030 class DLLSYM PDBLK;              //forward decl
00031 struct Pix;
00032 
00033 CLISTIZEH (PDBLK)
00035 class PDBLK
00036 {
00037   friend class BLOCK_RECT_IT;    //< block iterator
00038 
00039   public:
00041     PDBLK() {
00042       hand_poly = NULL;
00043       index_ = 0;
00044     }
00046     PDBLK(inT16 xmin,  //< bottom left
00047           inT16 ymin,
00048           inT16 xmax,  //< top right
00049           inT16 ymax);
00050 
00054     void set_sides(ICOORDELT_LIST *left,
00055                    ICOORDELT_LIST *right);
00056 
00058     ~PDBLK () {
00059       if (hand_poly) delete hand_poly;
00060     }
00061 
00062     POLY_BLOCK *poly_block() const {
00063       return hand_poly;
00064     }
00066     void set_poly_block(POLY_BLOCK *blk) {
00067       hand_poly = blk;
00068     }
00070     void bounding_box(ICOORD &bottom_left,        //bottom left
00071                       ICOORD &top_right) const {  //topright
00072       bottom_left = box.botleft ();
00073       top_right = box.topright ();
00074     }
00076     const TBOX &bounding_box() const {
00077       return box;
00078     }
00079 
00080     int index() const {
00081       return index_;
00082     }
00083     void set_index(int value) {
00084       index_ = value;
00085     }
00086 
00088     BOOL8 contains(ICOORD pt);
00089 
00091     void move(const ICOORD vec);  // by vector
00092 
00093     // Returns a binary Pix mask with a 1 pixel for every pixel within the
00094     // block. Rotates the coordinate system by rerotation prior to rendering.
00095     Pix* render_mask(const FCOORD& rerotation);
00100     void plot(ScrollView* window,
00101               inT32 serial,
00102               ScrollView::Color colour);
00103 
00107     void show(IMAGE *image,
00108               ScrollView* window);
00109 
00112     PDBLK & operator= (const PDBLK & source);
00113 
00114   protected:
00115     POLY_BLOCK *hand_poly;       //< wierd as well
00116     ICOORDELT_LIST leftside;     //< left side vertices
00117     ICOORDELT_LIST rightside;    //< right side vertices
00118     TBOX box;                    //< bounding box
00119     int index_;                  //< Serial number of this block.
00120 };
00121 
00122 class DLLSYM BLOCK_RECT_IT       //rectangle iterator
00123 {
00124   public:
00127     BLOCK_RECT_IT(PDBLK *blkptr);
00128 
00130     void set_to_block (
00131       PDBLK * blkptr);           //block to iterate
00132 
00134     void start_block();
00135 
00137     void forward();
00138 
00140     BOOL8 cycled_rects() {
00141       return left_it.cycled_list () && right_it.cycled_list ();
00142     }
00143 
00147     void bounding_box(ICOORD &bleft,
00148                       ICOORD &tright) {
00149                                  //bottom left
00150       bleft = ICOORD (left_it.data ()->x (), ymin);
00151                                  //top right
00152       tright = ICOORD (right_it.data ()->x (), ymax);
00153     }
00154 
00155   private:
00156     inT16 ymin;                  //< bottom of rectangle
00157     inT16 ymax;                  //< top of rectangle
00158     PDBLK *block;                //< block to iterate
00159     ICOORDELT_IT left_it;        //< boundary iterators
00160     ICOORDELT_IT right_it;
00161 };
00162 
00164 class DLLSYM BLOCK_LINE_IT
00165 {
00166   public:
00169     BLOCK_LINE_IT (PDBLK * blkptr)
00170     :rect_it (blkptr) {
00171       block = blkptr;            //remember block
00172     }
00173 
00176     void set_to_block (PDBLK * blkptr) {
00177       block = blkptr;            //remember block
00178                                  //set iterator
00179       rect_it.set_to_block (blkptr);
00180     }
00181 
00185     inT16 get_line(inT16 y,
00186                    inT16 &xext);
00187 
00188   private:
00189     PDBLK * block;               //< block to iterate
00190     BLOCK_RECT_IT rect_it;       //< rectangle iterator
00191 };
00192 
00193 int decreasing_top_order(const void *row1,
00194                          const void *row2);
00195 #endif