1 /****************************************************************************** 2 ** Filename: mfoutline.h 3 ** Purpose: Interface spec for fx outline structures 4 ** Author: Dan Johnson 5 ** History: Thu May 17 08:55:32 1990, DSJ, Created. 6 ** 7 ** (c) Copyright Hewlett-Packard Company, 1988. 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 #ifndef MFOUTLINE_H 19 #define MFOUTLINE_H 20 21 /**---------------------------------------------------------------------------- 22 Include Files and Type Defines 23 ----------------------------------------------------------------------------**/ 24 #include "general.h" 25 #include "oldlist.h" 26 #include "fpoint.h" 27 #include "fxdefs.h" 28 #include "baseline.h" 29 #include "varable.h" 30 31 #define NORMAL_X_HEIGHT (0.5) 32 #define NORMAL_BASELINE (0.0) 33 34 typedef LIST MFOUTLINE; 35 36 typedef enum { 37 north, south, east, west, northeast, northwest, southeast, southwest 38 } 39 40 41 DIRECTION; 42 43 typedef struct 44 { 45 FPOINT Point; 46 FLOAT32 Slope; 47 unsigned Padding:20; 48 BOOL8 Hidden:TRUE; 49 BOOL8 ExtremityMark:TRUE; 50 DIRECTION Direction:4; 51 DIRECTION PreviousDirection:4; 52 } 53 54 55 MFEDGEPT; 56 57 typedef enum { 58 outer, hole 59 } 60 61 62 OUTLINETYPE; 63 64 typedef struct 65 { 66 FLOAT64 Mx, My; /* first moment of all outlines */ 67 FLOAT64 L; /* total length of all outlines */ 68 FLOAT64 x, y; /* center of mass of all outlines */ 69 FLOAT64 Ix, Iy; /* second moments about center of mass axes */ 70 FLOAT64 Rx, Ry; /* radius of gyration about center of mass axes */ 71 } 72 73 74 OUTLINE_STATS; 75 76 typedef enum { 77 baseline, character 78 } 79 80 81 NORM_METHOD; 82 83 /*---------------------------------------------------------------------------- 84 Variables 85 ------------------------------------------------------------------------------*/ 86 /* control knobs used to control normalization of outlines */ 87 extern INT_VAR_H(classify_norm_method, character, 88 "Normalization Method ..."); 89 /* PREV DEFAULT "baseline" */ 90 extern double_VAR_H(classify_char_norm_range, 0.2, 91 "Character Normalization Range ..."); 92 extern double_VAR_H(classify_min_norm_scale_x, 0.0, 93 "Min char x-norm scale ..."); 94 /* PREV DEFAULT 0.1 */ 95 extern double_VAR_H(classify_max_norm_scale_x, 0.325, 96 "Max char x-norm scale ..."); 97 /* PREV DEFAULT 0.3 */ 98 extern double_VAR_H(classify_min_norm_scale_y, 0.0, 99 "Min char y-norm scale ..."); 100 /* PREV DEFAULT 0.1 */ 101 extern double_VAR_H(classify_max_norm_scale_y, 0.325, 102 "Max char y-norm scale ..."); 103 /* PREV DEFAULT 0.3 */ 104 105 /**---------------------------------------------------------------------------- 106 Macros 107 ----------------------------------------------------------------------------**/ 108 #define AverageOf(A,B) (((A) + (B)) / 2) 109 110 /* macro for computing the baseline of a row of text at an x position */ 111 #define BaselineAt(L,X) (BASELINE_OFFSET) 112 113 /* macro for computing the scale factor to use to normalize characters */ 114 #define ComputeScaleFactor(L) \ 115 (NORMAL_X_HEIGHT / ((classify_baseline_normalized)? \ 116 (BASELINE_SCALE): \ 117 ((L)->xheight))) 118 119 /* macros for manipulating micro-feature outlines */ 120 #define DegenerateOutline(O) (((O) == NIL) || ((O) == rest(O))) 121 #define PointAt(O) ((MFEDGEPT *) first_node (O)) 122 #define NextPointAfter(E) (rest (E)) 123 #define MakeOutlineCircular(O) (set_rest (last (O), (O))) 124 125 /* macros for manipulating micro-feature outline edge points */ 126 #define ClearMark(P) ((P)->ExtremityMark = FALSE) 127 #define MarkPoint(P) ((P)->ExtremityMark = TRUE) 128 129 /**---------------------------------------------------------------------------- 130 Public Function Prototypes 131 ----------------------------------------------------------------------------**/ 132 void ComputeBlobCenter(TBLOB *Blob, TPOINT *BlobCenter); 133 134 LIST ConvertBlob(TBLOB *Blob); 135 136 MFOUTLINE ConvertOutline(TESSLINE *Outline); 137 138 LIST ConvertOutlines(TESSLINE *Outline, 139 LIST ConvertedOutlines, 140 OUTLINETYPE OutlineType); 141 142 void ComputeOutlineStats(LIST Outlines, OUTLINE_STATS *OutlineStats); 143 144 void FilterEdgeNoise(MFOUTLINE Outline, FLOAT32 NoiseSegmentLength); 145 146 void FindDirectionChanges(MFOUTLINE Outline, 147 FLOAT32 MinSlope, 148 FLOAT32 MaxSlope); 149 150 void FreeMFOutline(void *agr); //MFOUTLINE Outline); 151 152 void FreeOutlines(LIST Outlines); 153 154 void MarkDirectionChanges(MFOUTLINE Outline); 155 156 MFEDGEPT *NewEdgePoint(); 157 158 MFOUTLINE NextExtremity(MFOUTLINE EdgePoint); 159 160 void NormalizeOutline(MFOUTLINE Outline, 161 LINE_STATS *LineStats, 162 FLOAT32 XOrigin); 163 164 void NormalizeOutlines(LIST Outlines, 165 LINE_STATS *LineStats, 166 FLOAT32 *XScale, 167 FLOAT32 *YScale); 168 169 void SettupBlobConversion(TBLOB *Blob); 170 171 void SmearExtremities(MFOUTLINE Outline, FLOAT32 XScale, FLOAT32 YScale); 172 173 /*---------------------------------------------------------------------------- 174 Private Function Prototypes 175 -----------------------------------------------------------------------------*/ 176 void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction); 177 178 void CharNormalizeOutline(MFOUTLINE Outline, 179 FLOAT32 XCenter, 180 FLOAT32 YCenter, 181 FLOAT32 XScale, 182 FLOAT32 YScale); 183 184 void ComputeDirection(MFEDGEPT *Start, 185 MFEDGEPT *Finish, 186 FLOAT32 MinSlope, 187 FLOAT32 MaxSlope); 188 189 void FinishOutlineStats(register OUTLINE_STATS *OutlineStats); 190 191 void InitOutlineStats(OUTLINE_STATS *OutlineStats); 192 193 MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint); 194 195 void UpdateOutlineStats(register OUTLINE_STATS *OutlineStats, 196 register FLOAT32 x1, 197 register FLOAT32 x2, 198 register FLOAT32 y1, 199 register FLOAT32 y2); 200 201 #endif 202