62 template<
typename TSample>
81 virtual bool IsTerminal()
const = 0;
88 virtual void GetParameters(
unsigned int &,
MeasurementType & )
const = 0;
91 virtual Self * Left() = 0;
94 virtual const Self * Left()
const = 0;
97 virtual Self * Right() = 0;
100 virtual const Self * Right()
const = 0;
106 virtual unsigned int Size()
const = 0;
136 template<
typename TSample>
155 void GetParameters(
unsigned int &, MeasurementType & )
const;
209 return this->m_InstanceIdentifier;
217 this->m_InstanceIdentifier = valueId;
244 template<
typename TSample>
265 void GetParameters(
unsigned int &, MeasurementType & )
const;
270 return m_MeasurementVectorSize;
308 centroid = m_WeightedCentroid;
316 centroid = m_Centroid;
326 return this->m_InstanceIdentifier;
334 this->m_InstanceIdentifier = valueId;
361 template<
typename TSample>
373 this->m_InstanceIdentifiers.clear();
412 return static_cast< unsigned int >( m_InstanceIdentifiers.size() );
434 return m_InstanceIdentifiers[index];
442 m_InstanceIdentifiers.push_back(
id );
482 template<
typename TSample>
538 NearestNeighbors( std::vector<double> & cache_vector) : m_FarthestNeighborIndex(0), m_Distances(cache_vector) {}
547 m_Identifiers.clear();
551 m_FarthestNeighborIndex = 0;
558 return m_Distances[m_FarthestNeighborIndex];
565 m_Identifiers[m_FarthestNeighborIndex] = id;
566 m_Distances[m_FarthestNeighborIndex] = distance;
568 const unsigned int size =
static_cast< unsigned int >( m_Distances.size() );
569 for (
unsigned int i = 0; i < size; i++ )
571 if ( m_Distances[i] > farthestDistance )
573 farthestDistance = m_Distances[i];
574 m_FarthestNeighborIndex = i;
583 return m_Identifiers;
590 return m_Identifiers[index];
596 unsigned int m_FarthestNeighborIndex;
604 std::vector<
double> & m_Distances;
609 void SetBucketSize(
unsigned int );
613 void SetSample( const TSample * );
616 const TSample * GetSample()
const
623 return m_Sample->Size();
632 return m_EmptyTerminalNode;
641 this->DeleteNode( this->m_Root );
658 return m_Sample->GetMeasurementVector(
id );
665 return m_Sample->GetFrequency(
id );
671 return m_DistanceMetric.GetPointer();
675 void Search(
const MeasurementVectorType &,
unsigned int,
676 InstanceIdentifierVectorType & )
const;
681 void Search(
const MeasurementVectorType &,
unsigned int,
682 InstanceIdentifierVectorType &, std::vector<double> & )
const;
685 void Search(
const MeasurementVectorType &,
double,
686 InstanceIdentifierVectorType & )
const;
693 bool BallWithinBounds(
const MeasurementVectorType &,
694 MeasurementVectorType &, MeasurementVectorType &,
double )
const;
699 bool BoundsOverlapBall(
const MeasurementVectorType &,
700 MeasurementVectorType &, MeasurementVectorType &,
double)
const;
703 void DeleteNode( KdTreeNodeType * );
706 void PrintTree( std::ostream & )
const;
709 void PrintTree( KdTreeNodeType *,
unsigned int,
unsigned int,
710 std::ostream & os = std::cout )
const;
714 void PlotTree( std::ostream & os )
const;
717 void PlotTree( KdTreeNodeType *node, std::ostream & os = std::cout )
const;
727 virtual ~
KdTree() ITK_OVERRIDE;
729 virtual
void PrintSelf( std::ostream & os,
Indent indent ) const ITK_OVERRIDE;
737 int SearchLoop( const KdTreeNodeType *, const MeasurementVectorType &,
738 double, MeasurementVectorType &, MeasurementVectorType &,
745 const TSample *m_Sample;
751 KdTreeNodeType *m_Root;
754 KdTreeNodeType *m_EmptyTerminalNode;
765 #ifndef ITK_MANUAL_INSTANTIATION
766 #include "itkKdTree.hxx"
void GetWeightedCentroid(CentroidType &)
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const
void GetCentroid(CentroidType &)
KdTreeNode< TSample > Self
TSample::ConstIterator ConstIterator
Light weight base class for most itk classes.
InstanceIdentifier GetInstanceIdentifier(InstanceIdentifier index) const
KdTreeNodeType * GetEmptyTerminalNode()
Superclass::InstanceIdentifier InstanceIdentifier
const Superclass * Left() const
KdTreeNodeType * GetRoot()
This class defines the interface of its derived classes.
This is a subclass of the KdTreeNode.
const Superclass * Left() const
Represent the size (bounds) of a n-dimensional image.
virtual bool IsTerminal() const
void GetCentroid(CentroidType ¢roid)
void AddInstanceIdentifier(InstanceIdentifier valueId)
const Superclass * Right() const
virtual ~KdTreeTerminalNode()
TSample::MeasurementVectorType MeasurementVectorType
void ReplaceFarthestNeighbor(InstanceIdentifier id, double distance)
TSample::AbsoluteFrequencyType AbsoluteFrequencyType
void GetWeightedCentroid(CentroidType &)
TSample::InstanceIdentifier InstanceIdentifier
void GetWeightedCentroid(CentroidType ¢roid)
TSample::MeasurementType MeasurementType
MeasurementType m_PartitionValue
SizeValueType Size() const
EuclideanDistanceMetric< MeasurementVectorType > DistanceMetricType
Euclidean distance function.
InstanceIdentifier GetInstanceIdentifier(InstanceIdentifier) const
unsigned long SizeValueType
const Superclass * Left() const
Superclass::CentroidType CentroidType
KdTreeNode< TSample > KdTreeNodeType
void GetCentroid(CentroidType &)
InstanceIdentifier m_InstanceIdentifier
virtual bool IsTerminal() const
data structure for storing k-nearest neighbor search result (k number of Neighbors) ...
virtual ~KdTreeWeightedCentroidNonterminalNode()
This class is the node that doesn't have any child node. The IsTerminal method returns true for this ...
unsigned int Size() const
TSample::Iterator Iterator
unsigned int Size() const
MeasurementType m_PartitionValue
InstanceIdentifier m_InstanceIdentifier
const InstanceIdentifierVectorType & GetNeighbors() const
InstanceIdentifier GetInstanceIdentifier(InstanceIdentifier) const
DistanceMetricType * GetDistanceMetric()
void SetRoot(KdTreeNodeType *root)
void AddInstanceIdentifier(InstanceIdentifier id)
unsigned int Size() const
This is a subclass of the KdTreeNode.
Superclass::InstanceIdentifier InstanceIdentifier
MeasurementVectorSizeType GetMeasurementVectorSize() const
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const
double GetLargestDistance()
TSample::InstanceIdentifier InstanceIdentifier
const Superclass * Right() const
Array< double > CentroidType
std::pair< InstanceIdentifier, double > NeighborType
std::vector< InstanceIdentifier > InstanceIdentifierVectorType
Superclass::MeasurementType MeasurementType
InstanceIdentifier GetNeighbor(unsigned int index) const
Superclass::CentroidType CentroidType
unsigned int MeasurementVectorSizeType
const Superclass * Right() const
std::vector< InstanceIdentifier > m_InstanceIdentifiers
MeasurementVectorSizeType m_MeasurementVectorSize
static ITK_CONSTEXPR_FUNC T min(const T &)
KdTreeNode< TSample > Superclass
TSample::MeasurementVectorSizeType MeasurementVectorSizeType
void resize(unsigned int k)
void GetParameters(unsigned int &, MeasurementType &) const
Control indentation during Print() invocation.
unsigned int m_PartitionDimension
KdTreeNode< TSample > Superclass
Define additional traits for native types such as int or float.
void AddInstanceIdentifier(InstanceIdentifier valueId)
Base class for most ITK classes.
SmartPointer< Self > Pointer
KdTreeNode< TSample > Superclass
NearestNeighbors(std::vector< double > &cache_vector)
Superclass::MeasurementType MeasurementType
Superclass::MeasurementType MeasurementType
This class provides methods for k-nearest neighbor search and related data structures for a k-d tree...
Superclass::CentroidType CentroidType
Superclass::InstanceIdentifier InstanceIdentifier
SmartPointer< const Self > ConstPointer
unsigned int m_PartitionDimension
TSample::MeasurementType MeasurementType
virtual ~KdTreeNonterminalNode()
CentroidType m_WeightedCentroid