tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
outlines.h
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: outlines.h
5  * Description: Combinatorial Splitter
6  * Author: Mark Seaman, OCR Technology
7  * Created: Thu Jul 27 11:27:55 1989
8  * Modified: Wed May 15 17:28:47 1991 (Mark Seaman) marks@hpgrlt
9  * Language: C
10  * Package: N/A
11  * Status: Experimental (Do Not Distribute)
12  *
13  * (c) Copyright 1989, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  *********************************************************************************/
25 
26 #ifndef OUTLINES_H
27 #define OUTLINES_H
28 
29 #include <cmath> // for abs
30 #include "blobs.h" // for TPOINT
31 #include "params.h" // for IntParam
32 #include "wordrec.h" // for Wordrec
33 
34 /*----------------------------------------------------------------------
35  C o n s t a n t s
36 ----------------------------------------------------------------------*/
37 #define LARGE_DISTANCE 100000 /* Used for closest dist */
38 #define MIN_BLOB_SIZE 10 /* Big units */
39 #define MAX_ASPECT_RATIO 2.5 /* Widest character */
40 
41 /*----------------------------------------------------------------------
42  M a c r o s
43 ----------------------------------------------------------------------*/
44 /**********************************************************************
45  * same_point
46  *
47  * Return TRUE if the point values are the same. The parameters must
48  * be of type POINT.
49  **********************************************************************/
50 #define same_point(p1,p2) \
51  ((abs (p1.x - p2.x) < chop_same_distance) && \
52  (abs (p1.y - p2.y) < chop_same_distance))
53 
54 /**********************************************************************
55  * dist_square
56  *
57  * Return the square of the distance between these two points. The
58  * parameters must be of type POINT.
59  **********************************************************************/
60 
61 #define dist_square(p1,p2) \
62  ((p2.x - p1.x) * (p2.x - p1.x) + \
63  (p2.y - p1.y) * (p2.y - p1.y))
64 
65 /**********************************************************************
66  * closest
67  *
68  * The expression provides the EDGEPT that is closest to the point in
69  * question. All three parameters must be of type EDGEPT.
70  **********************************************************************/
71 
72 #define closest(test_p,p1,p2) \
73 (p1 ? \
74  (p2 ? \
75  ((dist_square (test_p->pos, p1->pos) < \
76  dist_square (test_p->pos, p2->pos)) ? \
77  p1 : \
78  p2) : \
79  p1) : \
80  p2)
81 
82 /**********************************************************************
83  * edgept_dist
84  *
85  * Return the distance (squared) between the two edge points.
86  **********************************************************************/
87 
88 #define edgept_dist(p1,p2) \
89 (dist_square ((p1)->pos, (p2)->pos))
90 
91 /**********************************************************************
92  * is_exterior_point
93  *
94  * Return TRUE if the point supplied is an exterior projection from the
95  * outline.
96  **********************************************************************/
97 
98 #define is_exterior_point(edge,point) \
99 (same_point (edge->prev->pos, point->pos) || \
100  same_point (edge->next->pos, point->pos) || \
101  (angle_change (edge->prev, edge, edge->next) - \
102  angle_change (edge->prev, edge, point) > 20))
103 
104 /**********************************************************************
105  * is_equal
106  *
107  * Return TRUE if the POINTs are equal.
108  **********************************************************************/
109 
110 #define is_equal(p1,p2) \
111 (((p1).x == (p2).x) && ((p1).y == (p2).y))
112 
113 /**********************************************************************
114  * is_on_line
115  *
116  * Return TRUE if the point is on the line segment between the two end
117  * points. The two end points are included as part of the line. The
118  * parameters must be of type POINT.
119  **********************************************************************/
120 
121 #define is_on_line(p,p0,p1) \
122  (within_range ((p).x, (p0).x, (p1).x) && \
123  within_range ((p).y, (p0).y, (p1).y))
124 
125 /**********************************************************************
126  * within_range
127  *
128  * Return TRUE if the first number is in between the second two numbers.
129  * Return FALSE otherwise.
130  **********************************************************************/
131 
132 #define within_range(x,x0,x1) \
133  (((x0 <= x) && (x <= x1)) || ((x1 <= x) && (x <= x0)))
134 
135 #endif