tesseract  4.0.0-beta.1-59-g2cc4
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 }
CONFIGS Configurations
Definition: protos.h:64
BIT_VECTOR * CONFIGS
Definition: protos.h:40
BIT_VECTOR NewBitVector(int NumBits)
Definition: bitvec.cpp:89
int16_t MaxNumProtos
Definition: protos.h:60
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
int16_t NumConfigs
Definition: protos.h:62
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
#define WordsInVectorOfSize(NumBits)
Definition: bitvec.h:63
int16_t MaxNumConfigs
Definition: protos.h:63
#define zero_all_bits(array, length)
Definition: bitvec.h:33
CLUSTERCONFIG Config
#define CONFIG_INCREMENT
Definition: protos.cpp:42

◆ 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 }
PROTO_STRUCT * PROTO
Definition: protos.h:52
#define reset_bit(array, bit)
Definition: bitvec.h:59
CONFIGS Configurations
Definition: protos.h:64
int16_t MaxNumProtos
Definition: protos.h:60
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits)
Definition: bitvec.cpp:47
#define tprintf(...)
Definition: tprintf.h:31
int16_t NumConfigs
Definition: protos.h:62
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
PROTO Prototypes
Definition: protos.h:61
#define PROTO_INCREMENT
Definition: protos.cpp:41
#define MAX_NUM_PROTOS
Definition: intproto.h:47
CLUSTERCONFIG Config
int16_t NumProtos
Definition: protos.h:59

◆ ClassConfigLength()

FLOAT32 ClassConfigLength ( CLASS_TYPE  Class,
BIT_VECTOR  Config 
)

Definition at line 141 of file protos.cpp.

141  {
142  int16_t 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 }
#define test_bit(array, bit)
Definition: bitvec.h:61
float FLOAT32
Definition: host.h:34
#define ProtoIn(Class, Pid)
Definition: protos.h:123
CLUSTERCONFIG Config
int16_t NumProtos
Definition: protos.h:59

◆ ClassProtoLength()

FLOAT32 ClassProtoLength ( CLASS_TYPE  Class)

Definition at line 162 of file protos.cpp.

162  {
163  int16_t 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 }
float FLOAT32
Definition: host.h:34
#define ProtoIn(Class, Pid)
Definition: protos.h:123
int16_t NumProtos
Definition: protos.h:59

◆ 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 Length
Definition: protos.h:50
FLOAT32 C
Definition: protos.h:46
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 A
Definition: protos.h:44
FLOAT32 X
Definition: protos.h:47
FLOAT32 Y
Definition: protos.h:48
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 }
#define PI
Definition: const.h:19
float FLOAT32
Definition: host.h:34
FLOAT32 C
Definition: protos.h:46
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 A
Definition: protos.h:44
FLOAT32 X
Definition: protos.h:47
FLOAT32 Y
Definition: protos.h:48
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) free(Class->Prototypes);
232  if (Class->MaxNumConfigs > 0) {
233  for (i = 0; i < Class->NumConfigs; i++)
234  FreeBitVector (Class->Configurations[i]);
235  free(Class->Configurations);
236  }
237  }
238 }
CONFIGS Configurations
Definition: protos.h:64
int16_t MaxNumProtos
Definition: protos.h:60
int16_t NumConfigs
Definition: protos.h:62
PROTO Prototypes
Definition: protos.h:61
int16_t MaxNumConfigs
Definition: protos.h:63
void FreeBitVector(BIT_VECTOR BitVector)
Definition: bitvec.cpp:54

◆ NewClass()

CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 246 of file protos.cpp.

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

◆ PrintProtos()

void PrintProtos ( CLASS_TYPE  Class)

Definition at line 271 of file protos.cpp.

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

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.