tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
polyblk.h
1 /**********************************************************************
2  * File: polyblk.h (Formerly poly_block.h)
3  * Description: Polygonal blocks
4  *
5  * (C) Copyright 1993, Hewlett-Packard Ltd.
6  ** Licensed under the Apache License, Version 2.0 (the "License");
7  ** you may not use this file except in compliance with the License.
8  ** You may obtain a copy of the License at
9  ** http://www.apache.org/licenses/LICENSE-2.0
10  ** Unless required by applicable law or agreed to in writing, software
11  ** distributed under the License is distributed on an "AS IS" BASIS,
12  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  ** See the License for the specific language governing permissions and
14  ** limitations under the License.
15  *
16  **********************************************************************/
17 
18 #ifndef POLYBLK_H
19 #define POLYBLK_H
20 
21 #include "publictypes.h"
22 #include "elst.h"
23 #include "points.h"
24 #include "rect.h"
25 #include "scrollview.h"
26 
27 class DLLSYM POLY_BLOCK {
28  public:
29  POLY_BLOCK() = default;
30  // Initialize from box coordinates.
31  POLY_BLOCK(const TBOX& tbox, PolyBlockType type);
32  POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType type);
33  ~POLY_BLOCK () = default;
34 
35  TBOX *bounding_box() { // access function
36  return &box;
37  }
38 
39  ICOORDELT_LIST *points() { // access function
40  return &vertices;
41  }
42 
43  void compute_bb();
44 
45  PolyBlockType isA() const {
46  return type;
47  }
48 
49  bool IsText() const {
50  return PTIsTextType(type);
51  }
52 
53  // Rotate about the origin by the given rotation. (Analogous to
54  // multiplying by a complex number.
55  void rotate(FCOORD rotation);
56  // Reflect the coords of the polygon in the y-axis. (Flip the sign of x.)
57  void reflect_in_y_axis();
58  // Move by adding shift to all coordinates.
59  void move(ICOORD shift);
60 
61  void plot(ScrollView* window, int32_t num);
62 
63  #ifndef GRAPHICS_DISABLED
64  void fill(ScrollView* window, ScrollView::Color colour);
65  #endif // GRAPHICS_DISABLED
66 
67  // Returns true if other is inside this.
68  bool contains(POLY_BLOCK *other);
69 
70  // Returns true if the polygons of other and this overlap.
71  bool overlap(POLY_BLOCK *other);
72 
73  // Returns the winding number of this around the test_pt.
74  // Positive for anticlockwise, negative for clockwise, and zero for
75  // test_pt outside this.
76  int16_t winding_number(const ICOORD &test_pt);
77 
78  #ifndef GRAPHICS_DISABLED
79  // Static utility functions to handle the PolyBlockType.
80  // Returns a color to draw the given type.
81  static ScrollView::Color ColorForPolyBlockType(PolyBlockType type);
82  #endif // GRAPHICS_DISABLED
83 
84  private:
85  ICOORDELT_LIST vertices; // vertices
86  TBOX box; // bounding box
87  PolyBlockType type; // Type of this region.
88 };
89 
90 // Class to iterate the scanlines of a polygon.
91 class DLLSYM PB_LINE_IT {
92  public:
94  block = blkptr;
95  }
96 
97  void set_to_block(POLY_BLOCK * blkptr) {
98  block = blkptr;
99  }
100 
101  // Returns a list of runs of pixels for the given y coord.
102  // Each element of the returned list is the start (x) and extent(y) of
103  // a run inside the region.
104  // Delete the returned list after use.
105  ICOORDELT_LIST *get_line(int16_t y);
106 
107  private:
109 };
110 #endif
PolyBlockType type
Definition: polyblk.h:87
POLY_BLOCK * block
Definition: polyblk.h:108
void set_to_block(POLY_BLOCK *blkptr)
Definition: polyblk.h:97
Color
Definition: scrollview.h:105
Definition: rect.h:34
ICOORDELT_LIST * points()
Definition: polyblk.h:39
ICOORDELT_LIST vertices
Definition: polyblk.h:85
TBOX * bounding_box()
Definition: polyblk.h:35
Definition: scrollview.h:102
Definition: polyblk.h:27
PolyBlockType isA() const
Definition: polyblk.h:45
integer coordinate
Definition: points.h:32
TBOX box
Definition: polyblk.h:86
bool IsText() const
Definition: polyblk.h:49
PB_LINE_IT(POLY_BLOCK *blkptr)
Definition: polyblk.h:93
Definition: points.h:189
Definition: polyblk.h:91