tesseract  4.00.00dev
pdblock.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: pdblock.h (Formerly pdblk.h)
3  * Description: Page block class definition.
4  * Author: Ray Smith
5  * Created: Thu Mar 14 17:32:01 GMT 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef PDBLOCK_H
21 #define PDBLOCK_H
22 
23 #include "clst.h"
24 #include "strngs.h"
25 #include "polyblk.h"
26 
27 class DLLSYM PDBLK; //forward decl
28 struct Pix;
29 
32 class PDBLK {
33  friend class BLOCK_RECT_IT; //< block iterator
34 
35  public:
37  PDBLK() {
38  hand_poly = NULL;
39  index_ = 0;
40  }
42  PDBLK(inT16 xmin, //< bottom left
43  inT16 ymin,
44  inT16 xmax, //< top right
45  inT16 ymax);
46 
50  void set_sides(ICOORDELT_LIST *left, ICOORDELT_LIST *right);
51 
53  ~PDBLK() { delete hand_poly; }
54 
55  POLY_BLOCK *poly_block() const { return hand_poly; }
57  void set_poly_block(POLY_BLOCK *blk) { hand_poly = blk; }
59  void bounding_box(ICOORD &bottom_left, // bottom left
60  ICOORD &top_right) const { // topright
61  bottom_left = box.botleft();
62  top_right = box.topright();
63  }
65  const TBOX &bounding_box() const { return box; }
66 
67  int index() const { return index_; }
68  void set_index(int value) { index_ = value; }
69 
71  BOOL8 contains(ICOORD pt);
72 
74  void move(const ICOORD vec); // by vector
75 
76  // Returns a binary Pix mask with a 1 pixel for every pixel within the
77  // block. Rotates the coordinate system by rerotation prior to rendering.
78  // If not NULL, mask_box is filled with the position box of the returned
79  // mask image.
80  Pix *render_mask(const FCOORD &rerotation, TBOX *mask_box);
81 
82 #ifndef GRAPHICS_DISABLED
83  void plot(ScrollView *window, inT32 serial, ScrollView::Color colour);
88 #endif // GRAPHICS_DISABLED
89 
92  PDBLK &operator=(const PDBLK &source);
93 
94  protected:
95  POLY_BLOCK *hand_poly; //< weird as well
96  ICOORDELT_LIST leftside; //< left side vertices
97  ICOORDELT_LIST rightside; //< right side vertices
98  TBOX box; //< bounding box
99  int index_; //< Serial number of this block.
100 };
101 
102 class DLLSYM BLOCK_RECT_IT //rectangle iterator
103 {
104  public:
107  BLOCK_RECT_IT(PDBLK *blkptr);
108 
110  void set_to_block (
111  PDBLK * blkptr); //block to iterate
112 
114  void start_block();
115 
117  void forward();
118 
121  return left_it.cycled_list () && right_it.cycled_list ();
122  }
123 
127  void bounding_box(ICOORD &bleft,
128  ICOORD &tright) {
129  //bottom left
130  bleft = ICOORD (left_it.data ()->x (), ymin);
131  //top right
132  tright = ICOORD (right_it.data ()->x (), ymax);
133  }
134 
135  private:
136  inT16 ymin; //< bottom of rectangle
137  inT16 ymax; //< top of rectangle
138  PDBLK *block; //< block to iterate
139  ICOORDELT_IT left_it; //< boundary iterators
140  ICOORDELT_IT right_it;
141 };
142 
145 {
146  public:
149  BLOCK_LINE_IT (PDBLK * blkptr)
150  :rect_it (blkptr) {
151  block = blkptr; //remember block
152  }
153 
156  void set_to_block (PDBLK * blkptr) {
157  block = blkptr; //remember block
158  //set iterator
159  rect_it.set_to_block (blkptr);
160  }
161 
165  inT16 get_line(inT16 y,
166  inT16 &xext);
167 
168  private:
169  PDBLK * block; //< block to iterate
170  BLOCK_RECT_IT rect_it; //< rectangle iterator
171 };
172 
173 int decreasing_top_order(const void *row1,
174  const void *row2);
175 #endif
Definition: points.h:189
int32_t inT32
Definition: host.h:38
rectangle iterator
Definition: pdblock.h:144
int index() const
Definition: pdblock.h:67
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59
void set_poly_block(POLY_BLOCK *blk)
set the poly block
Definition: pdblock.h:57
class DLLSYM PDBLK
Definition: pdblock.h:27
int decreasing_top_order(const void *row1, const void *row2)
Definition: ocrblock.cpp:72
int16_t inT16
Definition: host.h:36
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:127
BLOCK_LINE_IT(PDBLK *blkptr)
Definition: pdblock.h:149
POLY_BLOCK * hand_poly
Definition: pdblock.h:95
unsigned char BOOL8
Definition: host.h:44
~PDBLK()
destructor
Definition: pdblock.h:53
void set_to_block(PDBLK *blkptr)
Definition: pdblock.h:156
void set_index(int value)
Definition: pdblock.h:68
Definition: rect.h:30
BOOL8 cycled_rects()
test end
Definition: pdblock.h:120
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
#define DLLSYM
Definition: platform.h:25
ICOORDELT_LIST leftside
Definition: pdblock.h:96
#define CLISTIZEH(CLASSNAME)
Definition: clst.h:901
const TBOX & bounding_box() const
get real box
Definition: pdblock.h:65
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97
PDBLK()
empty constructor
Definition: pdblock.h:37
integer coordinate
Definition: points.h:30
int index_
Definition: pdblock.h:99
page block
Definition: pdblock.h:32