using MeasurementType = int;
void initializeSubsample(SubsampleType* subsample, SampleType* sample)
{
subsample->SetSample(sample);
subsample->InitializeWithAllInstances();
}
void printSubsample(SubsampleType* subsample, const char* header)
{
std::cout << std::endl;
std::cout << header << std::endl;
SubsampleType::Iterator iter = subsample->Begin();
while ( iter != subsample->End() )
{
std::cout << "instance identifier = " << iter.GetInstanceIdentifier()
<< " \t measurement vector = "
<< iter.GetMeasurementVector()
<< std::endl;
++iter;
}
}
int main()
{
SampleType::Pointer sample = SampleType::New();
MeasurementVectorType mv;
for (unsigned int i = 5; i > 0; --i )
{
for (unsigned int j = 0; j < 2; ++j)
{
mv[j] = ( MeasurementType ) i;
}
for (unsigned int j = 0; j < i; ++j)
{
sample->PushBack(mv);
}
}
SubsampleType::Pointer subsample = SubsampleType::New();
subsample->SetSample(sample);
initializeSubsample(subsample, sample);
printSubsample(subsample, "Unsorted");
int activeDimension = 0;
itk::Statistics::Algorithm::InsertSort< SubsampleType >( subsample,
activeDimension, 0, subsample->Size() );
printSubsample(subsample, "InsertSort");
initializeSubsample(subsample, sample);
itk::Statistics::Algorithm::HeapSort< SubsampleType >( subsample,
activeDimension, 0, subsample->Size() );
printSubsample(subsample, "HeapSort");
initializeSubsample(subsample, sample);
itk::Statistics::Algorithm::IntrospectiveSort< SubsampleType >
( subsample, activeDimension, 0, subsample->Size(), 16 );
printSubsample(subsample, "IntrospectiveSort");
initializeSubsample(subsample, sample);
SubsampleType::MeasurementType median =
itk::Statistics::Algorithm::QuickSelect< SubsampleType >( subsample,
activeDimension,
0, subsample->Size(),
subsample->Size()/2 );
std::cout << std::endl;
std::cout << "Quick Select: median = " << median << std::endl;
return EXIT_SUCCESS;
}