tesseract  4.0.0-1-g2a2b
protos.h File Reference
#include "bitvec.h"
#include "params.h"
#include "unichar.h"
#include "unicity_table.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)   ((TrainingData[Char].NumProtos) ? (&TrainingData[Char]) : NO_CLASS)
 
#define ProtoIn(Class, Pid)   (&(Class)->Prototypes[Pid])
 
#define PrintProto(Proto)
 
#define PrintProtoLine(Proto)   (cprintf("A=%4.2f, B=%4.2f, C=%4.2f", Proto->A, Proto->B, Proto->C))
 

Typedefs

using CONFIGS = BIT_VECTOR *
 
using PROTO = PROTO_STRUCT *
 
using CLASS_TYPE = CLASS_STRUCT *
 
using CLASSES = CLASS_STRUCT *
 

Functions

int AddConfigToClass (CLASS_TYPE Class)
 
int AddProtoToClass (CLASS_TYPE Class)
 
float ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
 
float 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 95 of file protos.h.

◆ ClassOfChar

#define ClassOfChar (   Char)    ((TrainingData[Char].NumProtos) ? (&TrainingData[Char]) : NO_CLASS)

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 77 of file protos.h.

◆ NUMBER_OF_CLASSES

#define NUMBER_OF_CLASSES   MAX_NUM_CLASSES

Definition at line 75 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))
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

PrintProto

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

Definition at line 130 of file protos.h.

◆ PrintProtoLine

#define PrintProtoLine (   Proto)    (cprintf("A=%4.2f, B=%4.2f, C=%4.2f", Proto->A, Proto->B, Proto->C))

PrintProtoLine

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

Definition at line 141 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 121 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 103 of file protos.h.

◆ Y_OFFSET

#define Y_OFFSET   -40.0

Definition at line 76 of file protos.h.

Typedef Documentation

◆ CLASS_TYPE

Definition at line 69 of file protos.h.

◆ CLASSES

Definition at line 70 of file protos.h.

◆ CONFIGS

using CONFIGS = BIT_VECTOR*

Definition at line 40 of file protos.h.

◆ PROTO

using PROTO = PROTO_STRUCT*

Definition at line 51 of file protos.h.

Function Documentation

◆ AddConfigToClass()

int AddConfigToClass ( CLASS_TYPE  Class)

Definition at line 60 of file protos.cpp.

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

◆ AddProtoToClass()

int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 96 of file protos.cpp.

96  {
97  int i;
98  int Bit;
99  int NewNumProtos;
100  int NewProto;
102 
103  if (Class->NumProtos >= Class->MaxNumProtos) {
104  /* add protos in PROTO_INCREMENT chunks at a time */
105  NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
107 
108  Class->Prototypes = (PROTO) Erealloc (Class->Prototypes,
109  sizeof (PROTO_STRUCT) *
110  NewNumProtos);
111 
112  Class->MaxNumProtos = NewNumProtos;
113 
114  for (i = 0; i < Class->NumConfigs; i++) {
115  Config = Class->Configurations[i];
116  Class->Configurations[i] = ExpandBitVector (Config, NewNumProtos);
117 
118  for (Bit = Class->NumProtos; Bit < NewNumProtos; Bit++)
119  reset_bit(Config, Bit);
120  }
121  }
122  NewProto = Class->NumProtos++;
123  if (Class->NumProtos > MAX_NUM_PROTOS) {
124  tprintf("Ouch! number of protos = %d, vs max of %d!",
125  Class->NumProtos, MAX_NUM_PROTOS);
126  }
127  return (NewProto);
128 }
int16_t NumProtos
Definition: protos.h:61
CLUSTERCONFIG Config
PROTO_STRUCT * PROTO
Definition: protos.h:51
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
PROTO Prototypes
Definition: protos.h:63
int16_t MaxNumProtos
Definition: protos.h:62
int16_t NumConfigs
Definition: protos.h:64
#define MAX_NUM_PROTOS
Definition: intproto.h:48
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits)
Definition: bitvec.cpp:44
#define reset_bit(array, bit)
Definition: bitvec.h:59
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
CONFIGS Configurations
Definition: protos.h:66
#define PROTO_INCREMENT
Definition: protos.cpp:39

◆ ClassConfigLength()

float ClassConfigLength ( CLASS_TYPE  Class,
BIT_VECTOR  Config 
)

Definition at line 139 of file protos.cpp.

139  {
140  int16_t Pid;
141  float TotalLength = 0;
142 
143  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
144  if (test_bit (Config, Pid)) {
145 
146  TotalLength += (ProtoIn (Class, Pid))->Length;
147  }
148  }
149  return (TotalLength);
150 }
int16_t NumProtos
Definition: protos.h:61
CLUSTERCONFIG Config
#define ProtoIn(Class, Pid)
Definition: protos.h:121
#define test_bit(array, bit)
Definition: bitvec.h:61

◆ ClassProtoLength()

float ClassProtoLength ( CLASS_TYPE  Class)

Definition at line 160 of file protos.cpp.

160  {
161  int16_t Pid;
162  float TotalLength = 0;
163 
164  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
165  TotalLength += (ProtoIn (Class, Pid))->Length;
166  }
167  return (TotalLength);
168 }
int16_t NumProtos
Definition: protos.h:61
#define ProtoIn(Class, Pid)
Definition: protos.h:121

◆ CopyProto()

void CopyProto ( PROTO  Src,
PROTO  Dest 
)

Definition at line 179 of file protos.cpp.

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

◆ FillABC()

void FillABC ( PROTO  Proto)

Definition at line 195 of file protos.cpp.

195  {
196  float Slope, Intercept, Normalizer;
197 
198  Slope = tan(Proto->Angle * 2.0 * M_PI);
199  Intercept = Proto->Y - Slope * Proto->X;
200  Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
201  Proto->A = Slope * Normalizer;
202  Proto->B = -Normalizer;
203  Proto->C = Intercept * Normalizer;
204 }
float X
Definition: protos.h:46
float B
Definition: protos.h:44
float Y
Definition: protos.h:47
float C
Definition: protos.h:45
float Angle
Definition: protos.h:48
float A
Definition: protos.h:43

◆ FreeClass()

void FreeClass ( CLASS_TYPE  Class)

Definition at line 212 of file protos.cpp.

212  {
213  if (Class) {
214  FreeClassFields(Class);
215  delete Class;
216  }
217 }
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:225

◆ FreeClassFields()

void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 225 of file protos.cpp.

225  {
226  int i;
227 
228  if (Class) {
229  if (Class->MaxNumProtos > 0) free(Class->Prototypes);
230  if (Class->MaxNumConfigs > 0) {
231  for (i = 0; i < Class->NumConfigs; i++)
232  FreeBitVector (Class->Configurations[i]);
233  free(Class->Configurations);
234  }
235  }
236 }
PROTO Prototypes
Definition: protos.h:63
int16_t MaxNumProtos
Definition: protos.h:62
void FreeBitVector(BIT_VECTOR BitVector)
Definition: bitvec.cpp:51
int16_t NumConfigs
Definition: protos.h:64
int16_t MaxNumConfigs
Definition: protos.h:65
CONFIGS Configurations
Definition: protos.h:66

◆ InitPrototypes()

void InitPrototypes ( )

◆ NewClass()

CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 244 of file protos.cpp.

244  {
245  CLASS_TYPE Class;
246 
247  Class = new CLASS_STRUCT;
248 
249  if (NumProtos > 0)
250  Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT));
251 
252  if (NumConfigs > 0)
253  Class->Configurations = (CONFIGS) Emalloc (NumConfigs *
254  sizeof (BIT_VECTOR));
255  Class->MaxNumProtos = NumProtos;
256  Class->MaxNumConfigs = NumConfigs;
257  Class->NumProtos = 0;
258  Class->NumConfigs = 0;
259  return (Class);
260 
261 }
int16_t NumProtos
Definition: protos.h:61
PROTO_STRUCT * PROTO
Definition: protos.h:51
BIT_VECTOR * CONFIGS
Definition: protos.h:40
void * Emalloc(int Size)
Definition: emalloc.cpp:31
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
PROTO Prototypes
Definition: protos.h:63
int16_t MaxNumProtos
Definition: protos.h:62
int16_t NumConfigs
Definition: protos.h:64
int16_t MaxNumConfigs
Definition: protos.h:65
CONFIGS Configurations
Definition: protos.h:66

◆ PrintProtos()

void PrintProtos ( CLASS_TYPE  Class)

Definition at line 269 of file protos.cpp.

269  {
270  int16_t Pid;
271 
272  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
273  cprintf ("Proto %d:\t", Pid);
274  PrintProto (ProtoIn (Class, Pid));
275  cprintf ("\t");
276  PrintProtoLine (ProtoIn (Class, Pid));
277  tprintf("\n");
278  }
279 }
int16_t NumProtos
Definition: protos.h:61
void cprintf(const char *format,...)
Definition: callcpp.cpp:33
#define ProtoIn(Class, Pid)
Definition: protos.h:121
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
#define PrintProtoLine(Proto)
Definition: protos.h:141
#define PrintProto(Proto)
Definition: protos.h:130

Variable Documentation

◆ classify_training_file

char* classify_training_file = "MicroFeatures"

"Training file"

Definition at line 47 of file protos.cpp.

◆ TrainingData

CLASS_STRUCT TrainingData[]

Definition at line 45 of file protos.cpp.