1 /****************************************************************************** 2 ** Filename: features.h 3 ** Purpose: Generic definition of a feature. 4 ** Author: Dan Johnson 5 ** History: Sun May 20 10:28:30 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 FEATURES_H 19 #define FEATURES_H 20 21 /**---------------------------------------------------------------------------- 22 Include Files and Type Defines 23 ----------------------------------------------------------------------------**/ 24 #include "funcdefs.h" 25 #include "tessclas.h" 26 #include "fxdefs.h" 27 28 #include <stdio.h> 29 30 #undef Min 31 #undef Max 32 #define FEAT_NAME_SIZE 80 33 34 /*define trap errors which can be caused by this module*/ 35 #define ILLEGAL_FEATURE_PARAM 1000 36 #define ILLEGAL_NUM_FEATURES 1001 37 38 /* A character is described by multiple sets of extracted features. Each 39 set contains a number of features of a particular type, for example, a 40 set of bays, or a set of closures, or a set of microfeatures. Each 41 feature consists of a number of parameters. All features within a 42 feature set contain the same number of parameters. All circular 43 parameters are required to be the first parameters in the feature.*/ 44 45 typedef struct 46 { 47 struct fds *Type; /* points to description of feature type */ 48 FLOAT32 Params[1]; /* variable size array - params for feature */ 49 } FEATURE_STRUCT; 50 typedef FEATURE_STRUCT *FEATURE; 51 52 typedef struct 53 { 54 uinT16 NumFeatures; /* number of features in set */ 55 uinT16 MaxNumFeatures; /* maximum size of feature set */ 56 FEATURE Features[1]; /* variable size array of features */ 57 } FEATURE_SET_STRUCT; 58 typedef FEATURE_SET_STRUCT *FEATURE_SET; 59 60 /* Define various function types which will be needed for "class methods"*/ 61 typedef FEATURE (*FEAT_FUNC) (); 62 typedef FEATURE_SET (*FX_FUNC) (TBLOB *, LINE_STATS *); 63 typedef FLOAT32 (*PENALTY_FUNC) (); 64 65 typedef struct 66 { 67 inT8 Circular; /* TRUE if dimension wraps around */ 68 inT8 NonEssential; /* TRUE if dimension not used in searches */ 69 FLOAT32 Min; /* low end of range for circular dimensions */ 70 FLOAT32 Max; /* high end of range for circular dimensions */ 71 FLOAT32 Range; /* Max - Min */ 72 FLOAT32 HalfRange; /* (Max - Min)/2 */ 73 FLOAT32 MidRange; /* (Max + Min)/2 */ 74 } PARAM_DESC; 75 76 typedef struct fds 77 { 78 uinT16 NumParams; /* total # of params */ 79 uinT8 NumLinearParams; /* # of linear params */ 80 uinT8 NumCircularParams; /* # of linear params */ 81 uinT8 MinFeatPerChar; /* min # of feats allowed */ 82 uinT8 MaxFeatPerChar; /* max # of feats allowed */ 83 char LongName[FEAT_NAME_SIZE]; /* long name for feature */ 84 char ShortName[FEAT_NAME_SIZE];/* short name for feature */ 85 PARAM_DESC *ParamDesc; /* array - one per param */ 86 } FEATURE_DESC_STRUCT; 87 /* one per feature type */ 88 typedef FEATURE_DESC_STRUCT *FEATURE_DESC; 89 90 typedef struct fxs 91 { 92 FX_FUNC Extractor; /* func to extract features */ 93 } FEATURE_EXT_STRUCT; 94 95 /*---------------------------------------------------------------------- 96 Macros for defining the parameters of a new features 97 ----------------------------------------------------------------------*/ 98 #define StartParamDesc(Name) \ 99 static PARAM_DESC Name[] = { 100 101 #define DefineParam(Circular, NonEssential, Min, Max) \ 102 {Circular, NonEssential, Min, Max, \ 103 (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)}, 104 105 #define EndParamDesc }; 106 107 /*---------------------------------------------------------------------- 108 Macro for describing a new feature. The parameters of the macro 109 are as follows: 110 111 DefineFeature (Name, NumLinear, NumCircular, 112 MinFeatPerChar, MaxFeatPerChar, 113 LongName, ShortName, ParamName) 114 ----------------------------------------------------------------------*/ 115 #define DefineFeature(Name, NL, NC, Min, Max, LN, SN, PN) \ 116 FEATURE_DESC_STRUCT Name = { \ 117 ((NL) + (NC)), NL, NC, Min, Max, LN, SN, PN}; 118 119 #define DefineFeatureExt(Name, E) FEATURE_EXT_STRUCT Name = {E}; 120 121 /*---------------------------------------------------------------------- 122 Generic routines that work for all feature types 123 ----------------------------------------------------------------------*/ 124 BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature); 125 126 void FreeFeature(FEATURE Feature); 127 128 void FreeFeatureSet(FEATURE_SET FeatureSet); 129 130 FEATURE NewFeature(FEATURE_DESC FeatureDesc); 131 132 FEATURE_SET NewFeatureSet(int NumFeatures); 133 134 FEATURE ReadFeature(FILE *File, FEATURE_DESC FeatureDesc); 135 136 FEATURE_SET ReadFeatureSet(FILE *File, FEATURE_DESC FeatureDesc); 137 138 void WriteFeature(FILE *File, FEATURE Feature); 139 140 void WriteFeatureSet(FILE *File, FEATURE_SET FeatureSet); 141 142 void WriteOldParamDesc(FILE *File, FEATURE_DESC FeatureDesc); 143 #endif 144