tesseract  4.0.0-1-g2a2b
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 
19 #ifndef INTPROTO_H
20 #define INTPROTO_H
21 
25 #include "genericvector.h"
26 #include "matchdefs.h"
27 #include "mfoutline.h"
28 #include "protos.h"
29 #include "scrollview.h"
30 #include "unicharset.h"
31 
32 class FCOORD;
33 
34 /* define order of params in pruners */
35 #define PRUNER_X 0
36 #define PRUNER_Y 1
37 #define PRUNER_ANGLE 2
38 
39 /* definition of coordinate system offsets for each table parameter */
40 #define ANGLE_SHIFT (0.0)
41 #define X_SHIFT (0.5)
42 #define Y_SHIFT (0.5)
43 
44 #define MAX_PROTO_INDEX 24
45 #define BITS_PER_WERD static_cast<int>(8 * sizeof(uint32_t))
46 /* Script detection: increase this number to 128 */
47 #define MAX_NUM_CONFIGS 64
48 #define MAX_NUM_PROTOS 512
49 #define PROTOS_PER_PROTO_SET 64
50 #define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
51 #define NUM_PP_PARAMS 3
52 #define NUM_PP_BUCKETS 64
53 #define NUM_CP_BUCKETS 24
54 #define CLASSES_PER_CP 32
55 #define NUM_BITS_PER_CLASS 2
56 #define CLASS_PRUNER_CLASS_MASK (~(~0u << NUM_BITS_PER_CLASS))
57 #define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
58 #define PROTOS_PER_PP_WERD BITS_PER_WERD
59 #define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
60 #define MAX_NUM_CLASS_PRUNERS \
61  ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / CLASSES_PER_CP)
62 #define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD)
63 #define WERDS_PER_PP_VECTOR \
64  ((PROTOS_PER_PROTO_SET + BITS_PER_WERD - 1) / BITS_PER_WERD)
65 #define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR)
66 #define WERDS_PER_CP \
67  (NUM_CP_BUCKETS * NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
68 #define WERDS_PER_CONFIG_VEC \
69  ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / 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. */
79 };
80 
81 typedef struct {
82  int8_t A;
83  uint8_t B;
84  int8_t C;
85  uint8_t Angle;
86  uint32_t Configs[WERDS_PER_CONFIG_VEC];
87 }
88 
90  *INT_PROTO;
91 
92 typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS]
94 
95 typedef struct {
98 }
99 
101  *PROTO_SET;
102 
104 
105 typedef struct {
106  uint16_t NumProtos;
107  uint8_t NumProtoSets;
108  uint8_t NumConfigs;
110  uint8_t* ProtoLengths;
111  uint16_t ConfigLengths[MAX_NUM_CONFIGS];
112  int font_set_id; // FontSet id, see above
113 }
114 
116  *INT_CLASS;
117 
118 typedef struct {
123 }
124 
126  *INT_TEMPLATES;
127 
128 /* definitions of integer features*/
129 #define MAX_NUM_INT_FEATURES 512
130 #define INT_CHAR_NORM_RANGE 256
131 
133  INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) {}
134  // Builds a feature from an FCOORD for position with all the necessary
135  // clipping and rounding.
136  INT_FEATURE_STRUCT(const FCOORD& pos, uint8_t theta);
137  // Builds a feature from ints with all the necessary clipping and casting.
138  INT_FEATURE_STRUCT(int x, int y, int theta);
139 
140  uint8_t X;
141  uint8_t Y;
142  uint8_t Theta;
143  int8_t CP_misses;
144 
145  void print() const { tprintf("(%d,%d):%d\n", X, Y, Theta); }
146 };
147 
149 
151 
157 };
158 
163 #define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
164 #define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
165 #define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
166 #define ProtoForProtoId(C, P) \
167  (&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)]))
168 #define PPrunerWordIndexFor(I) \
169  (((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD)
170 #define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
171 #define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor(I))
172 
173 #define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
174 #define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
175 #define UnusedClassIdIn(T, c) ((T)->Class[c] == nullptr)
176 #define ClassForClassId(T, c) ((T)->Class[c])
177 #define ClassPrunersFor(T) ((T)->ClassPruner)
178 #define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
179 #define CPrunerFor(T, c) ((T)->ClassPruners[CPrunerIdFor(c)])
180 #define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
181 #define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
182 #define CPrunerMaskFor(L, c) \
183  (((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS)
184 
185 /* DEBUG macros*/
186 #define PRINT_MATCH_SUMMARY 0x001
187 #define DISPLAY_FEATURE_MATCHES 0x002
188 #define DISPLAY_PROTO_MATCHES 0x004
189 #define PRINT_FEATURE_MATCHES 0x008
190 #define PRINT_PROTO_MATCHES 0x010
191 #define CLIP_MATCH_EVIDENCE 0x020
192 
193 #define MatchDebuggingOn(D) (D)
194 #define PrintMatchSummaryOn(D) ((D)&PRINT_MATCH_SUMMARY)
195 #define DisplayFeatureMatchesOn(D) ((D)&DISPLAY_FEATURE_MATCHES)
196 #define DisplayProtoMatchesOn(D) ((D)&DISPLAY_PROTO_MATCHES)
197 #define PrintFeatureMatchesOn(D) ((D)&PRINT_FEATURE_MATCHES)
198 #define PrintProtoMatchesOn(D) ((D)&PRINT_PROTO_MATCHES)
199 #define ClipMatchEvidenceOn(D) ((D)&CLIP_MATCH_EVIDENCE)
200 
204 void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class);
205 
206 int AddIntConfig(INT_CLASS Class);
207 
208 int AddIntProto(INT_CLASS Class);
209 
210 void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId,
211  INT_TEMPLATES Templates);
212 
213 void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class,
214  bool debug);
215 
216 uint8_t Bucket8For(float param, float offset, int num_buckets);
217 uint16_t Bucket16For(float param, float offset, int num_buckets);
218 
219 uint8_t CircBucketFor(float param, float offset, int num_buckets);
220 
221 void UpdateMatchDisplay();
222 
223 void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
224 
225 void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, float Evidence);
226 
227 void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence);
228 
229 INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
230 
232 
233 void free_int_templates(INT_TEMPLATES templates);
234 
235 void ShowMatchDisplay();
236 
237 namespace tesseract {
238 
239 // Clears the given window and draws the featurespace guides for the
240 // appropriate normalization method.
241 void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window);
242 
243 } // namespace tesseract.
244 
245 /*----------------------------------------------------------------------------*/
246 #ifndef GRAPHICS_DISABLED
247 void RenderIntFeature(ScrollView* window, const INT_FEATURE_STRUCT* Feature,
248  ScrollView::Color color);
249 
251 
253 
255 
256 // Creates a window of the appropriate size for displaying elements
257 // in feature space.
258 ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos);
259 #endif // GRAPHICS_DISABLED
260 
261 #endif
void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
Definition: intproto.cpp:232
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1789
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
Definition: intproto.cpp:370
CLUSTERCONFIG Config
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
Definition: intproto.cpp:998
void InitIntMatchWindowIfReqd()
Definition: intproto.cpp:1748
#define NUM_PP_PARAMS
Definition: intproto.h:51
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1628
struct INT_CLASS_STRUCT * INT_CLASS
INT_FEATURE_STRUCT * INT_FEATURE
Definition: intproto.h:148
void ShowMatchDisplay()
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
Definition: intproto.cpp:330
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:50
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:36
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, float Evidence)
Definition: intproto.cpp:599
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:78
uint8_t NumProtoSets
Definition: intproto.h:107
void InitProtoDisplayWindowIfReqd()
Definition: intproto.cpp:1769
IntmatcherDebugAction
Definition: intproto.h:152
uint8_t * ProtoLengths
Definition: intproto.h:110
void UpdateMatchDisplay()
Definition: intproto.cpp:451
int AddIntProto(INT_CLASS Class)
Definition: intproto.cpp:283
uint8_t NumConfigs
Definition: intproto.h:108
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
#define WERDS_PER_PP_VECTOR
Definition: intproto.h:63
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence)
Definition: intproto.cpp:618
struct INT_PROTO_STRUCT * INT_PROTO
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:435
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs)
Definition: intproto.cpp:636
#define MAX_NUM_INT_FEATURES
Definition: intproto.h:129
void free_int_templates(INT_TEMPLATES templates)
Definition: intproto.cpp:708
void InitFeatureDisplayWindowIfReqd()
Definition: intproto.cpp:1780
struct PROTO_SET_STRUCT * PROTO_SET
int AddIntConfig(INT_CLASS Class)
Definition: intproto.cpp:262
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:49
#define NUM_CP_BUCKETS
Definition: intproto.h:53
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:150
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
void print() const
Definition: intproto.h:145
int16_t PROTO_ID
Definition: matchdefs.h:42
INT_TEMPLATES NewIntTemplates()
Definition: intproto.cpp:692
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:421
#define WERDS_PER_CP_VECTOR
Definition: intproto.h:62
Definition: points.h:189
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
Definition: intproto.cpp:469
uint16_t NumProtos
Definition: intproto.h:106
#define NUM_PP_BUCKETS
Definition: intproto.h:52
uint8_t Angle
Definition: intproto.h:85
uint16_t Bucket16For(float param, float offset, int num_buckets)
Definition: intproto.cpp:425
#define MAX_NUM_CLASSES
Definition: matchdefs.h:32
#define MAX_NUM_CLASS_PRUNERS
Definition: intproto.h:60
NORM_METHOD
Definition: mfoutline.h:54
uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
Definition: intproto.h:93
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:68
uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]
Definition: intproto.h:103