All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 class FCOORD;
32 
33 /* define order of params in pruners */
34 #define PRUNER_X 0
35 #define PRUNER_Y 1
36 #define PRUNER_ANGLE 2
37 
38 /* definition of coordinate system offsets for each table parameter */
39 #define ANGLE_SHIFT (0.0)
40 #define X_SHIFT (0.5)
41 #define Y_SHIFT (0.5)
42 
43 #define MAX_PROTO_INDEX 24
44 #define BITS_PER_WERD static_cast<int>(8 * sizeof(uinT32))
45 /* Script detection: increase this number to 128 */
46 #define MAX_NUM_CONFIGS 64
47 #define MAX_NUM_PROTOS 512
48 #define PROTOS_PER_PROTO_SET 64
49 #define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
50 #define NUM_PP_PARAMS 3
51 #define NUM_PP_BUCKETS 64
52 #define NUM_CP_BUCKETS 24
53 #define CLASSES_PER_CP 32
54 #define NUM_BITS_PER_CLASS 2
55 #define CLASS_PRUNER_CLASS_MASK (~(~0 << NUM_BITS_PER_CLASS))
56 #define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
57 #define PROTOS_PER_PP_WERD BITS_PER_WERD
58 #define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
59 #define MAX_NUM_CLASS_PRUNERS ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / \
60  CLASSES_PER_CP)
61 #define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD)
62 #define WERDS_PER_PP_VECTOR ((PROTOS_PER_PROTO_SET+BITS_PER_WERD-1)/ \
63  BITS_PER_WERD)
64 #define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * \
65  WERDS_PER_PP_VECTOR)
66 #define WERDS_PER_CP (NUM_CP_BUCKETS * NUM_CP_BUCKETS * \
67  NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
68 #define WERDS_PER_CONFIG_VEC ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / \
69  BITS_PER_WERD)
70 
71 /* The first 3 dimensions of the CLASS_PRUNER_STRUCT are the
72  * 3 axes of the quantized feature space.
73  * The position of the the bits recorded for each class in the
74  * 4th dimension is determined by using CPrunerWordIndexFor(c),
75  * where c is the corresponding class id. */
78 };
79 
80 typedef struct
81 {
87 }
88 
89 
91 
93 
94 typedef struct
95 {
98 }
99 
100 
102 
104 
105 
106 typedef struct
107 {
111  PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS];
113  uinT16 ConfigLengths[MAX_NUM_CONFIGS];
114  int font_set_id; // FontSet id, see above
115 }
116 
117 
119 
120 typedef struct
121 {
124  INT_CLASS Class[MAX_NUM_CLASSES];
126 }
127 
128 
130 
131 /* definitions of integer features*/
132 #define MAX_NUM_INT_FEATURES 512
133 #define INT_CHAR_NORM_RANGE 256
134 
136  INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) { }
137  // Builds a feature from an FCOORD for position with all the necessary
138  // clipping and rounding.
139  INT_FEATURE_STRUCT(const FCOORD& pos, uinT8 theta);
140  // Builds a feature from ints with all the necessary clipping and casting.
141  INT_FEATURE_STRUCT(int x, int y, int theta);
142 
147 
148  void print() const {
149  tprintf("(%d,%d):%d\n", X, Y, Theta);
150  }
151 };
152 
154 
156 
162 };
163 
168 #define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
169 #define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
170 #define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
171 #define ProtoForProtoId(C,P) (&((C->ProtoSets[SetForProto (P)])-> \
172  Protos [IndexForProto (P)]))
173 #define PPrunerWordIndexFor(I) (((I) % PROTOS_PER_PROTO_SET) / \
174  PROTOS_PER_PP_WERD)
175 #define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
176 #define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor (I))
177 
178 #define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
179 #define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
180 #define UnusedClassIdIn(T,c) ((T)->Class[c] == NULL)
181 #define ClassForClassId(T,c) ((T)->Class[c])
182 #define ClassPrunersFor(T) ((T)->ClassPruner)
183 #define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
184 #define CPrunerFor(T,c) ((T)->ClassPruners[CPrunerIdFor(c)])
185 #define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
186 #define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
187 #define CPrunerMaskFor(L,c) (((L)+1) << CPrunerBitIndexFor (c) * NUM_BITS_PER_CLASS)
188 
189 /* DEBUG macros*/
190 #define PRINT_MATCH_SUMMARY 0x001
191 #define DISPLAY_FEATURE_MATCHES 0x002
192 #define DISPLAY_PROTO_MATCHES 0x004
193 #define PRINT_FEATURE_MATCHES 0x008
194 #define PRINT_PROTO_MATCHES 0x010
195 #define CLIP_MATCH_EVIDENCE 0x020
196 
197 #define MatchDebuggingOn(D) (D)
198 #define PrintMatchSummaryOn(D) ((D) & PRINT_MATCH_SUMMARY)
199 #define DisplayFeatureMatchesOn(D) ((D) & DISPLAY_FEATURE_MATCHES)
200 #define DisplayProtoMatchesOn(D) ((D) & DISPLAY_PROTO_MATCHES)
201 #define PrintFeatureMatchesOn(D) ((D) & PRINT_FEATURE_MATCHES)
202 #define PrintProtoMatchesOn(D) ((D) & PRINT_PROTO_MATCHES)
203 #define ClipMatchEvidenceOn(D) ((D) & CLIP_MATCH_EVIDENCE)
204 
208 void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class);
209 
210 int AddIntConfig(INT_CLASS Class);
211 
212 int AddIntProto(INT_CLASS Class);
213 
214 void AddProtoToClassPruner(PROTO Proto,
215  CLASS_ID ClassId,
216  INT_TEMPLATES Templates);
217 
218 void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
219  INT_CLASS Class, bool debug);
220 
221 uinT8 Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets);
222 uinT16 Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets);
223 
224 uinT8 CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets);
225 
226 void UpdateMatchDisplay();
227 
228 void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
229 
230 void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, FLOAT32 Evidence);
231 
232 void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence);
233 
234 INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
235 
236 INT_TEMPLATES NewIntTemplates();
237 
238 void free_int_templates(INT_TEMPLATES templates);
239 
240 void ShowMatchDisplay();
241 
242 namespace tesseract {
243 
244 // Clears the given window and draws the featurespace guides for the
245 // appropriate normalization method.
246 void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window);
247 
248 } // namespace tesseract.
249 
250 /*----------------------------------------------------------------------------*/
251 #ifndef GRAPHICS_DISABLED
252 void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
253  ScrollView::Color color);
254 
256 
258 
260 
261 // Creates a window of the appropriate size for displaying elements
262 // in feature space.
263 ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos);
264 #endif // GRAPHICS_DISABLED
265 
266 #endif
#define NUM_CP_BUCKETS
Definition: intproto.h:52
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs)
Definition: intproto.cpp:672
float FLOAT32
Definition: host.h:111
inT16 PROTO_ID
Definition: matchdefs.h:41
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
Definition: intproto.cpp:1104
int AddIntConfig(INT_CLASS Class)
Definition: intproto.cpp:272
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
Definition: intproto.cpp:240
#define WERDS_PER_PP_VECTOR
Definition: intproto.h:62
struct INT_PROTO_STRUCT * INT_PROTO
#define MAX_NUM_CONFIGS
Definition: intproto.h:46
void free_int_templates(INT_TEMPLATES templates)
Definition: intproto.cpp:748
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
#define tprintf(...)
Definition: tprintf.h:31
uinT32 CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]
Definition: intproto.h:103
struct INT_CLASS_STRUCT * INT_CLASS
int AddIntProto(INT_CLASS Class)
Definition: intproto.cpp:295
void UpdateMatchDisplay()
Definition: intproto.cpp:473
uinT16 Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:445
uinT32 PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
Definition: intproto.h:92
IntmatcherDebugAction
Definition: intproto.h:157
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
Definition: intproto.cpp:389
INT_TEMPLATES NewIntTemplates()
Definition: intproto.cpp:732
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:35
#define WERDS_PER_CP_VECTOR
Definition: intproto.h:61
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:49
uinT8 Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:441
#define MAX_NUM_CLASS_PRUNERS
Definition: intproto.h:59
unsigned int uinT32
Definition: host.h:103
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence)
Definition: intproto.cpp:630
name_table name
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:155
#define MAX_NUM_INT_FEATURES
Definition: intproto.h:132
void ShowMatchDisplay()
#define NUM_PP_PARAMS
Definition: intproto.h:50
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1936
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES
#define NUM_PP_BUCKETS
Definition: intproto.h:51
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence)
Definition: intproto.cpp:652
void InitProtoDisplayWindowIfReqd()
Definition: intproto.cpp:1916
CLUSTERCONFIG Config
INT_FEATURE_STRUCT * INT_FEATURE
Definition: intproto.h:153
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
Definition: intproto.cpp:493
uinT8 NumProtoSets
Definition: intproto.h:109
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:48
void InitIntMatchWindowIfReqd()
Definition: intproto.cpp:1895
void InitFeatureDisplayWindowIfReqd()
Definition: intproto.cpp:1927
uinT8 NumConfigs
Definition: intproto.h:110
uinT8 CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:455
uinT32 p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:77
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1770
void print() const
Definition: intproto.h:148
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
Definition: intproto.cpp:346
SIGNED char inT8
Definition: host.h:98
uinT8 * ProtoLengths
Definition: intproto.h:112
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:68
NORM_METHOD
Definition: mfoutline.h:53
Definition: points.h:189
uinT16 NumProtos
Definition: intproto.h:108
struct PROTO_SET_STRUCT * PROTO_SET
unsigned short uinT16
Definition: host.h:101
unsigned char uinT8
Definition: host.h:99