tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/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          "strngs.h"
00025 #include          "polyblk.h"
00026 
00027 class DLLSYM PDBLK;              //forward decl
00028 struct Pix;
00029 
00030 CLISTIZEH (PDBLK)
00032 class PDBLK
00033 {
00034   friend class BLOCK_RECT_IT;    //< block iterator
00035 
00036   public:
00038     PDBLK() {
00039       hand_poly = NULL;
00040       index_ = 0;
00041     }
00043     PDBLK(inT16 xmin,  //< bottom left
00044           inT16 ymin,
00045           inT16 xmax,  //< top right
00046           inT16 ymax);
00047 
00051     void set_sides(ICOORDELT_LIST *left,
00052                    ICOORDELT_LIST *right);
00053 
00055     ~PDBLK () {
00056       if (hand_poly) delete hand_poly;
00057     }
00058 
00059     POLY_BLOCK *poly_block() const {
00060       return hand_poly;
00061     }
00063     void set_poly_block(POLY_BLOCK *blk) {
00064       hand_poly = blk;
00065     }
00067     void bounding_box(ICOORD &bottom_left,        //bottom left
00068                       ICOORD &top_right) const {  //topright
00069       bottom_left = box.botleft ();
00070       top_right = box.topright ();
00071     }
00073     const TBOX &bounding_box() const {
00074       return box;
00075     }
00076 
00077     int index() const {
00078       return index_;
00079     }
00080     void set_index(int value) {
00081       index_ = value;
00082     }
00083 
00085     BOOL8 contains(ICOORD pt);
00086 
00088     void move(const ICOORD vec);  // by vector
00089 
00090     // Returns a binary Pix mask with a 1 pixel for every pixel within the
00091     // block. Rotates the coordinate system by rerotation prior to rendering.
00092     Pix* render_mask(const FCOORD& rerotation);
00093 
00094     #ifndef GRAPHICS_DISABLED
00095 
00096 
00097 
00098 
00099     void plot(ScrollView* window,
00100               inT32 serial,
00101               ScrollView::Color colour);
00102     #endif  // GRAPHICS_DISABLED
00103 
00106     PDBLK & operator= (const PDBLK & source);
00107 
00108   protected:
00109     POLY_BLOCK *hand_poly;       //< wierd as well
00110     ICOORDELT_LIST leftside;     //< left side vertices
00111     ICOORDELT_LIST rightside;    //< right side vertices
00112     TBOX box;                    //< bounding box
00113     int index_;                  //< Serial number of this block.
00114 };
00115 
00116 class DLLSYM BLOCK_RECT_IT       //rectangle iterator
00117 {
00118   public:
00121     BLOCK_RECT_IT(PDBLK *blkptr);
00122 
00124     void set_to_block (
00125       PDBLK * blkptr);           //block to iterate
00126 
00128     void start_block();
00129 
00131     void forward();
00132 
00134     BOOL8 cycled_rects() {
00135       return left_it.cycled_list () && right_it.cycled_list ();
00136     }
00137 
00141     void bounding_box(ICOORD &bleft,
00142                       ICOORD &tright) {
00143                                  //bottom left
00144       bleft = ICOORD (left_it.data ()->x (), ymin);
00145                                  //top right
00146       tright = ICOORD (right_it.data ()->x (), ymax);
00147     }
00148 
00149   private:
00150     inT16 ymin;                  //< bottom of rectangle
00151     inT16 ymax;                  //< top of rectangle
00152     PDBLK *block;                //< block to iterate
00153     ICOORDELT_IT left_it;        //< boundary iterators
00154     ICOORDELT_IT right_it;
00155 };
00156 
00158 class DLLSYM BLOCK_LINE_IT
00159 {
00160   public:
00163     BLOCK_LINE_IT (PDBLK * blkptr)
00164     :rect_it (blkptr) {
00165       block = blkptr;            //remember block
00166     }
00167 
00170     void set_to_block (PDBLK * blkptr) {
00171       block = blkptr;            //remember block
00172                                  //set iterator
00173       rect_it.set_to_block (blkptr);
00174     }
00175 
00179     inT16 get_line(inT16 y,
00180                    inT16 &xext);
00181 
00182   private:
00183     PDBLK * block;               //< block to iterate
00184     BLOCK_RECT_IT rect_it;       //< rectangle iterator
00185 };
00186 
00187 int decreasing_top_order(const void *row1,
00188                          const void *row2);
00189 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines