tesseract  4.00.00dev
polyblk.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: polyblk.h (Formerly poly_block.h)
3  * Description: Polygonal blocks
4  * Author: Sheelagh Lloyd?
5  * Created:
6  *
7  * (C) Copyright 1993, 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 #ifndef POLYBLK_H
20 #define POLYBLK_H
21 
22 #include "publictypes.h"
23 #include "elst.h"
24 #include "points.h"
25 #include "rect.h"
26 #include "scrollview.h"
27 
29  public:
31  }
32  // Initialize from box coordinates.
33  POLY_BLOCK(const TBOX& box, PolyBlockType type);
34  POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType type);
36  }
37 
38  TBOX *bounding_box() { // access function
39  return &box;
40  }
41 
42  ICOORDELT_LIST *points() { // access function
43  return &vertices;
44  }
45 
46  void compute_bb();
47 
48  PolyBlockType isA() const {
49  return type;
50  }
51 
52  bool IsText() const {
53  return PTIsTextType(type);
54  }
55 
56  // Rotate about the origin by the given rotation. (Analogous to
57  // multiplying by a complex number.
58  void rotate(FCOORD rotation);
59  // Reflect the coords of the polygon in the y-axis. (Flip the sign of x.)
60  void reflect_in_y_axis();
61  // Move by adding shift to all coordinates.
62  void move(ICOORD shift);
63 
64  void plot(ScrollView* window, inT32 num);
65 
66  #ifndef GRAPHICS_DISABLED
67  void fill(ScrollView* window, ScrollView::Color colour);
68  #endif // GRAPHICS_DISABLED
69 
70  // Returns true if other is inside this.
71  bool contains(POLY_BLOCK *other);
72 
73  // Returns true if the polygons of other and this overlap.
74  bool overlap(POLY_BLOCK *other);
75 
76  // Returns the winding number of this around the test_pt.
77  // Positive for anticlockwise, negative for clockwise, and zero for
78  // test_pt outside this.
79  inT16 winding_number(const ICOORD &test_pt);
80 
81  #ifndef GRAPHICS_DISABLED
82  // Static utility functions to handle the PolyBlockType.
83  // Returns a color to draw the given type.
84  static ScrollView::Color ColorForPolyBlockType(PolyBlockType type);
85  #endif // GRAPHICS_DISABLED
86 
87  private:
88  ICOORDELT_LIST vertices; // vertices
89  TBOX box; // bounding box
90  PolyBlockType type; // Type of this region.
91 };
92 
93 // Class to iterate the scanlines of a polygon.
95  public:
97  block = blkptr;
98  }
99 
100  void set_to_block(POLY_BLOCK * blkptr) {
101  block = blkptr;
102  }
103 
104  // Returns a list of runs of pixels for the given y coord.
105  // Each element of the returned list is the start (x) and extent(y) of
106  // a run inside the region.
107  // Delete the returned list after use.
108  ICOORDELT_LIST *get_line(inT16 y);
109 
110  private:
111  POLY_BLOCK * block;
112 };
113 #endif
Definition: points.h:189
int32_t inT32
Definition: host.h:38
ICOORDELT_LIST * points()
Definition: polyblk.h:42
PolyBlockType
Definition: publictypes.h:41
PB_LINE_IT(POLY_BLOCK *blkptr)
Definition: polyblk.h:96
int16_t inT16
Definition: host.h:36
bool IsText() const
Definition: polyblk.h:52
~POLY_BLOCK()
Definition: polyblk.h:35
TBOX * bounding_box()
Definition: polyblk.h:38
POLY_BLOCK()
Definition: polyblk.h:30
Definition: rect.h:30
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70
PolyBlockType isA() const
Definition: polyblk.h:48
#define DLLSYM
Definition: platform.h:25
void set_to_block(POLY_BLOCK *blkptr)
Definition: polyblk.h:100
integer coordinate
Definition: points.h:30