tesseract  4.1.1
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 AddProtoToConfig(Pid, Config)   (SET_BIT(Config, Pid))
 
#define ProtoIn(Class, Pid)   (&(Class)->Prototypes[Pid])
 

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

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

Typedef Documentation

◆ CLASS_TYPE

Definition at line 63 of file protos.h.

◆ CLASSES

Definition at line 64 of file protos.h.

◆ CONFIGS

using CONFIGS = BIT_VECTOR*

Definition at line 34 of file protos.h.

◆ PROTO

using PROTO = PROTO_STRUCT*

Definition at line 45 of file protos.h.

Function Documentation

◆ AddConfigToClass()

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  ASSERT_HOST(MaxNumProtos <= MAX_NUM_PROTOS);
55 
56  if (Class->NumConfigs >= Class->MaxNumConfigs) {
57  /* add configs in CONFIG_INCREMENT chunks at a time */
58  NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) /
60 
61  Class->Configurations =
62  static_cast<CONFIGS>(Erealloc (Class->Configurations,
63  sizeof (BIT_VECTOR) * NewNumConfigs));
64 
65  Class->MaxNumConfigs = NewNumConfigs;
66  }
67  NewConfig = Class->NumConfigs++;
68  Config = NewBitVector(MAX_NUM_PROTOS);
69  Class->Configurations[NewConfig] = Config;
70  zero_all_bits (Config, WordsInVectorOfSize(MAX_NUM_PROTOS));
71 
72  return (NewConfig);
73 }

◆ AddProtoToClass()

int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 84 of file protos.cpp.

84  {
85  if (Class->NumProtos >= Class->MaxNumProtos) {
86  /* add protos in PROTO_INCREMENT chunks at a time */
87  int NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
89 
90  Class->Prototypes = static_cast<PROTO>(Erealloc (Class->Prototypes,
91  sizeof (PROTO_STRUCT) *
92  NewNumProtos));
93 
94  Class->MaxNumProtos = NewNumProtos;
95  ASSERT_HOST(NewNumProtos <= MAX_NUM_PROTOS);
96  }
97  int NewProto = Class->NumProtos++;
99  return (NewProto);
100 }

◆ FillABC()

void FillABC ( PROTO  Proto)

Definition at line 108 of file protos.cpp.

108  {
109  float Slope, Intercept, Normalizer;
110 
111  Slope = tan(Proto->Angle * 2.0 * M_PI);
112  Intercept = Proto->Y - Slope * Proto->X;
113  Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
114  Proto->A = Slope * Normalizer;
115  Proto->B = -Normalizer;
116  Proto->C = Intercept * Normalizer;
117 }

◆ FreeClass()

void FreeClass ( CLASS_TYPE  Class)

Definition at line 125 of file protos.cpp.

125  {
126  if (Class) {
127  FreeClassFields(Class);
128  delete Class;
129  }
130 }

◆ FreeClassFields()

void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 138 of file protos.cpp.

138  {
139  int i;
140 
141  if (Class) {
142  if (Class->MaxNumProtos > 0) free(Class->Prototypes);
143  if (Class->MaxNumConfigs > 0) {
144  for (i = 0; i < Class->NumConfigs; i++)
145  FreeBitVector (Class->Configurations[i]);
146  free(Class->Configurations);
147  }
148  }
149 }

◆ InitPrototypes()

void InitPrototypes ( )

◆ NewClass()

CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 157 of file protos.cpp.

157  {
158  CLASS_TYPE Class;
159 
160  Class = new CLASS_STRUCT;
161 
162  if (NumProtos > 0)
163  Class->Prototypes = static_cast<PROTO>(Emalloc (NumProtos * sizeof (PROTO_STRUCT)));
164 
165  if (NumConfigs > 0)
166  Class->Configurations = static_cast<CONFIGS>(Emalloc (NumConfigs *
167  sizeof (BIT_VECTOR)));
168  Class->MaxNumProtos = NumProtos;
169  Class->MaxNumConfigs = NumConfigs;
170  Class->NumProtos = 0;
171  Class->NumConfigs = 0;
172  return (Class);
173 
174 }
PROTO_STRUCT::C
float C
Definition: protos.h:39
BIT_VECTOR
uint32_t * BIT_VECTOR
Definition: bitvec.h:28
CLASS_STRUCT::Prototypes
PROTO Prototypes
Definition: protos.h:57
MAX_NUM_PROTOS
#define MAX_NUM_PROTOS
Definition: intproto.h:48
PROTO_STRUCT::Y
float Y
Definition: protos.h:41
CLASS_STRUCT::MaxNumProtos
int16_t MaxNumProtos
Definition: protos.h:56
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:88
CONFIG_INCREMENT
#define CONFIG_INCREMENT
Definition: protos.cpp:34
CLASS_STRUCT::Configurations
CONFIGS Configurations
Definition: protos.h:60
PROTO_STRUCT::B
float B
Definition: protos.h:38
Erealloc
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
PROTO_STRUCT::X
float X
Definition: protos.h:40
CLASS_STRUCT::MaxNumConfigs
int16_t MaxNumConfigs
Definition: protos.h:59
CLASS_STRUCT
Definition: protos.h:47
CONFIGS
BIT_VECTOR * CONFIGS
Definition: protos.h:34
PROTO_STRUCT::A
float A
Definition: protos.h:37
Emalloc
void * Emalloc(int Size)
Definition: emalloc.cpp:31
CLASS_STRUCT::NumConfigs
int16_t NumConfigs
Definition: protos.h:58
PROTO_INCREMENT
#define PROTO_INCREMENT
Definition: protos.cpp:33
PROTO_STRUCT
Definition: protos.h:36
CLASS_STRUCT::NumProtos
int16_t NumProtos
Definition: protos.h:55
FreeClassFields
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:138
PROTO_STRUCT::Angle
float Angle
Definition: protos.h:42
Config
CLUSTERCONFIG Config
Definition: commontraining.cpp:88