tesseract  4.00.00dev
protos.cpp File Reference
#include "protos.h"
#include "const.h"
#include "emalloc.h"
#include "callcpp.h"
#include "tprintf.h"
#include "scanutils.h"
#include "globals.h"
#include "classify.h"
#include "params.h"
#include <stdio.h>
#include <math.h>

Go to the source code of this file.

Macros

#define PROTO_INCREMENT   32
 
#define CONFIG_INCREMENT   16
 

Functions

AddConfigToClass

Add a new config to this class. Malloc new space and copy the old configs if necessary. Return the config id for the new config.

Parameters
ClassThe class to add to
int AddConfigToClass (CLASS_TYPE Class)
 
AddProtoToClass

Add a new proto to this class. Malloc new space and copy the old protos if necessary. Return the proto id for the new proto.

Parameters
ClassThe class to add to
int AddProtoToClass (CLASS_TYPE Class)
 
ClassConfigLength

Return the length of all the protos in this class.

Parameters
ClassThe class to add to
ConfigFIXME
FLOAT32 ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
 
ClassProtoLength

Return the length of all the protos in this class.

Parameters
ClassThe class to use
FLOAT32 ClassProtoLength (CLASS_TYPE Class)
 
CopyProto

Copy the first proto into the second.

Parameters
SrcSource
DestDestination
void CopyProto (PROTO Src, PROTO Dest)
 
void FillABC (PROTO Proto)
 
void FreeClass (CLASS_TYPE Class)
 
void FreeClassFields (CLASS_TYPE Class)
 
CLASS_TYPE NewClass (int NumProtos, int NumConfigs)
 
void PrintProtos (CLASS_TYPE Class)
 

Variables

CLASS_STRUCT TrainingData [NUMBER_OF_CLASSES]
 
char * classify_training_file = "MicroFeatures"
 

Macro Definition Documentation

◆ CONFIG_INCREMENT

#define CONFIG_INCREMENT   16

Definition at line 42 of file protos.cpp.

◆ PROTO_INCREMENT

#define PROTO_INCREMENT   32

Definition at line 41 of file protos.cpp.

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

◆ 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

Definition at line 47 of file protos.cpp.