tesseract  4.1.0
protos.cpp File Reference
#include "protos.h"
#include <cmath>
#include <cstdio>
#include "emalloc.h"
#include "callcpp.h"
#include "tprintf.h"
#include "classify.h"
#include "params.h"
#include "intproto.h"

Go to the source code of this file.

Macros

#define _USE_MATH_DEFINES
 
#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)
 
void FillABC (PROTO Proto)
 
void FreeClass (CLASS_TYPE Class)
 
void FreeClassFields (CLASS_TYPE Class)
 
CLASS_TYPE NewClass (int NumProtos, int NumConfigs)
 

Macro Definition Documentation

#define _USE_MATH_DEFINES

Definition at line 22 of file protos.cpp.

#define CONFIG_INCREMENT   16

Definition at line 34 of file protos.cpp.

#define PROTO_INCREMENT   32

Definition at line 33 of file protos.cpp.

Function Documentation

int AddConfigToClass ( CLASS_TYPE  Class)

Definition at line 47 of file protos.cpp.

47  {
48  int NewNumConfigs;
49  int NewConfig;
50  int MaxNumProtos;
52 
53  MaxNumProtos = Class->MaxNumProtos;
54 
55  if (Class->NumConfigs >= Class->MaxNumConfigs) {
56  /* add configs in CONFIG_INCREMENT chunks at a time */
57  NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) /
59 
60  Class->Configurations =
61  static_cast<CONFIGS>(Erealloc (Class->Configurations,
62  sizeof (BIT_VECTOR) * NewNumConfigs));
63 
64  Class->MaxNumConfigs = NewNumConfigs;
65  }
66  NewConfig = Class->NumConfigs++;
67  Config = NewBitVector (MaxNumProtos);
68  Class->Configurations[NewConfig] = Config;
69  zero_all_bits (Config, WordsInVectorOfSize (MaxNumProtos));
70 
71  return (NewConfig);
72 }
#define WordsInVectorOfSize(NumBits)
Definition: bitvec.h:63
#define zero_all_bits(array, length)
Definition: bitvec.h:33
int16_t MaxNumProtos
Definition: protos.h:56
BIT_VECTOR NewBitVector(int NumBits)
Definition: bitvec.cpp:81
int16_t MaxNumConfigs
Definition: protos.h:59
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
CONFIGS Configurations
Definition: protos.h:60
#define CONFIG_INCREMENT
Definition: protos.cpp:34
BIT_VECTOR * CONFIGS
Definition: protos.h:34
int16_t NumConfigs
Definition: protos.h:58
CLUSTERCONFIG Config
int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 83 of file protos.cpp.

83  {
84  int i;
85  int Bit;
86  int NewNumProtos;
87  int NewProto;
89 
90  if (Class->NumProtos >= Class->MaxNumProtos) {
91  /* add protos in PROTO_INCREMENT chunks at a time */
92  NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
94 
95  Class->Prototypes = static_cast<PROTO>(Erealloc (Class->Prototypes,
96  sizeof (PROTO_STRUCT) *
97  NewNumProtos));
98 
99  Class->MaxNumProtos = NewNumProtos;
100 
101  for (i = 0; i < Class->NumConfigs; i++) {
102  Config = Class->Configurations[i];
103  Class->Configurations[i] = ExpandBitVector (Config, NewNumProtos);
104 
105  for (Bit = Class->NumProtos; Bit < NewNumProtos; Bit++)
106  reset_bit(Config, Bit);
107  }
108  }
109  NewProto = Class->NumProtos++;
110  if (Class->NumProtos > MAX_NUM_PROTOS) {
111  tprintf("Ouch! number of protos = %d, vs max of %d!",
112  Class->NumProtos, MAX_NUM_PROTOS);
113  }
114  return (NewProto);
115 }
#define reset_bit(array, bit)
Definition: bitvec.h:59
#define PROTO_INCREMENT
Definition: protos.cpp:33
int16_t MaxNumProtos
Definition: protos.h:56
#define MAX_NUM_PROTOS
Definition: intproto.h:48
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
CONFIGS Configurations
Definition: protos.h:60
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:36
int16_t NumProtos
Definition: protos.h:55
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits)
Definition: bitvec.cpp:43
int16_t NumConfigs
Definition: protos.h:58
PROTO Prototypes
Definition: protos.h:57
CLUSTERCONFIG Config
void FillABC ( PROTO  Proto)

Definition at line 123 of file protos.cpp.

123  {
124  float Slope, Intercept, Normalizer;
125 
126  Slope = tan(Proto->Angle * 2.0 * M_PI);
127  Intercept = Proto->Y - Slope * Proto->X;
128  Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
129  Proto->A = Slope * Normalizer;
130  Proto->B = -Normalizer;
131  Proto->C = Intercept * Normalizer;
132 }
float A
Definition: protos.h:37
float X
Definition: protos.h:40
float Angle
Definition: protos.h:42
float Y
Definition: protos.h:41
float C
Definition: protos.h:39
float B
Definition: protos.h:38
void FreeClass ( CLASS_TYPE  Class)

Definition at line 140 of file protos.cpp.

140  {
141  if (Class) {
142  FreeClassFields(Class);
143  delete Class;
144  }
145 }
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:153
void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 153 of file protos.cpp.

153  {
154  int i;
155 
156  if (Class) {
157  if (Class->MaxNumProtos > 0) free(Class->Prototypes);
158  if (Class->MaxNumConfigs > 0) {
159  for (i = 0; i < Class->NumConfigs; i++)
160  FreeBitVector (Class->Configurations[i]);
161  free(Class->Configurations);
162  }
163  }
164 }
void FreeBitVector(BIT_VECTOR BitVector)
Definition: bitvec.cpp:50
int16_t MaxNumProtos
Definition: protos.h:56
int16_t MaxNumConfigs
Definition: protos.h:59
CONFIGS Configurations
Definition: protos.h:60
int16_t NumConfigs
Definition: protos.h:58
PROTO Prototypes
Definition: protos.h:57
CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 172 of file protos.cpp.

172  {
173  CLASS_TYPE Class;
174 
175  Class = new CLASS_STRUCT;
176 
177  if (NumProtos > 0)
178  Class->Prototypes = static_cast<PROTO>(Emalloc (NumProtos * sizeof (PROTO_STRUCT)));
179 
180  if (NumConfigs > 0)
181  Class->Configurations = static_cast<CONFIGS>(Emalloc (NumConfigs *
182  sizeof (BIT_VECTOR)));
183  Class->MaxNumProtos = NumProtos;
184  Class->MaxNumConfigs = NumConfigs;
185  Class->NumProtos = 0;
186  Class->NumConfigs = 0;
187  return (Class);
188 
189 }
int16_t MaxNumProtos
Definition: protos.h:56
int16_t MaxNumConfigs
Definition: protos.h:59
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
CONFIGS Configurations
Definition: protos.h:60
int16_t NumProtos
Definition: protos.h:55
void * Emalloc(int Size)
Definition: emalloc.cpp:31
BIT_VECTOR * CONFIGS
Definition: protos.h:34
int16_t NumConfigs
Definition: protos.h:58
PROTO Prototypes
Definition: protos.h:57