wordrec/gradechop.cpp

Go to the documentation of this file.
00001 
00020 /*----------------------------------------------------------------------
00021               I n c l u d e s
00022 ----------------------------------------------------------------------*/
00023 #include "gradechop.h"
00024 #include "debug.h"
00025 #include "olutil.h"
00026 #include "chop.h"
00027 #include <math.h>
00028 
00029 /*----------------------------------------------------------------------
00030               T y p e s
00031 ----------------------------------------------------------------------*/
00032 #define CENTER_GRADE_CAP 25.0
00033 
00034 /*----------------------------------------------------------------------
00035               M a c r o s
00036 ----------------------------------------------------------------------*/
00040 #define find_bounds_loop(point1,point2,x_min,x_max)     \
00041    x_min = point2->pos.x;                               \
00042    x_max = point2->pos.x;                               \
00043                                           \
00044    this_point = point1;                                 \
00045    do {                                                 \
00046       x_min = min (this_point->pos.x, x_min);           \
00047       x_max = max (this_point->pos.x, x_max);           \
00048       this_point = this_point->next;                    \
00049    }                                                    \
00050    while (this_point != point2 && this_point != point1) \
00051 
00052 
00053 /*----------------------------------------------------------------------
00054               F u n c t i o n s
00055 ----------------------------------------------------------------------*/
00056 /* ================== */
00063 PRIORITY full_split_priority(SPLIT *split, INT16 xmin, INT16 xmax) { 
00064   BOUNDS_RECT rect;
00065 
00066   set_outline_bounds (split->point1, split->point2, rect);
00067 
00068   if (xmin < min (rect[0], rect[2]) && xmax > max (rect[1], rect[3]))
00069     return (999.0);
00070 
00071   return (grade_overlap (rect) +
00072     grade_center_of_blob (rect) + grade_width_change (rect));
00073 }
00074 
00075 
00076 /* ================== */
00084 PRIORITY grade_center_of_blob(register BOUNDS_RECT rect) { 
00085   register PRIORITY grade;
00086 
00087   grade = (rect[1] - rect[0]) - (rect[3] - rect[2]);
00088   if (grade < 0)
00089     grade = -grade;
00090 
00091   grade *= center_knob;
00092   grade = min (CENTER_GRADE_CAP, grade);
00093   return (max (0.0, grade));
00094 }
00095 
00096 
00097 /* ================== */
00104 PRIORITY grade_overlap(register BOUNDS_RECT rect) { 
00105   register PRIORITY grade;
00106   register INT16 width1;
00107   register INT16 width2;
00108   register INT16 overlap;
00109 
00110   width1 = rect[3] - rect[2];
00111   width2 = rect[1] - rect[0];
00112 
00113   overlap = min (rect[1], rect[3]) - max (rect[0], rect[2]);
00114   width1 = min (width1, width2);
00115   if (overlap == width1)
00116     return (100.0);              /* Total overlap */
00117 
00118   width1 = 2 * overlap - width1; /* Extra penalty for too */
00119   overlap += max (0, width1);    /* much overlap */
00120 
00121   grade = overlap * overlap_knob;
00122 
00123   return (max (0.0, grade));
00124 }
00125 
00126 
00127 /* ================== */
00134 PRIORITY grade_split_length(register SPLIT *split) { 
00135   register PRIORITY grade;
00136   register float split_length;
00137 
00138   split_length = weighted_edgept_dist (split->point1, split->point2,
00139     x_y_weight);
00140 
00141   if (split_length <= 0)
00142     grade = 0;
00143   else
00144     grade = sqrt (split_length) * split_dist_knob;
00145 
00146   return (max (0.0, grade));
00147 }
00148 
00149 
00150 /* ================== */
00157 PRIORITY grade_sharpness(register SPLIT *split) { 
00158   register PRIORITY grade;
00159 
00160   grade = point_priority (split->point1) + point_priority (split->point2);
00161 
00162   if (grade < -360.0)
00163     grade = 0;
00164   else
00165     grade += 360.0;
00166 
00167   grade *= sharpness_knob;       /* Values 0 to -360 */
00168 
00169   return (grade);
00170 }
00171 
00172 
00173 /* ================== */
00180 PRIORITY grade_width_change(register BOUNDS_RECT rect) { 
00181   register PRIORITY grade;
00182   register INT32 width1;
00183   register INT32 width2;
00184 
00185   width1 = rect[3] - rect[2];
00186   width2 = rect[1] - rect[0];
00187 
00188   grade = 20 - (max (rect[1], rect[3])
00189     - min (rect[0], rect[2]) - max (width1, width2));
00190 
00191   grade *= width_change_knob;
00192 
00193   return (max (0.0, grade));
00194 }
00195 
00196 
00197 /* ================== */
00201 void set_outline_bounds(register EDGEPT *point1,
00202                         register EDGEPT *point2,
00203                         BOUNDS_RECT rect) {
00204   register EDGEPT *this_point;
00205   register INT16 x_min;
00206   register INT16 x_max;
00207 
00208   find_bounds_loop(point1, point2, x_min, x_max); 
00209 
00210   rect[0] = x_min;
00211   rect[1] = x_max;
00212 
00213   find_bounds_loop(point2, point1, x_min, x_max); 
00214 
00215   rect[2] = x_min;
00216   rect[3] = x_max;
00217 }

Generated on Wed Feb 28 19:49:13 2007 for Tesseract by  doxygen 1.5.1