/src/tesseract/src/ccstruct/pdblock.h
Line | Count | Source (jump to first uncovered line) |
1 | | /********************************************************************** |
2 | | * File: pdblock.h (Formerly pdblk.h) |
3 | | * Description: Page block class definition. |
4 | | * Author: Ray Smith |
5 | | * |
6 | | * (C) Copyright 1991, Hewlett-Packard Ltd. |
7 | | ** Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | ** you may not use this file except in compliance with the License. |
9 | | ** You may obtain a copy of the License at |
10 | | ** http://www.apache.org/licenses/LICENSE-2.0 |
11 | | ** Unless required by applicable law or agreed to in writing, software |
12 | | ** distributed under the License is distributed on an "AS IS" BASIS, |
13 | | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | ** See the License for the specific language governing permissions and |
15 | | ** limitations under the License. |
16 | | * |
17 | | **********************************************************************/ |
18 | | |
19 | | #ifndef PDBLOCK_H |
20 | | #define PDBLOCK_H |
21 | | |
22 | | #include "clst.h" |
23 | | #include "polyblk.h" |
24 | | |
25 | | struct Pix; |
26 | | |
27 | | namespace tesseract { |
28 | | |
29 | | class PDBLK; // forward decl |
30 | | |
31 | | CLISTIZEH(PDBLK) |
32 | | /// page block |
33 | | class PDBLK { |
34 | | friend class BLOCK_RECT_IT; ///< block iterator |
35 | | friend class BLOCK; ///< Page Block |
36 | | |
37 | | public: |
38 | | /// empty constructor |
39 | 0 | PDBLK() { |
40 | 0 | hand_poly = nullptr; |
41 | 0 | index_ = 0; |
42 | 0 | } |
43 | | /// simple constructor |
44 | | PDBLK(TDimension xmin, ///< bottom left |
45 | | TDimension ymin, |
46 | | TDimension xmax, ///< top right |
47 | | TDimension ymax); |
48 | | |
49 | | /// set vertex lists |
50 | | ///@param left list of left vertices |
51 | | ///@param right list of right vertices |
52 | | void set_sides(ICOORDELT_LIST *left, ICOORDELT_LIST *right); |
53 | | |
54 | | /// destructor |
55 | 7.72k | ~PDBLK() { |
56 | 7.72k | delete hand_poly; |
57 | 7.72k | } |
58 | | |
59 | 2.73M | POLY_BLOCK *poly_block() const { |
60 | 2.73M | return hand_poly; |
61 | 2.73M | } |
62 | | /// set the poly block |
63 | 0 | void set_poly_block(POLY_BLOCK *blk) { |
64 | 0 | hand_poly = blk; |
65 | 0 | } |
66 | | /// get box |
67 | | void bounding_box(ICOORD &bottom_left, // bottom left |
68 | 1.99M | ICOORD &top_right) const { // topright |
69 | 1.99M | bottom_left = box.botleft(); |
70 | 1.99M | top_right = box.topright(); |
71 | 1.99M | } |
72 | | /// get real box |
73 | 484k | const TBOX &bounding_box() const { |
74 | 484k | return box; |
75 | 484k | } |
76 | | |
77 | 0 | int index() const { |
78 | 0 | return index_; |
79 | 0 | } |
80 | 0 | void set_index(int value) { |
81 | 0 | index_ = value; |
82 | 0 | } |
83 | | |
84 | | /// is pt inside block |
85 | | bool contains(ICOORD pt); |
86 | | |
87 | | /// reposition block |
88 | | void move(const ICOORD vec); // by vector |
89 | | |
90 | | // Returns a binary Pix mask with a 1 pixel for every pixel within the |
91 | | // block. Rotates the coordinate system by rerotation prior to rendering. |
92 | | // If not nullptr, mask_box is filled with the position box of the returned |
93 | | // mask image. |
94 | | Image render_mask(const FCOORD &rerotation, TBOX *mask_box); |
95 | | |
96 | | #ifndef GRAPHICS_DISABLED |
97 | | /// draw histogram |
98 | | ///@param window window to draw in |
99 | | ///@param serial serial number |
100 | | ///@param colour colour to draw in |
101 | | void plot(ScrollView *window, int32_t serial, ScrollView::Color colour); |
102 | | #endif // !GRAPHICS_DISABLED |
103 | | |
104 | | /// assignment |
105 | | ///@param source from this |
106 | | PDBLK &operator=(const PDBLK &source); |
107 | | |
108 | | protected: |
109 | | POLY_BLOCK *hand_poly; ///< weird as well |
110 | | ICOORDELT_LIST leftside; ///< left side vertices |
111 | | ICOORDELT_LIST rightside; ///< right side vertices |
112 | | TBOX box; ///< bounding box |
113 | | int index_; ///< Serial number of this block. |
114 | | }; |
115 | | |
116 | | class BLOCK_RECT_IT // rectangle iterator |
117 | | { |
118 | | public: |
119 | | /// constructor |
120 | | ///@param blkptr block to iterate |
121 | | BLOCK_RECT_IT(PDBLK *blkptr); |
122 | | |
123 | | /// start (new) block |
124 | | void set_to_block(PDBLK *blkptr); // block to iterate |
125 | | |
126 | | /// start iteration |
127 | | void start_block(); |
128 | | |
129 | | /// next rectangle |
130 | | void forward(); |
131 | | |
132 | | /// test end |
133 | 0 | bool cycled_rects() const { |
134 | 0 | return left_it.cycled_list() && right_it.cycled_list(); |
135 | 0 | } |
136 | | |
137 | | /// current rectangle |
138 | | ///@param bleft bottom left |
139 | | ///@param tright top right |
140 | 1.97M | void bounding_box(ICOORD &bleft, ICOORD &tright) { |
141 | | // bottom left |
142 | 1.97M | bleft = ICOORD(left_it.data()->x(), ymin); |
143 | | // top right |
144 | 1.97M | tright = ICOORD(right_it.data()->x(), ymax); |
145 | 1.97M | } |
146 | | |
147 | | private: |
148 | | TDimension ymin = 0; ///< bottom of rectangle |
149 | | TDimension ymax = 0; ///< top of rectangle |
150 | | PDBLK *block = nullptr; ///< block to iterate |
151 | | ICOORDELT_IT left_it; ///< boundary iterators |
152 | | ICOORDELT_IT right_it; |
153 | | }; |
154 | | |
155 | | /// rectangle iterator |
156 | | class BLOCK_LINE_IT { |
157 | | public: |
158 | | /// constructor |
159 | | ///@param blkptr from block |
160 | 7.72k | BLOCK_LINE_IT(PDBLK *blkptr) : rect_it(blkptr) { |
161 | 7.72k | block = blkptr; // remember block |
162 | 7.72k | } |
163 | | |
164 | | /// start (new) block |
165 | | ///@param blkptr block to start |
166 | 0 | void set_to_block(PDBLK *blkptr) { |
167 | 0 | block = blkptr; // remember block |
168 | 0 | // set iterator |
169 | 0 | rect_it.set_to_block(blkptr); |
170 | 0 | } |
171 | | |
172 | | /// get a line |
173 | | ///@param y line to get |
174 | | ///@param xext output extent |
175 | | TDimension get_line(TDimension y, TDimension &xext); |
176 | | |
177 | | private: |
178 | | PDBLK *block; ///< block to iterate |
179 | | BLOCK_RECT_IT rect_it; ///< rectangle iterator |
180 | | }; |
181 | | |
182 | | } // namespace tesseract |
183 | | |
184 | | #endif |