tesseract  4.0.0-1-g2a2b
protos.cpp File Reference
#include "protos.h"
#include "emalloc.h"
#include "callcpp.h"
#include "tprintf.h"
#include "globals.h"
#include "classify.h"
#include "params.h"
#include <cstdio>
#include <cmath>

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
float ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
 
ClassProtoLength

Return the length of all the protos in this class.

Parameters
ClassThe class to use
float 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 40 of file protos.cpp.

◆ PROTO_INCREMENT

#define PROTO_INCREMENT   32

Definition at line 39 of file protos.cpp.

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

◆ 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

Definition at line 45 of file protos.cpp.