#include "bitvec.h"
#include "cutil.h"
Go to the source code of this file.
#define ClassOfChar | ( | Char | ) |
Value:
((TrainingData [Char].NumProtos) ? \ (& TrainingData [Char]) : \ NO_CLASS)
#define CoefficientA | ( | Proto | ) | ((Proto)->A) |
Return the first parameter of the prototype structure.
This is the A coefficient in the line representation of
"Ax + By + C = 0". The 'Proto' argument is of type 'PROTO'.
Definition at line 160 of file protos.h.
Referenced by ConvertProto(), CopyProto(), ReadProtos(), SetUpForFloat2Int(), and SubfeatureEvidence().
#define CoefficientB | ( | Proto | ) | ((Proto)->B) |
Return the second parameter of the prototype structure.
This is the B coefficient in the line representation of
"Ax + By + C = 0". The 'Proto' argument is of type 'PROTO'.
Definition at line 170 of file protos.h.
Referenced by ConvertProto(), CopyProto(), ReadProtos(), SetUpForFloat2Int(), and SubfeatureEvidence().
#define CoefficientC | ( | Proto | ) | ((Proto)->C) |
Return the third parameter of the prototype structure.
This is the C coefficient in the line representation of
"Ax + By + C = 0". The 'Proto' argument is of type 'PROTO'.
Definition at line 180 of file protos.h.
Referenced by ConvertProto(), CopyProto(), ReadProtos(), SetUpForFloat2Int(), and SubfeatureEvidence().
#define ConfigIn | ( | Class, | |||
Cid | ) | ((Class)->Configurations [Cid]) |
Choose the selected prototype configuration in this class record.
Return it as type 'BIT_VECTOR'.
Definition at line 134 of file protos.h.
Referenced by AddConfigToClass(), AddProtoToClass(), CreateIntTemplates(), FreeClassFields(), ReadConfigs(), SetUpForFloat2Int(), SplitProto(), WriteConfigs(), and WriteOldConfigFile().
#define NUMBER_OF_CLASSES 256 |
#define NumConfigsIn | ( | Class | ) | ((Class)->NumConfigs) |
Return the number of configurations in this class.
The 'Class' argument is of type 'CLASS_TYPE'.
Definition at line 150 of file protos.h.
Referenced by AddConfigToClass(), AddProtoToClass(), CreateIntTemplates(), FreeClassFields(), ReadConfigs(), SetUpForFloat2Int(), SplitProto(), WriteConfigs(), and WriteOldConfigFile().
#define NumProtosIn | ( | Class | ) | ((Class)->NumProtos) |
Return the number of prototypes in this class.
The 'Class' argument is of type 'CLASS_TYPE'.
Definition at line 142 of file protos.h.
Referenced by AddProtoToClass(), ClassConfigLength(), ClassProtoLength(), CreateIntTemplates(), FindClosestExistingProto(), PrintProtos(), ReadConfigs(), ReadProtos(), SetUpForFloat2Int(), WriteConfigs(), WriteOldConfigFile(), WriteOldProtoFile(), and WriteProtos().
#define PrintProto | ( | Proto | ) |
Value:
(cprintf ("X=%4.2f, Y=%4.2f, Angle=%4.2f", \ ProtoX (Proto), \ ProtoY (Proto), \ ProtoLength (Proto), \ ProtoAngle (Proto))) \
The 'Proto' argument is of type 'PROTO'.
Definition at line 220 of file protos.h.
Referenced by PrintProtos().
#define PrintProtoLine | ( | Proto | ) |
Value:
(cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \ CoefficientA (Proto), \ CoefficientB (Proto), \ CoefficientC (Proto))) \
The 'Proto' argument is of type 'PROTO'.
Definition at line 233 of file protos.h.
Referenced by PrintProtos().
#define ProtoAngle | ( | Proto | ) | ((Proto)->Angle) |
Return the angle parameter of the prototype structure.
The 'Proto' argument is of type 'PROTO'.
Definition at line 188 of file protos.h.
Referenced by AddProtoToProtoPruner(), CompareProtos(), ComputeMergedProto(), ComputePaddedBoundingBox(), ConvertProto(), CopyProto(), DummyFastMatch(), InitTableFiller(), MakeNewAdaptedClass(), MakeNewFromOld(), MakeNewTempProtos(), ReadProtos(), SetUpForFloat2Int(), SubfeatureEvidence(), WriteOldProtoFile(), and WriteProtos().
#define ProtoIn | ( | Class, | |||
Pid | ) | (& (Class)->Prototypes [Pid]) |
Choose the selected prototype in this class record.
Return the pointer to it (type PROTO).
Definition at line 126 of file protos.h.
Referenced by ClassConfigLength(), ClassProtoLength(), CreateIntTemplates(), FindClosestExistingProto(), PrintProtos(), ReadProtos(), SetUpForFloat2Int(), WriteOldProtoFile(), and WriteProtos().
#define ProtoLength | ( | Proto | ) | ((Proto)->Length) |
Return the length parameter of the prototype structure.
The 'Proto' argument is of type 'PROTO'.
Definition at line 212 of file protos.h.
Referenced by AddProtoToProtoPruner(), ClassConfigLength(), ClassProtoLength(), CompareProtos(), ComputeMergedProto(), ComputePaddedBoundingBox(), ConvertProto(), CopyProto(), InitTableFiller(), MakeNewAdaptedClass(), MakeNewFromOld(), MakeNewTempProtos(), ReadProtos(), SetUpForFloat2Int(), WriteOldProtoFile(), and WriteProtos().
#define ProtoX | ( | Proto | ) | ((Proto)->X) |
Return the X parameter of the prototype structure.
The 'Proto' argument is of type 'PROTO'.
Definition at line 196 of file protos.h.
Referenced by AddProtoToProtoPruner(), CompareProtos(), ComputeMergedProto(), ComputePaddedBoundingBox(), CopyProto(), InitTableFiller(), MakeNewAdaptedClass(), MakeNewFromOld(), MakeNewTempProtos(), ReadProtos(), SetUpForFloat2Int(), WriteOldProtoFile(), and WriteProtos().
#define ProtoY | ( | Proto | ) | ((Proto)->Y) |
Return the angle parameter of the prototype structure.
The 'Proto' argument is of type 'PROTO'.
Definition at line 204 of file protos.h.
Referenced by AddProtoToProtoPruner(), CompareProtos(), ComputeMergedProto(), ComputePaddedBoundingBox(), CopyProto(), InitTableFiller(), MakeNewAdaptedClass(), MakeNewFromOld(), MakeNewTempProtos(), ReadProtos(), SetUpForFloat2Int(), WriteOldProtoFile(), and WriteProtos().
int AddConfigToClass | ( | CLASS_TYPE | Class | ) |
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.
Definition at line 55 of file protos.cpp.
References Config, CONFIG_INCREMENT, ConfigIn, Erealloc(), CLASS_STRUCT::MaxNumProtos, NewBitVector(), NumConfigsIn, WordsInVectorOfSize, and zero_all_bits.
00055 { 00056 int NewNumConfigs; 00057 int NewConfig; 00058 int MaxNumProtos; 00059 BIT_VECTOR Config; 00060 00061 MaxNumProtos = Class->MaxNumProtos; 00062 00063 if (NumConfigsIn (Class) >= Class->MaxNumConfigs) { 00064 /* add configs in CONFIG_INCREMENT chunks at a time */ 00065 NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) / 00066 CONFIG_INCREMENT) * CONFIG_INCREMENT); 00067 00068 Class->Configurations = 00069 (CONFIGS) Erealloc (Class->Configurations, 00070 sizeof (BIT_VECTOR) * NewNumConfigs); 00071 00072 Class->MaxNumConfigs = NewNumConfigs; 00073 } 00074 NewConfig = NumConfigsIn (Class); 00075 NumConfigsIn (Class)++; 00076 Config = NewBitVector (MaxNumProtos); 00077 ConfigIn (Class, NewConfig) = Config; 00078 zero_all_bits (Config, WordsInVectorOfSize (MaxNumProtos)); 00079 00080 return (NewConfig); 00081 }
int AddProtoToClass | ( | CLASS_TYPE | Class | ) |
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.
Definition at line 90 of file protos.cpp.
References Config, ConfigIn, Erealloc(), ExpandBitVector(), NumConfigsIn, NumProtosIn, PROTO_INCREMENT, and reset_bit.
Referenced by SplitProto().
00090 { 00091 int i; 00092 int Bit; 00093 int NewNumProtos; 00094 int NewProto; 00095 BIT_VECTOR Config; 00096 00097 if (NumProtosIn (Class) >= Class->MaxNumProtos) { 00098 /* add protos in PROTO_INCREMENT chunks at a time */ 00099 NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) / 00100 PROTO_INCREMENT) * PROTO_INCREMENT); 00101 00102 Class->Prototypes = (PROTO) Erealloc (Class->Prototypes, 00103 sizeof (PROTO_STRUCT) * 00104 NewNumProtos); 00105 00106 Class->MaxNumProtos = NewNumProtos; 00107 00108 for (i = 0; i < NumConfigsIn (Class); i++) { 00109 Config = ConfigIn (Class, i); 00110 ConfigIn (Class, i) = ExpandBitVector (Config, NewNumProtos); 00111 00112 for (Bit = NumProtosIn (Class); Bit < NewNumProtos; Bit++) 00113 reset_bit(Config, Bit); 00114 } 00115 } 00116 NewProto = NumProtosIn (Class); 00117 NumProtosIn (Class)++; 00118 return (NewProto); 00119 }
FLOAT32 ClassConfigLength | ( | CLASS_TYPE | Class, | |
BIT_VECTOR | Config | |||
) |
Return the length of all the protos in this class.
Definition at line 125 of file protos.cpp.
References NumProtosIn, ProtoIn, ProtoLength, and test_bit.
00125 { 00126 INT16 Pid; 00127 FLOAT32 TotalLength = 0; 00128 00129 for (Pid = 0; Pid < NumProtosIn (Class); Pid++) { 00130 if (test_bit (Config, Pid)) { 00131 00132 TotalLength += ProtoLength (ProtoIn (Class, Pid)); 00133 } 00134 } 00135 return (TotalLength); 00136 }
FLOAT32 ClassProtoLength | ( | CLASS_TYPE | Class | ) |
Return the length of all the protos in this class.
Definition at line 142 of file protos.cpp.
References NumProtosIn, ProtoIn, and ProtoLength.
00142 { 00143 INT16 Pid; 00144 FLOAT32 TotalLength = 0; 00145 00146 for (Pid = 0; Pid < NumProtosIn (Class); Pid++) { 00147 TotalLength += ProtoLength (ProtoIn (Class, Pid)); 00148 } 00149 return (TotalLength); 00150 }
Copy the first proto into the second.
Definition at line 156 of file protos.cpp.
References CoefficientA, CoefficientB, CoefficientC, ProtoAngle, ProtoLength, ProtoX, and ProtoY.
00156 { 00157 ProtoX (Dest) = ProtoX (Src); 00158 ProtoY (Dest) = ProtoY (Src); 00159 ProtoLength (Dest) = ProtoLength (Src); 00160 ProtoAngle (Dest) = ProtoAngle (Src); 00161 CoefficientA (Dest) = CoefficientA (Src); 00162 CoefficientB (Dest) = CoefficientB (Src); 00163 CoefficientC (Dest) = CoefficientC (Src); 00164 }
void FillABC | ( | PROTO | Proto | ) |
Fill in Protos A, B, C fields based on the X, Y, Angle fields.
Definition at line 170 of file protos.cpp.
References PROTO_STRUCT::A, PROTO_STRUCT::Angle, PROTO_STRUCT::B, PROTO_STRUCT::C, PI, PROTO_STRUCT::X, and PROTO_STRUCT::Y.
Referenced by ComputeMergedProto(), MakeNewAdaptedClass(), MakeNewFromOld(), and MakeNewTempProtos().
00170 { 00171 FLOAT32 Slope, Intercept, Normalizer; 00172 00173 Slope = tan (Proto->Angle * 2.0 * PI); 00174 Intercept = Proto->Y - Slope * Proto->X; 00175 Normalizer = 1.0 / sqrt (Slope * Slope + 1.0); 00176 Proto->A = Slope * Normalizer; 00177 Proto->B = -Normalizer; 00178 Proto->C = Intercept * Normalizer; 00179 }
void FreeClass | ( | CLASS_TYPE | Class | ) |
Deallocate the memory consumed by the specified class.
Definition at line 185 of file protos.cpp.
References FreeClassFields(), and memfree().
Referenced by FreeLabeledClassList().
00185 { 00186 if (Class) { 00187 FreeClassFields(Class); 00188 memfree(Class); 00189 } 00190 }
void FreeClassFields | ( | CLASS_TYPE | Class | ) |
Deallocate the memory consumed by subfields of the specified class.
Definition at line 196 of file protos.cpp.
References ConfigIn, FreeBitVector(), CLASS_STRUCT::MaxNumConfigs, CLASS_STRUCT::MaxNumProtos, memfree(), NumConfigsIn, and CLASS_STRUCT::Prototypes.
Referenced by FreeClass().
00196 { 00197 int i; 00198 00199 if (Class) { 00200 if (Class->MaxNumProtos > 0) 00201 memfree (Class->Prototypes); 00202 if (Class->MaxNumConfigs > 0) { 00203 for (i = 0; i < NumConfigsIn (Class); i++) 00204 FreeBitVector (ConfigIn (Class, i)); 00205 memfree (Class->Configurations); 00206 } 00207 } 00208 }
void InitPrototypes | ( | ) |
Initialize anything that needs to be initialized to work with the functions in this file.
Definition at line 215 of file protos.cpp.
References string_variable, and TrainingFile.
00215 { 00216 string_variable (TrainingFile, "TrainingFile", "MicroFeatures"); 00217 }
CLASS_TYPE NewClass | ( | int | NumProtos, | |
int | NumConfigs | |||
) |
Allocate a new class with enough memory to hold the specified number of prototypes and configurations.
Definition at line 224 of file protos.cpp.
References CLASS_STRUCT::Configurations, Emalloc(), CLASS_STRUCT::MaxNumConfigs, CLASS_STRUCT::MaxNumProtos, CLASS_STRUCT::NumConfigs, CLASS_STRUCT::NumProtos, and CLASS_STRUCT::Prototypes.
Referenced by NewLabeledClass().
00224 { 00225 CLASS_TYPE Class; 00226 00227 Class = (CLASS_TYPE) Emalloc (sizeof (CLASS_STRUCT)); 00228 00229 if (NumProtos > 0) 00230 Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT)); 00231 00232 if (NumConfigs > 0) 00233 Class->Configurations = (CONFIGS) Emalloc (NumConfigs * 00234 sizeof (BIT_VECTOR)); 00235 Class->MaxNumProtos = NumProtos; 00236 Class->MaxNumConfigs = NumConfigs; 00237 Class->NumProtos = 0; 00238 Class->NumConfigs = 0; 00239 return (Class); 00240 00241 }
void PrintProtos | ( | CLASS_TYPE | Class | ) |
Print the list of prototypes in this class type.
Definition at line 247 of file protos.cpp.
References cprintf(), new_line, NumProtosIn, PrintProto, PrintProtoLine, and ProtoIn.
00247 { 00248 INT16 Pid; 00249 00250 for (Pid = 0; Pid < NumProtosIn (Class); Pid++) { 00251 cprintf ("Proto %d:\t", Pid); 00252 PrintProto (ProtoIn (Class, Pid)); 00253 cprintf ("\t"); 00254 PrintProtoLine (ProtoIn (Class, Pid)); 00255 new_line(); 00256 } 00257 }
void ReadClassFile | ( | ) |
Read in the training data from a file.
All of the classes are read in.
The results are stored in the global variable, 'TrainingData'.
Definition at line 267 of file protos.cpp.
References CHARS_PER_LINE, cprintf(), new_line, NULL, open_file(), ReadClassFromFile(), and TrainingFile.
00267 { 00268 FILE *File; 00269 char TextLine[CHARS_PER_LINE]; 00270 00271 cprintf ("Reading training data from '%s' ...", TrainingFile); 00272 fflush(stdout); 00273 00274 File = open_file (TrainingFile, "r"); 00275 while (fgets (TextLine, CHARS_PER_LINE, File) != NULL) { 00276 00277 ReadClassFromFile (File, TextLine[0]); 00278 fgets(TextLine, CHARS_PER_LINE, File); 00279 fgets(TextLine, CHARS_PER_LINE, File); 00280 } 00281 fclose(File); 00282 00283 new_line(); 00284 }
void ReadClassFromFile | ( | FILE * | File, | |
char | ClassChar | |||
) |
Read in a class description (protos and configs) from a file.
Update the class structure record.
Definition at line 292 of file protos.cpp.
References ReadConfigs(), ReadProtos(), and TrainingData.
Referenced by ReadClassFile().
00292 { 00293 CLASS_TYPE Class; 00294 00295 Class = &TrainingData[ClassChar]; 00296 00297 ReadProtos(File, Class); 00298 00299 ReadConfigs(File, Class); 00300 }
void ReadConfigs | ( | register FILE * | File, | |
CLASS_TYPE | Class | |||
) |
Read the prototype configurations for this class from a file.
Read the requested number of lines.
Definition at line 308 of file protos.cpp.
References ConfigIn, CLASS_STRUCT::Configurations, Emalloc(), fscanf(), CLASS_STRUCT::MaxNumConfigs, NewBitVector(), NumConfigsIn, NumProtosIn, and WordsInVectorOfSize.
Referenced by ReadClassFromFile().
00308 { 00309 INT16 Cid; 00310 register INT16 Wid; 00311 register BIT_VECTOR ThisConfig; 00312 int NumWords; 00313 int NumConfigs; 00314 00315 fscanf (File, "%d %d\n", &NumConfigs, &NumWords); 00316 NumConfigsIn (Class) = NumConfigs; 00317 Class->MaxNumConfigs = NumConfigs; 00318 Class->Configurations = 00319 (CONFIGS) Emalloc (sizeof (BIT_VECTOR) * NumConfigs); 00320 NumWords = WordsInVectorOfSize (NumProtosIn (Class)); 00321 00322 for (Cid = 0; Cid < NumConfigs; Cid++) { 00323 00324 ThisConfig = NewBitVector (NumProtosIn (Class)); 00325 for (Wid = 0; Wid < NumWords; Wid++) 00326 fscanf (File, "%x", &ThisConfig[Wid]); 00327 ConfigIn (Class, Cid) = ThisConfig; 00328 } 00329 }
void ReadProtos | ( | register FILE * | File, | |
CLASS_TYPE | Class | |||
) |
Read in all the prototype information from a file.
Read the number of lines requested.
Definition at line 337 of file protos.cpp.
References CoefficientA, CoefficientB, CoefficientC, Emalloc(), fscanf(), CLASS_STRUCT::MaxNumProtos, NumProtosIn, ProtoAngle, ProtoIn, ProtoLength, CLASS_STRUCT::Prototypes, ProtoX, and ProtoY.
Referenced by ReadClassFromFile().
00337 { 00338 register INT16 Pid; 00339 register PROTO Proto; 00340 int NumProtos; 00341 00342 fscanf (File, "%d\n", &NumProtos); 00343 NumProtosIn (Class) = NumProtos; 00344 Class->MaxNumProtos = NumProtos; 00345 Class->Prototypes = (PROTO) Emalloc (sizeof (PROTO_STRUCT) * NumProtos); 00346 00347 for (Pid = 0; Pid < NumProtos; Pid++) { 00348 Proto = ProtoIn (Class, Pid); 00349 fscanf (File, "%f %f %f %f %f %f %f\n", 00350 &ProtoX (Proto), 00351 &ProtoY (Proto), 00352 &ProtoLength (Proto), 00353 &ProtoAngle (Proto), 00354 &CoefficientA (Proto), 00355 &CoefficientB (Proto), &CoefficientC (Proto)); 00356 } 00357 }
int SplitProto | ( | CLASS_TYPE | Class, | |
int | OldPid | |||
) |
Add a new proto to this class.
Definition at line 370 of file protos.cpp.
References AddProtoToClass(), Config, ConfigIn, NumConfigsIn, SET_BIT, and test_bit.
00370 { 00371 int i; 00372 int NewPid; 00373 BIT_VECTOR Config; 00374 00375 NewPid = AddProtoToClass (Class); 00376 00377 for (i = 0; i < NumConfigsIn (Class); i++) { 00378 Config = ConfigIn (Class, i); 00379 if (test_bit (Config, OldPid)) 00380 SET_BIT(Config, NewPid); 00381 } 00382 return (NewPid); 00383 }
void WriteOldConfigFile | ( | FILE * | File, | |
CLASS_TYPE | Class | |||
) |
Write the configs in the given class to the specified file in the old config format.
Definition at line 390 of file protos.cpp.
References Config, ConfigIn, NumConfigsIn, NumProtosIn, and test_bit.
Referenced by WriteMergedTrainingSamples().
00390 { 00391 int Cid, Pid; 00392 BIT_VECTOR Config; 00393 00394 fprintf (File, "%d %d\n", NumConfigsIn (Class), NumProtosIn (Class)); 00395 00396 for (Cid = 0; Cid < NumConfigsIn (Class); Cid++) { 00397 fprintf (File, "1 "); 00398 00399 Config = ConfigIn (Class, Cid); 00400 00401 for (Pid = 0; Pid < NumProtosIn (Class); Pid++) { 00402 if (test_bit (Config, Pid)) 00403 fprintf (File, "1"); 00404 else 00405 fprintf (File, "0"); 00406 } 00407 fprintf (File, "\n"); 00408 } 00409 }
void WriteOldProtoFile | ( | FILE * | File, | |
CLASS_TYPE | Class | |||
) |
Write protos in Class to File in the old proto format.
Definition at line 415 of file protos.cpp.
References NumProtosIn, ProtoAngle, ProtoIn, ProtoLength, ProtoX, and ProtoY.
Referenced by WriteMergedTrainingSamples().
00415 { 00416 int Pid; 00417 PROTO Proto; 00418 00419 /* print old header */ 00420 fprintf (File, "6\n"); 00421 fprintf (File, "linear essential -0.500000 0.500000\n"); 00422 fprintf (File, "linear essential -0.250000 0.750000\n"); 00423 fprintf (File, "linear essential 0.000000 1.000000\n"); 00424 fprintf (File, "circular essential 0.000000 1.000000\n"); 00425 fprintf (File, "linear non-essential -0.500000 0.500000\n"); 00426 fprintf (File, "linear non-essential -0.500000 0.500000\n"); 00427 00428 for (Pid = 0; Pid < NumProtosIn (Class); Pid++) { 00429 Proto = ProtoIn (Class, Pid); 00430 00431 fprintf (File, "significant elliptical 1\n"); 00432 fprintf (File, " %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f\n", 00433 ProtoX (Proto), ProtoY (Proto), 00434 ProtoLength (Proto), ProtoAngle (Proto), 0.0, 0.0); 00435 fprintf (File, " %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f\n", 00436 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001); 00437 } 00438 }
Definition at line 40 of file protos.cpp.
Referenced by ReadClassFromFile(), and SetUpForFloat2Int().