tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
pdblock.h
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 
30 CLISTIZEH (PDBLK)
32 class PDBLK {
33  friend class BLOCK_RECT_IT; //< block iterator
34  friend class BLOCK; //< Page Block
35 
36  public:
38  PDBLK() {
39  hand_poly = nullptr;
40  index_ = 0;
41  }
43  PDBLK(int16_t xmin, //< bottom left
44  int16_t ymin,
45  int16_t xmax, //< top right
46  int16_t ymax);
47 
51  void set_sides(ICOORDELT_LIST *left, ICOORDELT_LIST *right);
52 
54  ~PDBLK() { delete hand_poly; }
55 
56  POLY_BLOCK *poly_block() const { return hand_poly; }
58  void set_poly_block(POLY_BLOCK *blk) { hand_poly = blk; }
60  void bounding_box(ICOORD &bottom_left, // bottom left
61  ICOORD &top_right) const { // topright
62  bottom_left = box.botleft();
63  top_right = box.topright();
64  }
66  const TBOX &bounding_box() const { return box; }
67 
68  int index() const { return index_; }
69  void set_index(int value) { index_ = value; }
70 
72  bool contains(ICOORD pt);
73 
75  void move(const ICOORD vec); // by vector
76 
77  // Returns a binary Pix mask with a 1 pixel for every pixel within the
78  // block. Rotates the coordinate system by rerotation prior to rendering.
79  // If not nullptr, mask_box is filled with the position box of the returned
80  // mask image.
81  Pix *render_mask(const FCOORD &rerotation, TBOX *mask_box);
82 
83 #ifndef GRAPHICS_DISABLED
84  void plot(ScrollView *window, int32_t serial, ScrollView::Color colour);
89 #endif // GRAPHICS_DISABLED
90 
93  PDBLK &operator=(const PDBLK &source);
94 
95  protected:
96  POLY_BLOCK *hand_poly; //< weird as well
97  ICOORDELT_LIST leftside; //< left side vertices
98  ICOORDELT_LIST rightside; //< right side vertices
99  TBOX box; //< bounding box
100  int index_; //< Serial number of this block.
101 };
102 
103 class DLLSYM BLOCK_RECT_IT //rectangle iterator
104 {
105  public:
108  BLOCK_RECT_IT(PDBLK *blkptr);
109 
111  void set_to_block (
112  PDBLK * blkptr); //block to iterate
113 
115  void start_block();
116 
118  void forward();
119 
121  bool cycled_rects() {
122  return left_it.cycled_list() && right_it.cycled_list();
123  }
124 
128  void bounding_box(ICOORD &bleft,
129  ICOORD &tright) {
130  //bottom left
131  bleft = ICOORD (left_it.data ()->x (), ymin);
132  //top right
133  tright = ICOORD (right_it.data ()->x (), ymax);
134  }
135 
136  private:
137  int16_t ymin; //< bottom of rectangle
138  int16_t ymax; //< top of rectangle
139  PDBLK *block; //< block to iterate
140  ICOORDELT_IT left_it; //< boundary iterators
141  ICOORDELT_IT right_it;
142 };
143 
145 class DLLSYM BLOCK_LINE_IT
146 {
147  public:
150  BLOCK_LINE_IT (PDBLK * blkptr)
151  :rect_it (blkptr) {
152  block = blkptr; //remember block
153  }
154 
157  void set_to_block (PDBLK * blkptr) {
158  block = blkptr; //remember block
159  //set iterator
160  rect_it.set_to_block (blkptr);
161  }
162 
166  int16_t get_line(int16_t y,
167  int16_t &xext);
168 
169  private:
170  PDBLK * block; //< block to iterate
171  BLOCK_RECT_IT rect_it; //< rectangle iterator
172 };
173 
174 #endif
POLY_BLOCK * hand_poly
Definition: pdblock.h:96
BLOCK_RECT_IT rect_it
Definition: pdblock.h:171
PDBLK * block
Definition: pdblock.h:139
POLY_BLOCK * poly_block() const
Definition: pdblock.h:56
Color
Definition: scrollview.h:105
Definition: rect.h:34
page block
Definition: pdblock.h:32
bool cycled_rects()
test end
Definition: pdblock.h:121
void set_poly_block(POLY_BLOCK *blk)
set the poly block
Definition: pdblock.h:58
ICOORDELT_LIST rightside
Definition: pdblock.h:98
Definition: pdblock.h:103
rectangle iterator
Definition: pdblock.h:145
int index() const
Definition: pdblock.h:68
ICOORDELT_IT left_it
Definition: pdblock.h:140
Definition: scrollview.h:102
Definition: ocrblock.h:30
Definition: polyblk.h:27
PDBLK()
empty constructor
Definition: pdblock.h:38
const TBOX & bounding_box() const
get real box
Definition: pdblock.h:66
int16_t ymax
Definition: pdblock.h:138
void set_index(int value)
Definition: pdblock.h:69
int index_
Definition: pdblock.h:100
ICOORDELT_LIST leftside
Definition: pdblock.h:97
Pix * render_mask(TBOX *mask_box)
Definition: ocrblock.h:162
integer coordinate
Definition: points.h:32
~PDBLK()
destructor
Definition: pdblock.h:54
int16_t ymin
Definition: pdblock.h:137
BLOCK_LINE_IT(PDBLK *blkptr)
Definition: pdblock.h:150
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:60
ICOORDELT_IT right_it
Definition: pdblock.h:141
TBOX box
Definition: pdblock.h:99
BLOCK & operator=(const BLOCK &source)
Definition: ocrblock.cpp:226
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:128
PDBLK * block
Definition: pdblock.h:170
Definition: points.h:189
void set_to_block(PDBLK *blkptr)
Definition: pdblock.h:157