* This routine creates a new sample data structure to hold * the specified feature. This sample is added to the clusterer * data structure (so that it knows which samples are to be * clustered later), and a pointer to the sample is returned to * the caller. * * @param Clusterer clusterer data structure to add sample to * @param Feature feature to be added to clusterer * @param CharID uni
| 454 | * @note History: 5/29/89, DSJ, Created. |
| 455 | */ |
| 456 | SAMPLE* MakeSample(CLUSTERER * Clusterer, const FLOAT32* Feature, |
| 457 | inT32 CharID) { |
| 458 | SAMPLE *Sample; |
| 459 | int i; |
| 460 | |
| 461 | // see if the samples have already been clustered - if so trap an error |
| 462 | if (Clusterer->Root != NULL) |
| 463 | DoError (ALREADYCLUSTERED, |
| 464 | "Can't add samples after they have been clustered"); |
| 465 | |
| 466 | // allocate the new sample and initialize it |
| 467 | Sample = (SAMPLE *) Emalloc (sizeof (SAMPLE) + |
| 468 | (Clusterer->SampleSize - |
| 469 | 1) * sizeof (FLOAT32)); |
| 470 | Sample->Clustered = FALSE; |
| 471 | Sample->Prototype = FALSE; |
| 472 | Sample->SampleCount = 1; |
| 473 | Sample->Left = NULL; |
| 474 | Sample->Right = NULL; |
| 475 | Sample->CharID = CharID; |
| 476 | |
| 477 | for (i = 0; i < Clusterer->SampleSize; i++) |
| 478 | Sample->Mean[i] = Feature[i]; |
| 479 | |
| 480 | // add the sample to the KD tree - keep track of the total # of samples |
| 481 | Clusterer->NumberOfSamples++; |
| 482 | KDStore (Clusterer->KDTree, Sample->Mean, (char *) Sample); |
| 483 | if (CharID >= Clusterer->NumChar) |
| 484 | Clusterer->NumChar = CharID + 1; |
| 485 | |
| 486 | // execute hook for monitoring clustering operation |
| 487 | // (*SampleCreationHook)( Sample ); |
| 488 | |
| 489 | return (Sample); |
| 490 | } // MakeSample |
| 491 | |
| 492 | /** |
| 493 | * This routine first checks to see if the samples in this |
no test coverage detected