tesseract  5.0.0-alpha-619-ge9db
outlines.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * File: outlines.h
4  * Description: Combinatorial Splitter
5  * Author: Mark Seaman, OCR Technology
6  *
7  * (c) Copyright 1989, Hewlett-Packard Company.
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 OUTLINES_H
21 #define OUTLINES_H
22 
23 #include <cmath> // for abs
24 #include "blobs.h" // for TPOINT
25 #include "params.h" // for IntParam
26 #include "wordrec.h" // for Wordrec
27 
28 /*----------------------------------------------------------------------
29  C o n s t a n t s
30 ----------------------------------------------------------------------*/
31 #define LARGE_DISTANCE 100000 /* Used for closest dist */
32 #define MIN_BLOB_SIZE 10 /* Big units */
33 #define MAX_ASPECT_RATIO 2.5 /* Widest character */
34 
35 /*----------------------------------------------------------------------
36  M a c r o s
37 ----------------------------------------------------------------------*/
38 /**********************************************************************
39  * same_point
40  *
41  * Return true if the point values are the same. The parameters must
42  * be of type POINT.
43  **********************************************************************/
44 #define same_point(p1,p2) \
45  ((abs (p1.x - p2.x) < chop_same_distance) && \
46  (abs (p1.y - p2.y) < chop_same_distance))
47 
48 /**********************************************************************
49  * dist_square
50  *
51  * Return the square of the distance between these two points. The
52  * parameters must be of type POINT.
53  **********************************************************************/
54 
55 #define dist_square(p1,p2) \
56  ((p2.x - p1.x) * (p2.x - p1.x) + \
57  (p2.y - p1.y) * (p2.y - p1.y))
58 
59 /**********************************************************************
60  * closest
61  *
62  * The expression provides the EDGEPT that is closest to the point in
63  * question. All three parameters must be of type EDGEPT.
64  **********************************************************************/
65 
66 #define closest(test_p,p1,p2) \
67 (p1 ? \
68  (p2 ? \
69  ((dist_square (test_p->pos, p1->pos) < \
70  dist_square (test_p->pos, p2->pos)) ? \
71  p1 : \
72  p2) : \
73  p1) : \
74  p2)
75 
76 /**********************************************************************
77  * edgept_dist
78  *
79  * Return the distance (squared) between the two edge points.
80  **********************************************************************/
81 
82 #define edgept_dist(p1,p2) \
83 (dist_square ((p1)->pos, (p2)->pos))
84 
85 /**********************************************************************
86  * is_exterior_point
87  *
88  * Return true if the point supplied is an exterior projection from the
89  * outline.
90  **********************************************************************/
91 
92 #define is_exterior_point(edge,point) \
93 (same_point (edge->prev->pos, point->pos) || \
94  same_point (edge->next->pos, point->pos) || \
95  (angle_change (edge->prev, edge, edge->next) - \
96  angle_change (edge->prev, edge, point) > 20))
97 
98 /**********************************************************************
99  * is_equal
100  *
101  * Return true if the POINTs are equal.
102  **********************************************************************/
103 
104 #define is_equal(p1,p2) \
105 (((p1).x == (p2).x) && ((p1).y == (p2).y))
106 
107 /**********************************************************************
108  * is_on_line
109  *
110  * Return true if the point is on the line segment between the two end
111  * points. The two end points are included as part of the line. The
112  * parameters must be of type POINT.
113  **********************************************************************/
114 
115 #define is_on_line(p,p0,p1) \
116  (within_range ((p).x, (p0).x, (p1).x) && \
117  within_range ((p).y, (p0).y, (p1).y))
118 
119 /**********************************************************************
120  * within_range
121  *
122  * Return true if the first number is in between the second two numbers.
123  * Return false otherwise.
124  **********************************************************************/
125 
126 #define within_range(x,x0,x1) \
127  (((x0 <= x) && (x <= x1)) || ((x1 <= x) && (x <= x0)))
128 
129 #endif
params.h
wordrec.h
blobs.h