• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File:        protos.h  (Formerly protos.h)
5  * Description:
6  * Author:       Mark Seaman, SW Productivity
7  * Created:      Fri Oct 16 14:37:00 1987
8  * Modified:     Fri Jul 12 10:06:55 1991 (Dan Johnson) danj@hpgrlj
9  * Language:     C
10  * Package:      N/A
11  * Status:       Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  *********************************************************************************/
25 #ifndef PROTOS_H
26 #define PROTOS_H
27 
28 /*----------------------------------------------------------------------
29               I n c l u d e s
30 ----------------------------------------------------------------------*/
31 #include "bitvec.h"
32 #include "cutil.h"
33 #include "unichar.h"
34 #include "unicity_table.h"
35 #include "varable.h"
36 
37 /*----------------------------------------------------------------------
38               T y p e s
39 ----------------------------------------------------------------------*/
40 typedef BIT_VECTOR *CONFIGS;
41 
42 typedef struct
43 {
44   FLOAT32 A;
45   FLOAT32 B;
46   FLOAT32 C;
47   FLOAT32 X;
48   FLOAT32 Y;
49   FLOAT32 Angle;
50   FLOAT32 Length;
51 } PROTO_STRUCT;
52 typedef PROTO_STRUCT *PROTO;
53 
54 typedef struct
55 {
56   inT16 NumProtos;
57   inT16 MaxNumProtos;
58   PROTO Prototypes;
59   inT16 NumConfigs;
60   inT16 MaxNumConfigs;
61   CONFIGS Configurations;
62   UnicityTableEqEq<int> font_set;
63 } CLASS_STRUCT;
64 typedef CLASS_STRUCT *CLASS_TYPE;
65 typedef CLASS_STRUCT *CLASSES;
66 
67 /*----------------------------------------------------------------------
68               C o n s t a n t s
69 ----------------------------------------------------------------------*/
70 #define NUMBER_OF_CLASSES  MAX_NUM_CLASSES
71 #define Y_OFFSET           -40.0
72 #define FEATURE_SCALE      100.0
73 
74 /*----------------------------------------------------------------------
75               V a r i a b l e s
76 ----------------------------------------------------------------------*/
77 extern CLASS_STRUCT TrainingData[];
78 
79 extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
80 
81 /*----------------------------------------------------------------------
82               M a c r o s
83 ----------------------------------------------------------------------*/
84 /**********************************************************************
85  * AddProtoToConfig
86  *
87  * Set a single proto bit in the specified configuration.
88  **********************************************************************/
89 
90 #define AddProtoToConfig(Pid,Config)	\
91 (SET_BIT (Config, Pid))
92 
93 /**********************************************************************
94  * RemoveProtoFromConfig
95  *
96  * Clear a single proto bit in the specified configuration.
97  **********************************************************************/
98 
99 #define RemoveProtoFromConfig(Pid,Config)	\
100 (reset_bit (Config, Pid))
101 
102 /**********************************************************************
103  * ClassOfChar
104  *
105  * Return the class of a particular ASCII character value.
106  **********************************************************************/
107 
108 #define ClassOfChar(Char)            \
109 ((TrainingData [Char].NumProtos) ? \
110 	(& TrainingData [Char])         : \
111 	NO_CLASS)
112 
113 /**********************************************************************
114  * ProtoIn
115  *
116  * Choose the selected prototype in this class record.  Return the
117  * pointer to it (type PROTO).
118  **********************************************************************/
119 
120 #define ProtoIn(Class,Pid)  \
121 (& (Class)->Prototypes [Pid])
122 
123 /**********************************************************************
124  * PrintProto
125  *
126  * Print out the contents of a prototype.   The 'Proto' argument is of
127  * type 'PROTO'.
128  **********************************************************************/
129 
130 #define PrintProto(Proto)                      \
131 (cprintf ("X=%4.2f, Y=%4.2f, Angle=%4.2f",    \
132           Proto->X,                \
133           Proto->Y,                \
134           Proto->Length,                \
135           Proto->Angle))                \
136 
137 
138 /**********************************************************************
139  * PrintProtoLine
140  *
141  * Print out the contents of a prototype.   The 'Proto' argument is of
142  * type 'PROTO'.
143  **********************************************************************/
144 
145 #define PrintProtoLine(Proto)             \
146 (cprintf ("A=%4.2f, B=%4.2f, C=%4.2f",   \
147 			Proto->A,           \
148 			Proto->B,           \
149 			Proto->C))           \
150 
151 /*----------------------------------------------------------------------
152               F u n c t i o n s
153 ----------------------------------------------------------------------*/
154 int AddConfigToClass(CLASS_TYPE Class);
155 
156 int AddProtoToClass(CLASS_TYPE Class);
157 
158 FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config);
159 
160 FLOAT32 ClassProtoLength(CLASS_TYPE Class);
161 
162 void CopyProto(PROTO Src, PROTO Dest);
163 
164 void FillABC(PROTO Proto);
165 
166 void FreeClass(CLASS_TYPE Class);
167 
168 void FreeClassFields(CLASS_TYPE Class);
169 
170 void InitPrototypes();
171 
172 CLASS_TYPE NewClass(int NumProtos, int NumConfigs);
173 
174 void PrintProtos(CLASS_TYPE Class);
175 
176 void ReadClassFromFile(FILE *File, UNICHAR_ID unichar_id);
177 
178 void ReadConfigs(register FILE *File, CLASS_TYPE Class);
179 
180 void ReadProtos(register FILE *File, CLASS_TYPE Class);
181 
182 int SplitProto(CLASS_TYPE Class, int OldPid);
183 
184 void WriteOldConfigFile(FILE *File, CLASS_TYPE Class);
185 
186 void WriteOldProtoFile(FILE *File, CLASS_TYPE Class);
187 
188 #endif
189