/** * Compare protos p1 and p2 and return an estimate of the * worst evidence rating that will result for any part of p1 * that is compared to p2. In other words, if p1 were broken * into pico-features and each pico-feature was matched to p2, * what is the worst evidence rating that will be achieved for * any pico-feature. * * @param p1, p2 protos to be compared * * Globals: none * * @return Worst possible result when matching p1 to p2. * @note Exceptions: none * @note History: Mon Nov 26 08:27:53 1990, DSJ, Created. */ FLOAT32 CompareProtos(PROTO p1, PROTO p2) { FEATURE Feature; FLOAT32 WorstEvidence = WORST_EVIDENCE; FLOAT32 Evidence; FLOAT32 Angle, Length; /* if p1 and p2 are not close in length, don't let them match */ Length = fabs (p1->Length - p2->Length); if (Length > MAX_LENGTH_MISMATCH) return (0.0); /* create a dummy pico-feature to be used for comparisons */ Feature = NewFeature (&PicoFeatDesc); Feature->Params[PicoFeatDir] = p1->Angle; /* convert angle to radians */ Angle = p1->Angle * 2.0 * PI; /* find distance from center of p1 to 1/2 picofeat from end */ Length = p1->Length / 2.0 - GetPicoFeatureLength () / 2.0; if (Length < 0) Length = 0; /* set the dummy pico-feature at one end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X + cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y + sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } /* set the dummy pico-feature at the other end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X - cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y - sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } FreeFeature (Feature); return (WorstEvidence); } /* CompareProtos */
/** * Release the memory consumed by the specified feature * set. This routine also frees the memory consumed by the * features contained in the set. * @param FeatureSet set of features to be freed */ void FreeFeatureSet(FEATURE_SET FeatureSet) { int i; if (FeatureSet) { for (i = 0; i < FeatureSet->NumFeatures; i++) FreeFeature(FeatureSet->Features[i]); free(FeatureSet); } } /* FreeFeatureSet */
/** * Add a feature to a feature set. If the feature set is * already full, false is returned to indicate that the * feature could not be added to the set; otherwise, true is * returned. * @param FeatureSet set of features to add Feature to * @param Feature feature to be added to FeatureSet * @return true if feature added to set, false if set is already full. */ bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature) { if (FeatureSet->NumFeatures >= FeatureSet->MaxNumFeatures) { FreeFeature(Feature); return false; } FeatureSet->Features[FeatureSet->NumFeatures++] = Feature; return true; } /* AddFeature */
/*---------------------------------------------------------------------------*/ void FreeFeatureSet(FEATURE_SET FeatureSet) { /* ** Parameters: ** FeatureSet set of features to be freed ** Globals: none ** Operation: Release the memory consumed by the specified feature ** set. This routine also frees the memory consumed by the ** features contained in the set. ** Return: none ** Exceptions: none ** History: Mon May 21 13:59:46 1990, DSJ, Created. */ int i; if (FeatureSet) { for (i = 0; i < FeatureSet->NumFeatures; i++) FreeFeature(FeatureSet->Features[i]); memfree(FeatureSet); } } /* FreeFeatureSet */
/*---------------------------------------------------------------------------*/ BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature) { /* ** Parameters: ** FeatureSet set of features to add Feature to ** Feature feature to be added to FeatureSet ** Globals: none ** Operation: Add a feature to a feature set. If the feature set is ** already full, FALSE is returned to indicate that the ** feature could not be added to the set; otherwise, TRUE is ** returned. ** Return: TRUE if feature added to set, FALSE if set is already full. ** Exceptions: none ** History: Tue May 22 17:22:23 1990, DSJ, Created. */ if (FeatureSet->NumFeatures >= FeatureSet->MaxNumFeatures) { FreeFeature(Feature); return FALSE; } FeatureSet->Features[FeatureSet->NumFeatures++] = Feature; return TRUE; } /* AddFeature */
/*---------------------------------------------------------------------------*/ FLOAT32 CompareProtos(PROTO p1, PROTO p2) { /* ** Parameters: ** p1, p2 protos to be compared ** Globals: none ** Operation: Compare protos p1 and p2 and return an estimate of the ** worst evidence rating that will result for any part of p1 ** that is compared to p2. In other words, if p1 were broken ** into pico-features and each pico-feature was matched to p2, ** what is the worst evidence rating that will be achieved for ** any pico-feature. ** Return: Worst possible result when matching p1 to p2. ** Exceptions: none ** History: Mon Nov 26 08:27:53 1990, DSJ, Created. */ FEATURE Feature; FLOAT32 WorstEvidence = WORST_EVIDENCE; FLOAT32 Evidence; FLOAT32 Angle, Length; /* if p1 and p2 are not close in length, don't let them match */ Length = fabs (p1->Length - p2->Length); if (Length > MAX_LENGTH_MISMATCH) return (0.0); /* create a dummy pico-feature to be used for comparisons */ Feature = NewFeature (&PicoFeatDesc); Feature->Params[PicoFeatDir] = p1->Angle; /* convert angle to radians */ Angle = p1->Angle * 2.0 * PI; /* find distance from center of p1 to 1/2 picofeat from end */ Length = p1->Length / 2.0 - GetPicoFeatureLength () / 2.0; if (Length < 0) Length = 0; /* set the dummy pico-feature at one end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X + cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y + sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } /* set the dummy pico-feature at the other end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X - cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y - sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } FreeFeature (Feature); return (WorstEvidence); } /* CompareProtos */