tesseract  4.00.00dev
protos.h File Reference
#include "bitvec.h"
#include "cutil.h"
#include "unichar.h"
#include "unicity_table.h"
#include "params.h"

Go to the source code of this file.

Classes

struct  PROTO_STRUCT
 
struct  CLASS_STRUCT
 

Macros

#define NUMBER_OF_CLASSES   MAX_NUM_CLASSES
 
#define Y_OFFSET   -40.0
 
#define FEATURE_SCALE   100.0
 
#define AddProtoToConfig(Pid, Config)   (SET_BIT (Config, Pid))
 
#define RemoveProtoFromConfig(Pid, Config)   (reset_bit (Config, Pid))
 
#define ClassOfChar(Char)
 
#define ProtoIn(Class, Pid)   (& (Class)->Prototypes [Pid])
 
#define PrintProto(Proto)
 
#define PrintProtoLine(Proto)
 

Typedefs

typedef BIT_VECTORCONFIGS
 
typedef PROTO_STRUCTPROTO
 
typedef CLASS_STRUCTCLASS_TYPE
 
typedef CLASS_STRUCTCLASSES
 

Functions

int AddConfigToClass (CLASS_TYPE Class)
 
int AddProtoToClass (CLASS_TYPE Class)
 
FLOAT32 ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
 
FLOAT32 ClassProtoLength (CLASS_TYPE Class)
 
void CopyProto (PROTO Src, PROTO Dest)
 
void FillABC (PROTO Proto)
 
void FreeClass (CLASS_TYPE Class)
 
void FreeClassFields (CLASS_TYPE Class)
 
void InitPrototypes ()
 
CLASS_TYPE NewClass (int NumProtos, int NumConfigs)
 
void PrintProtos (CLASS_TYPE Class)
 

Variables

CLASS_STRUCT TrainingData []
 
char * classify_training_file = "MicroFeatures"
 

Macro Definition Documentation

◆ AddProtoToConfig

#define AddProtoToConfig (   Pid,
  Config 
)    (SET_BIT (Config, Pid))

AddProtoToConfig

Set a single proto bit in the specified configuration.

Definition at line 93 of file protos.h.

◆ ClassOfChar

#define ClassOfChar (   Char)
Value:
((TrainingData [Char].NumProtos) ? \
(& TrainingData [Char]) : \
NO_CLASS)
inT16 NumProtos
Definition: protos.h:59
CLASS_STRUCT TrainingData[]
Definition: protos.cpp:47

ClassOfChar

Return the class of a particular ASCII character value.

Definition at line 111 of file protos.h.

◆ FEATURE_SCALE

#define FEATURE_SCALE   100.0

Definition at line 75 of file protos.h.

◆ NUMBER_OF_CLASSES

#define NUMBER_OF_CLASSES   MAX_NUM_CLASSES

Definition at line 73 of file protos.h.

◆ PrintProto

#define PrintProto (   Proto)
Value:
(tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", \
Proto->X, \
Proto->Y, \
Proto->Length, \
Proto->Angle)) \
#define tprintf(...)
Definition: tprintf.h:31

PrintProto

Print out the contents of a prototype. The 'Proto' argument is of type 'PROTO'.

Definition at line 133 of file protos.h.

◆ PrintProtoLine

#define PrintProtoLine (   Proto)
Value:
(cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \
Proto->A, \
Proto->B, \
Proto->C)) \
void cprintf(const char *format,...)
Definition: callcpp.cpp:40

PrintProtoLine

Print out the contents of a prototype. The 'Proto' argument is of type 'PROTO'.

Definition at line 148 of file protos.h.

◆ ProtoIn

#define ProtoIn (   Class,
  Pid 
)    (& (Class)->Prototypes [Pid])

ProtoIn

Choose the selected prototype in this class record. Return the pointer to it (type PROTO).

Definition at line 123 of file protos.h.

◆ RemoveProtoFromConfig

#define RemoveProtoFromConfig (   Pid,
  Config 
)    (reset_bit (Config, Pid))

RemoveProtoFromConfig

Clear a single proto bit in the specified configuration.

Definition at line 102 of file protos.h.

◆ Y_OFFSET

#define Y_OFFSET   -40.0

Definition at line 74 of file protos.h.

Typedef Documentation

◆ CLASS_TYPE

Definition at line 67 of file protos.h.

◆ CLASSES

Definition at line 68 of file protos.h.

◆ CONFIGS

typedef BIT_VECTOR* CONFIGS

Definition at line 40 of file protos.h.

◆ PROTO

typedef PROTO_STRUCT* PROTO

Definition at line 52 of file protos.h.

Function Documentation

◆ AddConfigToClass()

int AddConfigToClass ( CLASS_TYPE  Class)

Definition at line 62 of file protos.cpp.

62  {
63  int NewNumConfigs;
64  int NewConfig;
65  int MaxNumProtos;
67 
68  MaxNumProtos = Class->MaxNumProtos;
69 
70  if (Class->NumConfigs >= Class->MaxNumConfigs) {
71  /* add configs in CONFIG_INCREMENT chunks at a time */
72  NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) /
74 
75  Class->Configurations =
77  sizeof (BIT_VECTOR) * NewNumConfigs);
78 
79  Class->MaxNumConfigs = NewNumConfigs;
80  }
81  NewConfig = Class->NumConfigs++;
82  Config = NewBitVector (MaxNumProtos);
83  Class->Configurations[NewConfig] = Config;
84  zero_all_bits (Config, WordsInVectorOfSize (MaxNumProtos));
85 
86  return (NewConfig);
87 }
#define WordsInVectorOfSize(NumBits)
Definition: bitvec.h:63
BIT_VECTOR * CONFIGS
Definition: protos.h:40
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 NumConfigs
Definition: protos.h:62
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
CLUSTERCONFIG Config
BIT_VECTOR NewBitVector(int NumBits)
Definition: bitvec.cpp:89
CONFIGS Configurations
Definition: protos.h:64
#define CONFIG_INCREMENT
Definition: protos.cpp:42
#define zero_all_bits(array, length)
Definition: bitvec.h:33
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
inT16 MaxNumProtos
Definition: protos.h:60

◆ AddProtoToClass()

int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 98 of file protos.cpp.

98  {
99  int i;
100  int Bit;
101  int NewNumProtos;
102  int NewProto;
104 
105  if (Class->NumProtos >= Class->MaxNumProtos) {
106  /* add protos in PROTO_INCREMENT chunks at a time */
107  NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
109 
110  Class->Prototypes = (PROTO) Erealloc (Class->Prototypes,
111  sizeof (PROTO_STRUCT) *
112  NewNumProtos);
113 
114  Class->MaxNumProtos = NewNumProtos;
115 
116  for (i = 0; i < Class->NumConfigs; i++) {
117  Config = Class->Configurations[i];
118  Class->Configurations[i] = ExpandBitVector (Config, NewNumProtos);
119 
120  for (Bit = Class->NumProtos; Bit < NewNumProtos; Bit++)
121  reset_bit(Config, Bit);
122  }
123  }
124  NewProto = Class->NumProtos++;
125  if (Class->NumProtos > MAX_NUM_PROTOS) {
126  tprintf("Ouch! number of protos = %d, vs max of %d!",
127  Class->NumProtos, MAX_NUM_PROTOS);
128  }
129  return (NewProto);
130 }
#define MAX_NUM_PROTOS
Definition: intproto.h:47
inT16 NumConfigs
Definition: protos.h:62
#define tprintf(...)
Definition: tprintf.h:31
inT16 NumProtos
Definition: protos.h:59
#define PROTO_INCREMENT
Definition: protos.cpp:41
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
CLUSTERCONFIG Config
CONFIGS Configurations
Definition: protos.h:64
PROTO_STRUCT * PROTO
Definition: protos.h:52
PROTO Prototypes
Definition: protos.h:61
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits)
Definition: bitvec.cpp:47
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
inT16 MaxNumProtos
Definition: protos.h:60
#define reset_bit(array, bit)
Definition: bitvec.h:59

◆ ClassConfigLength()

FLOAT32 ClassConfigLength ( CLASS_TYPE  Class,
BIT_VECTOR  Config 
)

Definition at line 141 of file protos.cpp.

141  {
142  inT16 Pid;
143  FLOAT32 TotalLength = 0;
144 
145  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
146  if (test_bit (Config, Pid)) {
147 
148  TotalLength += (ProtoIn (Class, Pid))->Length;
149  }
150  }
151  return (TotalLength);
152 }
inT16 NumProtos
Definition: protos.h:59
CLUSTERCONFIG Config
int16_t inT16
Definition: host.h:36
float FLOAT32
Definition: host.h:42
#define test_bit(array, bit)
Definition: bitvec.h:61
#define ProtoIn(Class, Pid)
Definition: protos.h:123

◆ ClassProtoLength()

FLOAT32 ClassProtoLength ( CLASS_TYPE  Class)

Definition at line 162 of file protos.cpp.

162  {
163  inT16 Pid;
164  FLOAT32 TotalLength = 0;
165 
166  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
167  TotalLength += (ProtoIn (Class, Pid))->Length;
168  }
169  return (TotalLength);
170 }
inT16 NumProtos
Definition: protos.h:59
int16_t inT16
Definition: host.h:36
float FLOAT32
Definition: host.h:42
#define ProtoIn(Class, Pid)
Definition: protos.h:123

◆ CopyProto()

void CopyProto ( PROTO  Src,
PROTO  Dest 
)

Definition at line 181 of file protos.cpp.

181  {
182  Dest->X = Src->X;
183  Dest->Y = Src->Y;
184  Dest->Length = Src->Length;
185  Dest->Angle = Src->Angle;
186  Dest->A = Src->A;
187  Dest->B = Src->B;
188  Dest->C = Src->C;
189 }
FLOAT32 A
Definition: protos.h:44
FLOAT32 Length
Definition: protos.h:50
FLOAT32 Y
Definition: protos.h:48
FLOAT32 X
Definition: protos.h:47
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 C
Definition: protos.h:46
FLOAT32 B
Definition: protos.h:45

◆ FillABC()

void FillABC ( PROTO  Proto)

Definition at line 197 of file protos.cpp.

197  {
198  FLOAT32 Slope, Intercept, Normalizer;
199 
200  Slope = tan (Proto->Angle * 2.0 * PI);
201  Intercept = Proto->Y - Slope * Proto->X;
202  Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
203  Proto->A = Slope * Normalizer;
204  Proto->B = -Normalizer;
205  Proto->C = Intercept * Normalizer;
206 }
FLOAT32 A
Definition: protos.h:44
#define PI
Definition: const.h:19
FLOAT32 Y
Definition: protos.h:48
FLOAT32 X
Definition: protos.h:47
float FLOAT32
Definition: host.h:42
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 C
Definition: protos.h:46
FLOAT32 B
Definition: protos.h:45

◆ FreeClass()

void FreeClass ( CLASS_TYPE  Class)

Definition at line 214 of file protos.cpp.

214  {
215  if (Class) {
216  FreeClassFields(Class);
217  delete Class;
218  }
219 }
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:227

◆ FreeClassFields()

void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 227 of file protos.cpp.

227  {
228  int i;
229 
230  if (Class) {
231  if (Class->MaxNumProtos > 0)
232  free(Class->Prototypes);
233  if (Class->MaxNumConfigs > 0) {
234  for (i = 0; i < Class->NumConfigs; i++)
235  FreeBitVector (Class->Configurations[i]);
236  free(Class->Configurations);
237  }
238  }
239 }
void FreeBitVector(BIT_VECTOR BitVector)
Definition: bitvec.cpp:54
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 NumConfigs
Definition: protos.h:62
CONFIGS Configurations
Definition: protos.h:64
PROTO Prototypes
Definition: protos.h:61
inT16 MaxNumProtos
Definition: protos.h:60

◆ InitPrototypes()

void InitPrototypes ( )

◆ NewClass()

CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 247 of file protos.cpp.

247  {
248  CLASS_TYPE Class;
249 
250  Class = new CLASS_STRUCT;
251 
252  if (NumProtos > 0)
253  Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT));
254 
255  if (NumConfigs > 0)
256  Class->Configurations = (CONFIGS) Emalloc (NumConfigs *
257  sizeof (BIT_VECTOR));
258  Class->MaxNumProtos = NumProtos;
259  Class->MaxNumConfigs = NumConfigs;
260  Class->NumProtos = 0;
261  Class->NumConfigs = 0;
262  return (Class);
263 
264 }
BIT_VECTOR * CONFIGS
Definition: protos.h:40
void * Emalloc(int Size)
Definition: emalloc.cpp:47
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 NumConfigs
Definition: protos.h:62
inT16 NumProtos
Definition: protos.h:59
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
CONFIGS Configurations
Definition: protos.h:64
PROTO_STRUCT * PROTO
Definition: protos.h:52
PROTO Prototypes
Definition: protos.h:61
inT16 MaxNumProtos
Definition: protos.h:60

◆ PrintProtos()

void PrintProtos ( CLASS_TYPE  Class)

Definition at line 272 of file protos.cpp.

272  {
273  inT16 Pid;
274 
275  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
276  cprintf ("Proto %d:\t", Pid);
277  PrintProto (ProtoIn (Class, Pid));
278  cprintf ("\t");
279  PrintProtoLine (ProtoIn (Class, Pid));
280  new_line();
281  }
282 }
inT16 NumProtos
Definition: protos.h:59
int16_t inT16
Definition: host.h:36
#define PrintProtoLine(Proto)
Definition: protos.h:148
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
#define PrintProto(Proto)
Definition: protos.h:133
#define new_line()
Definition: cutil.h:83
#define ProtoIn(Class, Pid)
Definition: protos.h:123

Variable Documentation

◆ classify_training_file

char* classify_training_file = "MicroFeatures"

"Training file"

Definition at line 49 of file protos.cpp.

◆ TrainingData

CLASS_STRUCT TrainingData[]

Definition at line 47 of file protos.cpp.