|
tesseract 3.04.01
|
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 // If not NULL, mask_box is filled with the position box of the returned 00093 // mask image. 00094 Pix *render_mask(const FCOORD &rerotation, TBOX *mask_box); 00095 00096 #ifndef GRAPHICS_DISABLED 00097 00098 00099 00100 00101 void plot(ScrollView* window, 00102 inT32 serial, 00103 ScrollView::Color colour); 00104 #endif // GRAPHICS_DISABLED 00105 00108 PDBLK & operator= (const PDBLK & source); 00109 00110 protected: 00111 POLY_BLOCK *hand_poly; //< weird as well 00112 ICOORDELT_LIST leftside; //< left side vertices 00113 ICOORDELT_LIST rightside; //< right side vertices 00114 TBOX box; //< bounding box 00115 int index_; //< Serial number of this block. 00116 }; 00117 00118 class DLLSYM BLOCK_RECT_IT //rectangle iterator 00119 { 00120 public: 00123 BLOCK_RECT_IT(PDBLK *blkptr); 00124 00126 void set_to_block ( 00127 PDBLK * blkptr); //block to iterate 00128 00130 void start_block(); 00131 00133 void forward(); 00134 00136 BOOL8 cycled_rects() { 00137 return left_it.cycled_list () && right_it.cycled_list (); 00138 } 00139 00143 void bounding_box(ICOORD &bleft, 00144 ICOORD &tright) { 00145 //bottom left 00146 bleft = ICOORD (left_it.data ()->x (), ymin); 00147 //top right 00148 tright = ICOORD (right_it.data ()->x (), ymax); 00149 } 00150 00151 private: 00152 inT16 ymin; //< bottom of rectangle 00153 inT16 ymax; //< top of rectangle 00154 PDBLK *block; //< block to iterate 00155 ICOORDELT_IT left_it; //< boundary iterators 00156 ICOORDELT_IT right_it; 00157 }; 00158 00160 class DLLSYM BLOCK_LINE_IT 00161 { 00162 public: 00165 BLOCK_LINE_IT (PDBLK * blkptr) 00166 :rect_it (blkptr) { 00167 block = blkptr; //remember block 00168 } 00169 00172 void set_to_block (PDBLK * blkptr) { 00173 block = blkptr; //remember block 00174 //set iterator 00175 rect_it.set_to_block (blkptr); 00176 } 00177 00181 inT16 get_line(inT16 y, 00182 inT16 &xext); 00183 00184 private: 00185 PDBLK * block; //< block to iterate 00186 BLOCK_RECT_IT rect_it; //< rectangle iterator 00187 }; 00188 00189 int decreasing_top_order(const void *row1, 00190 const void *row2); 00191 #endif