Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
28 #include "hpddef.h" // must be last (handpd.dll)
29
30 class DLLSYM POLY_BLOCK {
31 public:
32 POLY_BLOCK() {
33 }
34 // Initialize from box coordinates.
35 POLY_BLOCK(const TBOX& box, PolyBlockType type);
36 POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType type);
37 ~POLY_BLOCK () {
38 }
39
40 TBOX *bounding_box() { // access function
41 return &box;
42 }
43
44 ICOORDELT_LIST *points() { // access function
45 return &vertices;
46 }
47
48 void compute_bb();
49
50 PolyBlockType isA() const {
51 return type;
52 }
53
54 bool IsText() const {
55 return PTIsTextType(type);
56 }
57
58 // Rotate about the origin by the given rotation. (Analogous to
59 // multiplying by a complex number.
60 void rotate(FCOORD rotation);
61 // Reflect the coords of the polygon in the y-axis. (Flip the sign of x.)
62 void reflect_in_y_axis();
63 // Move by adding shift to all coordinates.
64 void move(ICOORD shift);
65
66 void plot(ScrollView* window, inT32 num);
67
68 #ifndef GRAPHICS_DISABLED
69 void fill(ScrollView* window, ScrollView::Color colour);
70 #endif // GRAPHICS_DISABLED
71
72 // Returns true if other is inside this.
73 bool contains(POLY_BLOCK *other);
74
75 // Returns true if the polygons of other and this overlap.
76 bool overlap(POLY_BLOCK *other);
77
78 // Returns the winding number of this around the test_pt.
79 // Positive for anticlockwise, negative for clockwise, and zero for
80 // test_pt outside this.
81 inT16 winding_number(const ICOORD &test_pt);
82
83 #ifndef GRAPHICS_DISABLED
84 // Static utility functions to handle the PolyBlockType.
85 // Returns a color to draw the given type.
86 static ScrollView::Color ColorForPolyBlockType(PolyBlockType type);
87 #endif // GRAPHICS_DISABLED
88
89 private:
90 ICOORDELT_LIST vertices; // vertices
91 TBOX box; // bounding box
92 PolyBlockType type; // Type of this region.
93 };
94
95 // Class to iterate the scanlines of a polygon.
96 class DLLSYM PB_LINE_IT {
97 public:
98 PB_LINE_IT(POLY_BLOCK *blkptr) {
99 block = blkptr;
100 }
101
102 void set_to_block(POLY_BLOCK * blkptr) {
103 block = blkptr;
104 }
105
106 // Returns a list of runs of pixels for the given y coord.
107 // Each element of the returned list is the start (x) and extent(y) of
108 // a run inside the region.
109 // Delete the returned list after use.
110 ICOORDELT_LIST *get_line(inT16 y);
111
112 private:
113 POLY_BLOCK * block;
114 };
115 #endif