tesseract v5.3.3.20231005
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 *
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
25struct Pix;
26
27namespace tesseract {
28
29class PDBLK; // forward decl
30
31CLISTIZEH(PDBLK)
33class PDBLK {
34 friend class BLOCK_RECT_IT;
35 friend class BLOCK;
36
37public:
40 hand_poly = nullptr;
41 index_ = 0;
42 }
44 PDBLK(TDimension xmin,
45 TDimension ymin,
46 TDimension xmax,
47 TDimension ymax);
48
52 void set_sides(ICOORDELT_LIST *left, ICOORDELT_LIST *right);
53
56 delete hand_poly;
57 }
58
60 return hand_poly;
61 }
64 hand_poly = blk;
65 }
67 void bounding_box(ICOORD &bottom_left, // bottom left
68 ICOORD &top_right) const { // topright
69 bottom_left = box.botleft();
70 top_right = box.topright();
71 }
73 const TBOX &bounding_box() const {
74 return box;
75 }
76
77 int index() const {
78 return index_;
79 }
80 void set_index(int value) {
81 index_ = value;
82 }
83
85 bool contains(ICOORD pt);
86
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
101 void plot(ScrollView *window, int32_t serial, ScrollView::Color colour);
102#endif // !GRAPHICS_DISABLED
103
106 PDBLK &operator=(const PDBLK &source);
107
108protected:
110 ICOORDELT_LIST leftside;
111 ICOORDELT_LIST rightside;
113 int index_;
114};
115
116class BLOCK_RECT_IT // rectangle iterator
117{
118public:
121 BLOCK_RECT_IT(PDBLK *blkptr);
122
124 void set_to_block(PDBLK *blkptr); // block to iterate
125
127 void start_block();
128
130 void forward();
131
133 bool cycled_rects() const {
134 return left_it.cycled_list() && right_it.cycled_list();
135 }
136
140 void bounding_box(ICOORD &bleft, ICOORD &tright) {
141 // bottom left
142 bleft = ICOORD(left_it.data()->x(), ymin);
143 // top right
144 tright = ICOORD(right_it.data()->x(), ymax);
145 }
146
147private:
148 TDimension ymin = 0;
149 TDimension ymax = 0;
150 PDBLK *block = nullptr;
151 ICOORDELT_IT left_it;
152 ICOORDELT_IT right_it;
153};
154
157public:
160 BLOCK_LINE_IT(PDBLK *blkptr) : rect_it(blkptr) {
161 block = blkptr; // remember block
162 }
163
166 void set_to_block(PDBLK *blkptr) {
167 block = blkptr; // remember block
168 // set iterator
169 rect_it.set_to_block(blkptr);
170 }
171
176
177private:
178 PDBLK *block;
179 BLOCK_RECT_IT rect_it;
180};
181
182} // namespace tesseract
183
184#endif
#define CLISTIZEH(CLASSNAME)
Definition: clst.h:705
int value
const double y
int16_t TDimension
Definition: tesstypes.h:32
bool contains(const std::vector< T > &data, const T &value)
Definition: helpers.h:39
page block
Definition: pdblock.h:33
const TBOX & bounding_box() const
get real box
Definition: pdblock.h:73
POLY_BLOCK * poly_block() const
Definition: pdblock.h:59
PDBLK()
empty constructor
Definition: pdblock.h:39
void set_index(int value)
Definition: pdblock.h:80
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:111
TBOX box
bounding box
Definition: pdblock.h:112
~PDBLK()
destructor
Definition: pdblock.h:55
int index_
Serial number of this block.
Definition: pdblock.h:113
int index() const
Definition: pdblock.h:77
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:109
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:110
void set_poly_block(POLY_BLOCK *blk)
set the poly block
Definition: pdblock.h:63
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:67
void forward()
next rectangle
Definition: pdblock.cpp:321
void start_block()
start iteration
Definition: pdblock.cpp:302
bool cycled_rects() const
test end
Definition: pdblock.h:133
void set_to_block(PDBLK *blkptr)
start (new) block
Definition: pdblock.cpp:285
BLOCK_RECT_IT(PDBLK *blkptr)
Definition: pdblock.cpp:267
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:140
rectangle iterator
Definition: pdblock.h:156
BLOCK_LINE_IT(PDBLK *blkptr)
Definition: pdblock.h:160
void set_to_block(PDBLK *blkptr)
Definition: pdblock.h:166
TDimension get_line(TDimension y, TDimension &xext)
Definition: pdblock.cpp:353
integer coordinate
Definition: points.h:36