/** * Release the memory consumed by the specified character * description and all of the features in that description. * * @param CharDesc character description to be deallocated * * Globals: * - none * * @note Exceptions: none * @note History: Wed May 23 13:52:19 1990, DSJ, Created. */ void FreeCharDescription(CHAR_DESC CharDesc) { int i; if (CharDesc) { for (i = 0; i < CharDesc->NumFeatureSets; i++) FreeFeatureSet (CharDesc->FeatureSets[i]); Efree(CharDesc); } } /* FreeCharDescription */
/*---------------------------------------------------------------------------*/ void ReadTrainingSamples ( FILE *File, LIST* TrainingSamples) /* ** Parameters: ** File open text file to read samples from ** Globals: none ** Operation: ** This routine reads training samples from a file and ** places them into a data structure which organizes the ** samples by FontName and CharName. It then returns this ** data structure. ** Return: none ** Exceptions: none ** History: Fri Aug 18 13:11:39 1989, DSJ, Created. ** Tue May 17 1998 simplifications to structure, illiminated ** font, and feature specification levels of structure. */ { char unichar[UNICHAR_LEN + 1]; LABELEDLIST CharSample; FEATURE_SET FeatureSamples; CHAR_DESC CharDesc; int Type, i; while (fscanf (File, "%s %s", FontName, unichar) == 2) { CharSample = FindList (*TrainingSamples, unichar); if (CharSample == NULL) { CharSample = NewLabeledList (unichar); *TrainingSamples = push (*TrainingSamples, CharSample); } CharDesc = ReadCharDescription (File); Type = ShortNameToFeatureType(PROGRAM_FEATURE_TYPE); FeatureSamples = CharDesc->FeatureSets[Type]; for (int feature = 0; feature < FeatureSamples->NumFeatures; ++feature) { FEATURE f = FeatureSamples->Features[feature]; for (int dim =0; dim < f->Type->NumParams; ++dim) f->Params[dim] += UniformRandomNumber(-MINSD, MINSD); } CharSample->List = push (CharSample->List, FeatureSamples); CharSample->SampleCount++; for (i = 0; i < CharDesc->NumFeatureSets; i++) if (Type != i) FreeFeatureSet(CharDesc->FeatureSets[i]); free (CharDesc); } } // ReadTrainingSamples
/*---------------------------------------------------------------------------*/ void FreeCharDescription(CHAR_DESC CharDesc) { /* ** Parameters: ** CharDesc character description to be deallocated ** Globals: none ** Operation: Release the memory consumed by the specified character ** description and all of the features in that description. ** Return: none ** Exceptions: none ** History: Wed May 23 13:52:19 1990, DSJ, Created. */ int i; if (CharDesc) { for (i = 0; i < NumFeatureSetsIn (CharDesc); i++) FreeFeatureSet (FeaturesOfType (CharDesc, i)); Efree(CharDesc); } } /* FreeCharDescription */
/*---------------------------------------------------------------------------*/ void FreeTrainingSamples ( LIST CharList) /* ** Parameters: ** FontList list of all fonts in document ** Globals: none ** Operation: ** This routine deallocates all of the space allocated to ** the specified list of training samples. ** Return: none ** Exceptions: none ** History: Fri Aug 18 17:44:27 1989, DSJ, Created. */ { LABELEDLIST CharSample; FEATURE_SET FeatureSet; LIST FeatureList; // printf ("FreeTrainingSamples...\n"); iterate (CharList) /* iterate thru all of the fonts */ { CharSample = (LABELEDLIST) first_node (CharList); FeatureList = CharSample->List; iterate (FeatureList) /* iterate thru all of the classes */ { FeatureSet = (FEATURE_SET) first_node (FeatureList); FreeFeatureSet (FeatureSet); } FreeLabeledList (CharSample); } destroy (CharList); } /* FreeTrainingSamples */
/*---------------------------------------------------------------------------*/ LIST ReadTrainingSamples ( FILE *File) /* ** Parameters: ** File open text file to read samples from ** Globals: none ** Operation: ** This routine reads training samples from a file and ** places them into a data structure which organizes the ** samples by FontName and CharName. It then returns this ** data structure. ** Return: none ** Exceptions: none ** History: Fri Aug 18 13:11:39 1989, DSJ, Created. ** Tue May 17 1998 simplifications to structure, illiminated ** font, and feature specification levels of structure. */ { char unichar[UNICHAR_LEN + 1]; LABELEDLIST CharSample; FEATURE_SET FeatureSamples; LIST TrainingSamples = NIL; CHAR_DESC CharDesc; int Type, i; while (fscanf (File, "%s %s", CTFontName, unichar) == 2) { if (!unicharset_training.contains_unichar(unichar)) { unicharset_training.unichar_insert(unichar); if (unicharset_training.size() > MAX_NUM_CLASSES) { cprintf("Error: Size of unicharset of mftraining is " "greater than MAX_NUM_CLASSES\n"); exit(1); } } CharSample = FindList (TrainingSamples, unichar); if (CharSample == NULL) { CharSample = NewLabeledList (unichar); TrainingSamples = push (TrainingSamples, CharSample); } CharDesc = ReadCharDescription (File); Type = ShortNameToFeatureType(PROGRAM_FEATURE_TYPE); FeatureSamples = CharDesc->FeatureSets[Type]; for (int feature = 0; feature < FeatureSamples->NumFeatures; ++feature) { FEATURE f = FeatureSamples->Features[feature]; for (int dim =0; dim < f->Type->NumParams; ++dim) f->Params[dim] += dim == MFDirection ? UniformRandomNumber(-MINSD_ANGLE, MINSD_ANGLE) : UniformRandomNumber(-MINSD, MINSD); } CharSample->List = push (CharSample->List, FeatureSamples); CharSample->SampleCount++; for (i = 0; i < CharDesc->NumFeatureSets; i++) if (Type != i) FreeFeatureSet(CharDesc->FeatureSets[i]); free (CharDesc); } return (TrainingSamples); } /* ReadTrainingSamples */