Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
intproto.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Filename: intproto.h
3 ** Purpose: Definition of data structures for integer protos.
4 ** Author: Dan Johnson
5 ** History: Thu Feb 7 12:58:45 1991, 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 INTPROTO_H
19 #define INTPROTO_H
20
24 #include "genericvector.h"
25 #include "matchdefs.h"
26 #include "mfoutline.h"
27 #include "protos.h"
28 #include "scrollview.h"
29 #include "unicharset.h"
30
31 /* define order of params in pruners */
32 #define PRUNER_X 0
33 #define PRUNER_Y 1
34 #define PRUNER_ANGLE 2
35
36 /* definition of coordinate system offsets for each table parameter */
37 #define ANGLE_SHIFT (0.0)
38 #define X_SHIFT (0.5)
39 #define Y_SHIFT (0.5)
40
41 #define MAX_PROTO_INDEX 24
42 #define BITS_PER_WERD (8 * sizeof (uinT32))
43 /* Script detection: increase this number to 128 */
44 #define MAX_NUM_CONFIGS 64
45 #define MAX_NUM_PROTOS 512
46 #define PROTOS_PER_PROTO_SET 64
47 #define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
48 #define NUM_PP_PARAMS 3
49 #define NUM_PP_BUCKETS 64
50 #define NUM_CP_BUCKETS 24
51 #define CLASSES_PER_CP 32
52 #define NUM_BITS_PER_CLASS 2
53 #define CLASS_PRUNER_CLASS_MASK (~(~0 << NUM_BITS_PER_CLASS))
54 #define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
55 #define PROTOS_PER_PP_WERD BITS_PER_WERD
56 #define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
57 #define MAX_NUM_CLASS_PRUNERS ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / \
58 CLASSES_PER_CP)
59 #define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD)
60 #define WERDS_PER_PP_VECTOR ((PROTOS_PER_PROTO_SET+BITS_PER_WERD-1)/ \
61 BITS_PER_WERD)
62 #define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * \
63 WERDS_PER_PP_VECTOR)
64 #define WERDS_PER_CP (NUM_CP_BUCKETS * NUM_CP_BUCKETS * \
65 NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
66 #define WERDS_PER_CONFIG_VEC ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / \
67 BITS_PER_WERD)
68
69 /* The first 3 dimensions of the CLASS_PRUNER_STRUCT are the
70 * 3 axes of the quantized feature space.
71 * The position of the the bits recorded for each class in the
72 * 4th dimension is determined by using CPrunerWordIndexFor(c),
73 * where c is the corresponding class id. */
74 struct CLASS_PRUNER_STRUCT {
75 uinT32 p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR];
76 };
77
78 typedef struct
79 {
80 inT8 A;
81 uinT8 B;
82 inT8 C;
83 uinT8 Angle;
84 uinT32 Configs[WERDS_PER_CONFIG_VEC];
85 }
86
87
88 INT_PROTO_STRUCT, *INT_PROTO;
89
90 typedef uinT32 PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR];
91
92 typedef struct
93 {
94 PROTO_PRUNER ProtoPruner;
95 INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET];
96 }
97
98
99 PROTO_SET_STRUCT, *PROTO_SET;
100
101 typedef uinT32 CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4];
102
103
104 typedef struct
105 {
106 uinT16 NumProtos;
107 uinT8 NumProtoSets;
108 uinT8 NumConfigs;
109 PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS];
110 uinT8 *ProtoLengths;
111 uinT16 ConfigLengths[MAX_NUM_CONFIGS];
112 int font_set_id; // FontSet id, see above
113 }
114
115
116 INT_CLASS_STRUCT, *INT_CLASS;
117
118 typedef struct
119 {
120 int NumClasses;
121 int NumClassPruners;
122 INT_CLASS Class[MAX_NUM_CLASSES];
123 CLASS_PRUNER_STRUCT* ClassPruners[MAX_NUM_CLASS_PRUNERS];
124 }
125
126
127 INT_TEMPLATES_STRUCT, *INT_TEMPLATES;
128
129 /* definitions of integer features*/
130 #define MAX_NUM_INT_FEATURES 512
131 #define INT_CHAR_NORM_RANGE 256
132
133 struct INT_FEATURE_STRUCT
134 {
135 uinT8 X;
136 uinT8 Y;
137 uinT8 Theta;
138 inT8 CP_misses;
139
140 void print() const {
141 tprintf("(%d,%d):%d\n", X, Y, Theta);
142 }
143 };
144
145 typedef INT_FEATURE_STRUCT *INT_FEATURE;
146
147 typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES];
148
149 enum IntmatcherDebugAction {
150 IDA_ADAPTIVE,
151 IDA_STATIC,
152 IDA_SHAPE_INDEX,
153 IDA_BOTH
154 };
155
160 #define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
161 #define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
162 #define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
163 #define ProtoForProtoId(C,P) (&((C->ProtoSets[SetForProto (P)])-> \
164 Protos [IndexForProto (P)]))
165 #define PPrunerWordIndexFor(I) (((I) % PROTOS_PER_PROTO_SET) / \
166 PROTOS_PER_PP_WERD)
167 #define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
168 #define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor (I))
169
170 #define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
171 #define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
172 #define UnusedClassIdIn(T,c) ((T)->Class[c] == NULL)
173 #define ClassForClassId(T,c) ((T)->Class[c])
174 #define ClassPrunersFor(T) ((T)->ClassPruner)
175 #define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
176 #define CPrunerFor(T,c) ((T)->ClassPruners[CPrunerIdFor(c)])
177 #define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
178 #define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
179 #define CPrunerMaskFor(L,c) (((L)+1) << CPrunerBitIndexFor (c) * NUM_BITS_PER_CLASS)
180
181 /* DEBUG macros*/
182 #define PRINT_MATCH_SUMMARY 0x001
183 #define DISPLAY_FEATURE_MATCHES 0x002
184 #define DISPLAY_PROTO_MATCHES 0x004
185 #define PRINT_FEATURE_MATCHES 0x008
186 #define PRINT_PROTO_MATCHES 0x010
187 #define CLIP_MATCH_EVIDENCE 0x020
188
189 #define MatchDebuggingOn(D) (D)
190 #define PrintMatchSummaryOn(D) ((D) & PRINT_MATCH_SUMMARY)
191 #define DisplayFeatureMatchesOn(D) ((D) & DISPLAY_FEATURE_MATCHES)
192 #define DisplayProtoMatchesOn(D) ((D) & DISPLAY_PROTO_MATCHES)
193 #define PrintFeatureMatchesOn(D) ((D) & PRINT_FEATURE_MATCHES)
194 #define PrintProtoMatchesOn(D) ((D) & PRINT_PROTO_MATCHES)
195 #define ClipMatchEvidenceOn(D) ((D) & CLIP_MATCH_EVIDENCE)
196
200 void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class);
201
202 int AddIntConfig(INT_CLASS Class);
203
204 int AddIntProto(INT_CLASS Class);
205
206 void AddProtoToClassPruner(PROTO Proto,
207 CLASS_ID ClassId,
208 INT_TEMPLATES Templates);
209
210 void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
211 INT_CLASS Class, bool debug);
212
213 int BucketFor(FLOAT32 Param, FLOAT32 Offset, int NumBuckets);
214
215 int CircBucketFor(FLOAT32 Param, FLOAT32 Offset, int NumBuckets);
216
217 void UpdateMatchDisplay();
218
219 void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
220
221 void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, FLOAT32 Evidence);
222
223 void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence);
224
225 INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
226
227 INT_TEMPLATES NewIntTemplates();
228
229 void free_int_templates(INT_TEMPLATES templates);
230
231 void ShowMatchDisplay();
232
233 namespace tesseract {
234
235 // Clears the given window and draws the featurespace guides for the
236 // appropriate normalization method.
237 void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window);
238
239 } // namespace tesseract.
240
241 /*----------------------------------------------------------------------------*/
242 #ifndef GRAPHICS_DISABLED
243 void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
244 ScrollView::Color color);
245
246 void InitIntMatchWindowIfReqd();
247
248 void InitProtoDisplayWindowIfReqd();
249
250 void InitFeatureDisplayWindowIfReqd();
251
252 // Creates a window of the appropriate size for displaying elements
253 // in feature space.
254 ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos);
255 #endif // GRAPHICS_DISABLED
256
257 #endif