tesseract  5.0.0-alpha-619-ge9db
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

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 20 of file protos.cpp.

◆ CONFIG_INCREMENT

#define CONFIG_INCREMENT   16

Definition at line 32 of file protos.cpp.

◆ PROTO_INCREMENT

#define PROTO_INCREMENT   32

Definition at line 31 of file protos.cpp.

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]);

◆ 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