ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Numerics/Statistics/SpatialSearch/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "itkVector.h"
#include "itkListSample.h"
int
main()
{
using MeasurementVectorType = itk::Vector<float, 2>;
auto 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);
}
auto treeGenerator = TreeGeneratorType::New();
treeGenerator->SetSample(sample);
treeGenerator->SetBucketSize(16);
treeGenerator->Update();
using TreeType = TreeGeneratorType::KdTreeType;
TreeType::Pointer tree = treeGenerator->GetOutput();
MeasurementVectorType queryPoint;
queryPoint[0] = 10.0;
queryPoint[1] = 7.0;
// K-Neighbor search
std::cout << "K-Neighbor search:" << std::endl;
unsigned int numberOfNeighbors = 3;
TreeType::InstanceIdentifierVectorType neighbors;
tree->Search(queryPoint, numberOfNeighbors, neighbors);
for (unsigned long neighbor : neighbors)
{
std::cout << tree->GetMeasurementVector(neighbor) << std::endl;
}
// Radius search
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 long neighbor : neighbors)
{
std::cout << tree->GetMeasurementVector(neighbor) << std::endl;
}
return EXIT_SUCCESS;
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itkListSample.h
itkVector.h
New
static Pointer New()
itk::Statistics::KdTreeGenerator
This class generates a KdTree object without centroid information.
Definition: itkKdTreeGenerator.h:71
itkEuclideanDistanceMetric.h
itkWeightedCentroidKdTreeGenerator.h