tesseract  5.0.0-alpha-619-ge9db
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 <tesseract/strngs.h>
24 #include "polyblk.h"
25 
26 class DLLSYM PDBLK; //forward decl
27 struct Pix;
28 
31 class PDBLK {
32  friend class BLOCK_RECT_IT;
33  friend class BLOCK;
34 
35  public:
37  PDBLK() {
38  hand_poly = nullptr;
39  index_ = 0;
40  }
42  PDBLK(int16_t xmin,
43  int16_t ymin,
44  int16_t xmax,
45  int16_t 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  bool 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 nullptr, 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_t serial, ScrollView::Color colour);
88 #endif // GRAPHICS_DISABLED
89 
92  PDBLK &operator=(const PDBLK &source);
93 
94  protected:
95  POLY_BLOCK *hand_poly;
96  ICOORDELT_LIST leftside;
97  ICOORDELT_LIST rightside;
98  TBOX box;
99  int index_;
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 
120  bool cycled_rects() {
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_t ymin = 0;
137  int16_t ymax = 0;
138  PDBLK* block = nullptr;
139  ICOORDELT_IT left_it;
140  ICOORDELT_IT right_it;
141 };
142 
144 class DLLSYM BLOCK_LINE_IT
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_t get_line(int16_t y,
166  int16_t &xext);
167 
168  private:
169  PDBLK * block;
170  BLOCK_RECT_IT rect_it;
171 };
172 
173 #endif
ScrollView
Definition: scrollview.h:97
strngs.h
PDBLK
class DLLSYM PDBLK
Definition: pdblock.h:25
ICOORD
integer coordinate
Definition: points.h:30
polyblk.h
BLOCK::render_mask
Pix * render_mask(TBOX *mask_box)
Definition: ocrblock.h:159
FCOORD
Definition: points.h:187
BLOCK::operator=
BLOCK & operator=(const BLOCK &source)
Definition: ocrblock.cpp:221
BLOCK_LINE_IT
rectangle iterator
Definition: pdblock.h:143
BLOCK
Definition: ocrblock.h:28
CLISTIZEH
CLISTIZEH(STRING) CLISTIZE(STRING) namespace tesseract
Definition: reject.cpp:50
DLLSYM
#define DLLSYM
Definition: platform.h:21
PDBLK
page block
Definition: pdblock.h:30
POLY_BLOCK
Definition: polyblk.h:26
ScrollView::Color
Color
Definition: scrollview.h:100
BLOCK_RECT_IT
Definition: pdblock.h:101
clst.h
TBOX
Definition: rect.h:33