tesseract  5.0.0-alpha-619-ge9db
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 
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. */
76 struct CLASS_PRUNER_STRUCT {
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 
94 
95 typedef struct {
96  PROTO_PRUNER ProtoPruner;
98 }
99 
101  *PROTO_SET;
102 
103 typedef uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4];
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 {
119  int NumClasses;
120  int NumClassPruners;
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 {
146  tprintf("(%d,%d):%d\n", X, Y, Theta);
147  }
148 };
149 
151 
153 
158  IDA_BOTH
159 };
160 
165 #define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
166 #define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
167 #define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
168 #define ProtoForProtoId(C, P) \
169  (&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)]))
170 #define PPrunerWordIndexFor(I) \
171  (((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD)
172 #define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
173 #define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor(I))
174 
175 #define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
176 #define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
177 #define UnusedClassIdIn(T, c) ((T)->Class[c] == nullptr)
178 #define ClassForClassId(T, c) ((T)->Class[c])
179 #define ClassPrunersFor(T) ((T)->ClassPruner)
180 #define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
181 #define CPrunerFor(T, c) ((T)->ClassPruners[CPrunerIdFor(c)])
182 #define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
183 #define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
184 #define CPrunerMaskFor(L, c) \
185  (((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS)
186 
187 /* DEBUG macros*/
188 #define PRINT_MATCH_SUMMARY 0x001
189 #define DISPLAY_FEATURE_MATCHES 0x002
190 #define DISPLAY_PROTO_MATCHES 0x004
191 #define PRINT_FEATURE_MATCHES 0x008
192 #define PRINT_PROTO_MATCHES 0x010
193 #define CLIP_MATCH_EVIDENCE 0x020
194 
195 #define MatchDebuggingOn(D) (D)
196 #define PrintMatchSummaryOn(D) ((D)&PRINT_MATCH_SUMMARY)
197 #define DisplayFeatureMatchesOn(D) ((D)&DISPLAY_FEATURE_MATCHES)
198 #define DisplayProtoMatchesOn(D) ((D)&DISPLAY_PROTO_MATCHES)
199 #define PrintFeatureMatchesOn(D) ((D)&PRINT_FEATURE_MATCHES)
200 #define PrintProtoMatchesOn(D) ((D)&PRINT_PROTO_MATCHES)
201 #define ClipMatchEvidenceOn(D) ((D)&CLIP_MATCH_EVIDENCE)
202 
206 void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class);
207 
208 int AddIntConfig(INT_CLASS Class);
209 
210 int AddIntProto(INT_CLASS Class);
211 
212 void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId,
213  INT_TEMPLATES Templates);
214 
215 void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class,
216  bool debug);
217 
218 uint8_t Bucket8For(float param, float offset, int num_buckets);
219 uint16_t Bucket16For(float param, float offset, int num_buckets);
220 
221 uint8_t CircBucketFor(float param, float offset, int num_buckets);
222 
223 void UpdateMatchDisplay();
224 
225 void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
226 
227 void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, float Evidence);
228 
229 void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence);
230 
231 INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
232 
234 
235 void free_int_templates(INT_TEMPLATES templates);
236 
237 void ShowMatchDisplay();
238 
239 namespace tesseract {
240 
241 // Clears the given window and draws the featurespace guides for the
242 // appropriate normalization method.
243 void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window);
244 
245 } // namespace tesseract.
246 
247 /*----------------------------------------------------------------------------*/
248 #ifndef GRAPHICS_DISABLED
249 void RenderIntFeature(ScrollView* window, const INT_FEATURE_STRUCT* Feature,
250  ScrollView::Color color);
251 
253 
255 
257 
258 // Creates a window of the appropriate size for displaying elements
259 // in feature space.
260 ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos);
261 #endif // GRAPHICS_DISABLED
262 
263 #endif
INT_TEMPLATES_STRUCT
Definition: intproto.h:117
CONFIG_PRUNER
uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]
Definition: intproto.h:102
ScrollView
Definition: scrollview.h:97
PROTOS_PER_PROTO_SET
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:48
CLASS_ID
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:33
IDA_SHAPE_INDEX
Definition: intproto.h:156
NewIntTemplates
INT_TEMPLATES NewIntTemplates()
Definition: intproto.cpp:681
NUM_PP_PARAMS
#define NUM_PP_PARAMS
Definition: intproto.h:50
INT_CLASS_STRUCT
Definition: intproto.h:104
PROTO_STRUCT
Definition: protos.h:34
mfoutline.h
InitFeatureDisplayWindowIfReqd
void InitFeatureDisplayWindowIfReqd()
Definition: intproto.cpp:1755
INT_FEATURE_STRUCT::Theta
uint8_t Theta
Definition: intproto.h:141
INT_FEATURE_STRUCT::INT_FEATURE_STRUCT
INT_FEATURE_STRUCT()
Definition: intproto.h:132
RenderIntFeature
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1603
PROTO_ID
int16_t PROTO_ID
Definition: matchdefs.h:39
INT_CLASS
struct INT_CLASS_STRUCT * INT_CLASS
INT_PROTO_STRUCT
Definition: intproto.h:80
Config
CLUSTERCONFIG Config
Definition: commontraining.cpp:88
NUM_PP_BUCKETS
#define NUM_PP_BUCKETS
Definition: intproto.h:51
MAX_NUM_PROTO_SETS
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:49
FCOORD
Definition: points.h:187
MAX_NUM_CLASS_PRUNERS
#define MAX_NUM_CLASS_PRUNERS
Definition: intproto.h:59
Bucket8For
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:417
ConvertConfig
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
Definition: intproto.cpp:462
INT_FEATURE_STRUCT::print
void print() const
Definition: intproto.h:144
genericvector.h
AddIntProto
int AddIntProto(INT_CLASS Class)
Definition: intproto.cpp:281
unicharset.h
MAX_NUM_CONFIGS
#define MAX_NUM_CONFIGS
Definition: intproto.h:46
MAX_NUM_CLASSES
#define MAX_NUM_CLASSES
Definition: matchdefs.h:29
Bucket16For
uint16_t Bucket16For(float param, float offset, int num_buckets)
Definition: intproto.cpp:421
DisplayIntProto
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence)
Definition: intproto.cpp:607
INT_PROTO
struct INT_PROTO_STRUCT * INT_PROTO
CircBucketFor
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:431
PROTO_PRUNER
uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
Definition: intproto.h:92
MAX_NUM_INT_FEATURES
#define MAX_NUM_INT_FEATURES
Definition: intproto.h:128
NORM_METHOD
NORM_METHOD
Definition: mfoutline.h:62
PROTO_SET
struct PROTO_SET_STRUCT * PROTO_SET
INT_FEATURE_STRUCT::Y
uint8_t Y
Definition: intproto.h:140
BIT_VECTOR
uint32_t * BIT_VECTOR
Definition: bitvec.h:27
tesseract
Definition: baseapi.h:65
WERDS_PER_CONFIG_VEC
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:67
free_int_templates
void free_int_templates(INT_TEMPLATES templates)
Definition: intproto.cpp:697
AddIntClass
void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
Definition: intproto.cpp:230
CreateFeatureSpaceWindow
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1764
AddProtoToProtoPruner
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
Definition: intproto.cpp:366
NUM_CP_BUCKETS
#define NUM_CP_BUCKETS
Definition: intproto.h:52
AddIntConfig
int AddIntConfig(INT_CLASS Class)
Definition: intproto.cpp:260
IDA_STATIC
Definition: intproto.h:155
INT_FEATURE_ARRAY
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:151
INT_FEATURE_STRUCT::CP_misses
int8_t CP_misses
Definition: intproto.h:142
INT_FEATURE_STRUCT
Definition: intproto.h:131
InitIntMatchWindowIfReqd
void InitIntMatchWindowIfReqd()
Definition: intproto.cpp:1723
protos.h
DisplayIntFeature
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, float Evidence)
Definition: intproto.cpp:589
PROTO_SET_STRUCT
Definition: intproto.h:94
ShowMatchDisplay
void ShowMatchDisplay()
AddProtoToClassPruner
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
Definition: intproto.cpp:327
WERDS_PER_CP_VECTOR
#define WERDS_PER_CP_VECTOR
Definition: intproto.h:61
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
CLASS_PRUNER_STRUCT
Definition: intproto.h:75
CLASS_PRUNER_STRUCT::p
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:77
IDA_BOTH
Definition: intproto.h:157
WERDS_PER_PP_VECTOR
#define WERDS_PER_PP_VECTOR
Definition: intproto.h:62
ScrollView::Color
Color
Definition: scrollview.h:100
INT_FEATURE_STRUCT::X
uint8_t X
Definition: intproto.h:139
InitProtoDisplayWindowIfReqd
void InitProtoDisplayWindowIfReqd()
Definition: intproto.cpp:1744
scrollview.h
IDA_ADAPTIVE
Definition: intproto.h:154
tesseract::ClearFeatureSpaceWindow
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
Definition: intproto.cpp:987
matchdefs.h
NewIntClass
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs)
Definition: intproto.cpp:625
IntmatcherDebugAction
IntmatcherDebugAction
Definition: intproto.h:153
INT_TEMPLATES
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES
UpdateMatchDisplay
void UpdateMatchDisplay()
Definition: intproto.cpp:446