Tesseract  3.02
tesseract-ocr/wordrec/outlines.h
Go to the documentation of this file.
00001 /* -*-C-*-
00002  ********************************************************************************
00003  *
00004  * File:        outlines.h  (Formerly outlines.h)
00005  * Description:  Combinatorial Splitter
00006  * Author:       Mark Seaman, OCR Technology
00007  * Created:      Thu Jul 27 11:27:55 1989
00008  * Modified:     Wed May 15 17:28:47 1991 (Mark Seaman) marks@hpgrlt
00009  * Language:     C
00010  * Package:      N/A
00011  * Status:       Experimental (Do Not Distribute)
00012  *
00013  * (c) Copyright 1989, Hewlett-Packard Company.
00014  ** Licensed under the Apache License, Version 2.0 (the "License");
00015  ** you may not use this file except in compliance with the License.
00016  ** You may obtain a copy of the License at
00017  ** http://www.apache.org/licenses/LICENSE-2.0
00018  ** Unless required by applicable law or agreed to in writing, software
00019  ** distributed under the License is distributed on an "AS IS" BASIS,
00020  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  ** See the License for the specific language governing permissions and
00022  ** limitations under the License.
00023  *
00024  *********************************************************************************/
00025 #ifndef OUTLINES_H
00026 #define OUTLINES_H
00027 
00028 #include "blobs.h"
00029 #include "chop.h"
00030 
00031 #include <math.h>
00032 
00033 /*----------------------------------------------------------------------
00034               C o n s t a n t s
00035 ----------------------------------------------------------------------*/
00036 #define LARGE_DISTANCE   100000  /* Used for closest dist */
00037 #define MIN_BLOB_SIZE    10      /* Big units */
00038 #define MAX_ASPECT_RATIO 2.5     /* Widest character */
00039 
00040 /*----------------------------------------------------------------------
00041               M a c r o s
00042 ----------------------------------------------------------------------*/
00043 /**********************************************************************
00044  * same_point
00045  *
00046  * Return TRUE if the point values are the same. The parameters must
00047  * be of type POINT.
00048  **********************************************************************/
00049 #define same_point(p1,p2)                    \
00050         ((abs (p1.x - p2.x) < chop_same_distance) && \
00051         (abs (p1.y - p2.y) < chop_same_distance))
00052 
00053 /**********************************************************************
00054  * dist_square
00055  *
00056  * Return the square of the distance between these two points.  The
00057  * parameters must be of type POINT.
00058  **********************************************************************/
00059 
00060 #define dist_square(p1,p2)                     \
00061         ((p2.x - p1.x) * (p2.x - p1.x) +            \
00062         (p2.y - p1.y) * (p2.y - p1.y))
00063 
00064 /**********************************************************************
00065  * closest
00066  *
00067  * The expression provides the EDGEPT that is closest to the point in
00068  * question.  All three parameters must be of type EDGEPT.
00069  **********************************************************************/
00070 
00071 #define closest(test_p,p1,p2)                   \
00072 (p1 ?                                         \
00073         (p2 ?                                        \
00074         ((dist_square (test_p->pos, p1->pos) <      \
00075                 dist_square (test_p->pos, p2->pos)) ?     \
00076         p1  :                                      \
00077         p2) :                                      \
00078         p1)  :                                      \
00079         p2)
00080 
00081 /**********************************************************************
00082  * edgept_dist
00083  *
00084  * Return the distance (squared) between the two edge points.
00085  **********************************************************************/
00086 
00087 #define edgept_dist(p1,p2)  \
00088 (dist_square ((p1)->pos, (p2)->pos))
00089 
00090 /**********************************************************************
00091  * is_exterior_point
00092  *
00093  * Return TRUE if the point supplied is an exterior projection from the
00094  * outline.
00095  **********************************************************************/
00096 
00097 #define is_exterior_point(edge,point)                    \
00098 (same_point (edge->prev->pos, point->pos)  ||          \
00099         same_point (edge->next->pos, point->pos)  ||          \
00100         (angle_change (edge->prev, edge, edge->next) -   \
00101         angle_change (edge->prev, edge, point) > 20))
00102 
00103 /**********************************************************************
00104  * is_equal
00105  *
00106  * Return TRUE if the POINTs are equal.
00107  **********************************************************************/
00108 
00109 #define is_equal(p1,p2)  \
00110 (((p1).x == (p2).x) && ((p1).y == (p2).y))
00111 
00112 /**********************************************************************
00113  * is_on_line
00114  *
00115  * Return TRUE if the point is on the line segment between the two end
00116  * points.  The two end points are included as part of the  line.  The
00117  * parameters must be of type POINT.
00118  **********************************************************************/
00119 
00120 #define is_on_line(p,p0,p1)                  \
00121         (within_range ((p).x, (p0).x, (p1).x) &&  \
00122         within_range ((p).y, (p0).y, (p1).y))
00123 
00124 /**********************************************************************
00125  * within_range
00126  *
00127  * Return TRUE if the first number is in between the second two numbers.
00128  * Return FALSE otherwise.
00129  **********************************************************************/
00130 
00131 #define within_range(x,x0,x1) \
00132         (((x0 <= x) && (x <= x1)) || ((x1 <= x) && (x <= x0)))
00133 
00134 #endif