All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
protos.cpp File Reference
#include "protos.h"
#include "const.h"
#include "emalloc.h"
#include "freelist.h"
#include "callcpp.h"
#include "tprintf.h"
#include "scanutils.h"
#include "globals.h"
#include "classify.h"
#include "params.h"
#include <stdio.h>
#include <math.h>

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

Return the length of all the protos in this class.

Parameters
ClassThe class to use
FLOAT32 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

#define CONFIG_INCREMENT   16

Definition at line 43 of file protos.cpp.

#define PROTO_INCREMENT   32

Definition at line 42 of file protos.cpp.

Function Documentation

int AddConfigToClass ( CLASS_TYPE  Class)

Definition at line 63 of file protos.cpp.

63  {
64  int NewNumConfigs;
65  int NewConfig;
66  int MaxNumProtos;
68 
69  MaxNumProtos = Class->MaxNumProtos;
70 
71  if (Class->NumConfigs >= Class->MaxNumConfigs) {
72  /* add configs in CONFIG_INCREMENT chunks at a time */
73  NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) /
75 
76  Class->Configurations =
78  sizeof (BIT_VECTOR) * NewNumConfigs);
79 
80  Class->MaxNumConfigs = NewNumConfigs;
81  }
82  NewConfig = Class->NumConfigs++;
83  Config = NewBitVector (MaxNumProtos);
84  Class->Configurations[NewConfig] = Config;
85  zero_all_bits (Config, WordsInVectorOfSize (MaxNumProtos));
86 
87  return (NewConfig);
88 }
#define CONFIG_INCREMENT
Definition: protos.cpp:43
#define zero_all_bits(array, length)
Definition: bitvec.h:33
BIT_VECTOR * CONFIGS
Definition: protos.h:40
#define WordsInVectorOfSize(NumBits)
Definition: bitvec.h:63
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
inT16 NumConfigs
Definition: protos.h:62
BIT_VECTOR NewBitVector(int NumBits)
Definition: bitvec.cpp:90
inT16 MaxNumConfigs
Definition: protos.h:63
CLUSTERCONFIG Config
inT16 MaxNumProtos
Definition: protos.h:60
CONFIGS Configurations
Definition: protos.h:64
int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 99 of file protos.cpp.

99  {
100  int i;
101  int Bit;
102  int NewNumProtos;
103  int NewProto;
105 
106  if (Class->NumProtos >= Class->MaxNumProtos) {
107  /* add protos in PROTO_INCREMENT chunks at a time */
108  NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
110 
111  Class->Prototypes = (PROTO) Erealloc (Class->Prototypes,
112  sizeof (PROTO_STRUCT) *
113  NewNumProtos);
114 
115  Class->MaxNumProtos = NewNumProtos;
116 
117  for (i = 0; i < Class->NumConfigs; i++) {
118  Config = Class->Configurations[i];
119  Class->Configurations[i] = ExpandBitVector (Config, NewNumProtos);
120 
121  for (Bit = Class->NumProtos; Bit < NewNumProtos; Bit++)
122  reset_bit(Config, Bit);
123  }
124  }
125  NewProto = Class->NumProtos++;
126  if (Class->NumProtos > MAX_NUM_PROTOS) {
127  tprintf("Ouch! number of protos = %d, vs max of %d!",
128  Class->NumProtos, MAX_NUM_PROTOS);
129  }
130  return (NewProto);
131 }
PROTO_STRUCT * PROTO
Definition: protos.h:52
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
#define reset_bit(array, bit)
Definition: bitvec.h:59
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
#define tprintf(...)
Definition: tprintf.h:31
inT16 NumConfigs
Definition: protos.h:62
inT16 NumProtos
Definition: protos.h:59
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits)
Definition: bitvec.cpp:48
CLUSTERCONFIG Config
#define PROTO_INCREMENT
Definition: protos.cpp:42
#define MAX_NUM_PROTOS
Definition: intproto.h:47
inT16 MaxNumProtos
Definition: protos.h:60
PROTO Prototypes
Definition: protos.h:61
CONFIGS Configurations
Definition: protos.h:64
FLOAT32 ClassConfigLength ( CLASS_TYPE  Class,
BIT_VECTOR  Config 
)

Definition at line 142 of file protos.cpp.

142  {
143  inT16 Pid;
144  FLOAT32 TotalLength = 0;
145 
146  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
147  if (test_bit (Config, Pid)) {
148 
149  TotalLength += (ProtoIn (Class, Pid))->Length;
150  }
151  }
152  return (TotalLength);
153 }
float FLOAT32
Definition: host.h:111
#define ProtoIn(Class, Pid)
Definition: protos.h:123
#define test_bit(array, bit)
Definition: bitvec.h:61
inT16 NumProtos
Definition: protos.h:59
CLUSTERCONFIG Config
short inT16
Definition: host.h:100
FLOAT32 ClassProtoLength ( CLASS_TYPE  Class)

Definition at line 163 of file protos.cpp.

163  {
164  inT16 Pid;
165  FLOAT32 TotalLength = 0;
166 
167  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
168  TotalLength += (ProtoIn (Class, Pid))->Length;
169  }
170  return (TotalLength);
171 }
float FLOAT32
Definition: host.h:111
#define ProtoIn(Class, Pid)
Definition: protos.h:123
inT16 NumProtos
Definition: protos.h:59
short inT16
Definition: host.h:100
void CopyProto ( PROTO  Src,
PROTO  Dest 
)

Definition at line 182 of file protos.cpp.

182  {
183  Dest->X = Src->X;
184  Dest->Y = Src->Y;
185  Dest->Length = Src->Length;
186  Dest->Angle = Src->Angle;
187  Dest->A = Src->A;
188  Dest->B = Src->B;
189  Dest->C = Src->C;
190 }
FLOAT32 X
Definition: protos.h:47
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 B
Definition: protos.h:45
FLOAT32 Length
Definition: protos.h:50
FLOAT32 C
Definition: protos.h:46
FLOAT32 A
Definition: protos.h:44
FLOAT32 Y
Definition: protos.h:48
void FillABC ( PROTO  Proto)

Definition at line 198 of file protos.cpp.

198  {
199  FLOAT32 Slope, Intercept, Normalizer;
200 
201  Slope = tan (Proto->Angle * 2.0 * PI);
202  Intercept = Proto->Y - Slope * Proto->X;
203  Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
204  Proto->A = Slope * Normalizer;
205  Proto->B = -Normalizer;
206  Proto->C = Intercept * Normalizer;
207 }
float FLOAT32
Definition: host.h:111
FLOAT32 X
Definition: protos.h:47
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 B
Definition: protos.h:45
#define PI
Definition: const.h:19
FLOAT32 C
Definition: protos.h:46
FLOAT32 A
Definition: protos.h:44
FLOAT32 Y
Definition: protos.h:48
void FreeClass ( CLASS_TYPE  Class)

Definition at line 215 of file protos.cpp.

215  {
216  if (Class) {
217  FreeClassFields(Class);
218  delete Class;
219  }
220 }
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:228
void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 228 of file protos.cpp.

228  {
229  int i;
230 
231  if (Class) {
232  if (Class->MaxNumProtos > 0)
233  memfree (Class->Prototypes);
234  if (Class->MaxNumConfigs > 0) {
235  for (i = 0; i < Class->NumConfigs; i++)
236  FreeBitVector (Class->Configurations[i]);
237  memfree (Class->Configurations);
238  }
239  }
240 }
void memfree(void *element)
Definition: freelist.cpp:30
void FreeBitVector(BIT_VECTOR BitVector)
Definition: bitvec.cpp:55
inT16 NumConfigs
Definition: protos.h:62
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 MaxNumProtos
Definition: protos.h:60
PROTO Prototypes
Definition: protos.h:61
CONFIGS Configurations
Definition: protos.h:64
CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 248 of file protos.cpp.

248  {
249  CLASS_TYPE Class;
250 
251  Class = new CLASS_STRUCT;
252 
253  if (NumProtos > 0)
254  Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT));
255 
256  if (NumConfigs > 0)
257  Class->Configurations = (CONFIGS) Emalloc (NumConfigs *
258  sizeof (BIT_VECTOR));
259  Class->MaxNumProtos = NumProtos;
260  Class->MaxNumConfigs = NumConfigs;
261  Class->NumProtos = 0;
262  Class->NumConfigs = 0;
263  return (Class);
264 
265 }
BIT_VECTOR * CONFIGS
Definition: protos.h:40
PROTO_STRUCT * PROTO
Definition: protos.h:52
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
inT16 NumConfigs
Definition: protos.h:62
inT16 NumProtos
Definition: protos.h:59
void * Emalloc(int Size)
Definition: emalloc.cpp:47
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 MaxNumProtos
Definition: protos.h:60
PROTO Prototypes
Definition: protos.h:61
CONFIGS Configurations
Definition: protos.h:64
void PrintProtos ( CLASS_TYPE  Class)

Definition at line 273 of file protos.cpp.

273  {
274  inT16 Pid;
275 
276  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
277  cprintf ("Proto %d:\t", Pid);
278  PrintProto (ProtoIn (Class, Pid));
279  cprintf ("\t");
280  PrintProtoLine (ProtoIn (Class, Pid));
281  new_line();
282  }
283 }
#define PrintProtoLine(Proto)
Definition: protos.h:148
#define new_line()
Definition: cutil.h:83
#define ProtoIn(Class, Pid)
Definition: protos.h:123
inT16 NumProtos
Definition: protos.h:59
#define PrintProto(Proto)
Definition: protos.h:133
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
short inT16
Definition: host.h:100

Variable Documentation

char* classify_training_file = "MicroFeatures"

"Training file"

Definition at line 50 of file protos.cpp.

Definition at line 48 of file protos.cpp.