int main(int, char *[])
{
SampleType::Pointer sample = SampleType::New();
sample->SetMeasurementVectorSize( 2 );
MeasurementVectorType mv;
for (unsigned int i = 0 ; i < 100 ; ++i )
{
mv[0] = static_cast<float>(i);
mv[1] = static_cast<float>(i);
sample->PushBack( mv );
}
TreeGeneratorType::Pointer treeGenerator = TreeGeneratorType::New();
treeGenerator->SetSample( sample );
treeGenerator->SetBucketSize( 16 );
treeGenerator->Update();
typedef TreeGeneratorType::KdTreeType TreeType;
typedef TreeType::NearestNeighbors NeighborsType;
typedef TreeType::KdTreeNodeType NodeType;
TreeType::Pointer tree = treeGenerator->GetOutput();
MeasurementVectorType queryPoint;
queryPoint[0] = 10.0;
queryPoint[1] = 7.0;
std::cout << "K-Neighbor search:" << std::endl;
unsigned int numberOfNeighbors = 3;
TreeType::InstanceIdentifierVectorType neighbors;
tree->Search( queryPoint, numberOfNeighbors, neighbors ) ;
for ( unsigned int i = 0 ; i < neighbors.size() ; ++i )
{
std::cout << tree->GetMeasurementVector( neighbors[i] ) << std::endl;
}
std::cout << "Radius search:" << std::endl;
double radius = 4.0;
tree->Search( queryPoint, radius, neighbors ) ;
std::cout << "There are " << neighbors.size() << " neighbors." << std::endl;
for ( unsigned int i = 0 ; i < neighbors.size() ; ++i )
{
std::cout << tree->GetMeasurementVector( neighbors[i] ) << std::endl;
}
return EXIT_SUCCESS;
}