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