tesseract  5.0.0-alpha-619-ge9db
protos.h File Reference
#include "bitvec.h"
#include "params.h"
#include <tesseract/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 73 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 82 of file protos.h.

Typedef Documentation

◆ CLASS_TYPE

Definition at line 61 of file protos.h.

◆ CLASSES

Definition at line 62 of file protos.h.

◆ CONFIGS

using CONFIGS = BIT_VECTOR*

Definition at line 32 of file protos.h.

◆ PROTO

using PROTO = PROTO_STRUCT*

Definition at line 43 of file protos.h.

Function Documentation

◆ AddConfigToClass()

int AddConfigToClass ( CLASS_TYPE  Class)

Definition at line 45 of file protos.cpp.

46  {
47  int NewNumConfigs;
48  int NewConfig;
49  int MaxNumProtos;
51 
52  MaxNumProtos = Class->MaxNumProtos;
53  ASSERT_HOST(MaxNumProtos <= MAX_NUM_PROTOS);
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(MAX_NUM_PROTOS);
68  Class->Configurations[NewConfig] = Config;
69  zero_all_bits (Config, WordsInVectorOfSize(MAX_NUM_PROTOS));
70 
71  return (NewConfig);

◆ AddProtoToClass()

int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 82 of file protos.cpp.

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

◆ FillABC()

void FillABC ( PROTO  Proto)

Definition at line 105 of file protos.cpp.

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

◆ FreeClass()

void FreeClass ( CLASS_TYPE  Class)

Definition at line 121 of file protos.cpp.

124  {
125  if (Class) {
126  FreeClassFields(Class);

◆ FreeClassFields()

void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 133 of file protos.cpp.

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

◆ InitPrototypes()

void InitPrototypes ( )

◆ NewClass()

CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 151 of file protos.cpp.

156  {
157  CLASS_TYPE Class;
158 
159  Class = new CLASS_STRUCT;
160 
161  if (NumProtos > 0)
162  Class->Prototypes = static_cast<PROTO>(Emalloc (NumProtos * sizeof (PROTO_STRUCT)));
163 
164  if (NumConfigs > 0)
165  Class->Configurations = static_cast<CONFIGS>(Emalloc (NumConfigs *
166  sizeof (BIT_VECTOR)));
167  Class->MaxNumProtos = NumProtos;
168  Class->MaxNumConfigs = NumConfigs;
CLASS_STRUCT::Configurations
CONFIGS Configurations
Definition: protos.h:58
Emalloc
void * Emalloc(int Size)
Definition: emalloc.cpp:31
PROTO_INCREMENT
#define PROTO_INCREMENT
Definition: protos.cpp:31
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
PROTO_STRUCT
Definition: protos.h:34
CLASS_STRUCT::NumProtos
int16_t NumProtos
Definition: protos.h:53
Config
CLUSTERCONFIG Config
Definition: commontraining.cpp:88
CLASS_STRUCT::MaxNumProtos
int16_t MaxNumProtos
Definition: protos.h:54
PROTO_STRUCT::B
float B
Definition: protos.h:36
FreeClassFields
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:133
MAX_NUM_PROTOS
#define MAX_NUM_PROTOS
Definition: intproto.h:47
PROTO_STRUCT::Y
float Y
Definition: protos.h:39
CLASS_STRUCT::NumConfigs
int16_t NumConfigs
Definition: protos.h:56
PROTO_STRUCT::X
float X
Definition: protos.h:38
CLASS_STRUCT
Definition: protos.h:45
PROTO_STRUCT::Angle
float Angle
Definition: protos.h:40
BIT_VECTOR
uint32_t * BIT_VECTOR
Definition: bitvec.h:27
CLASS_STRUCT::MaxNumConfigs
int16_t MaxNumConfigs
Definition: protos.h:57
Erealloc
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
CLASS_STRUCT::Prototypes
PROTO Prototypes
Definition: protos.h:55
PROTO_STRUCT::A
float A
Definition: protos.h:35
CONFIG_INCREMENT
#define CONFIG_INCREMENT
Definition: protos.cpp:32