ITK  5.2.0
Insight Toolkit
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
itk::Statistics::KdTree< TSample > Class Template Reference

#include <itkKdTree.h>

+ Inheritance diagram for itk::Statistics::KdTree< TSample >:
+ Collaboration diagram for itk::Statistics::KdTree< TSample >:

Classes

class  NearestNeighbors
 

Public Types

using AbsoluteFrequencyType = typename TSample::AbsoluteFrequencyType
 
using ConstPointer = SmartPointer< const Self >
 
using DistanceMetricType = EuclideanDistanceMetric< MeasurementVectorType >
 
using InstanceIdentifier = typename TSample::InstanceIdentifier
 
using InstanceIdentifierVectorType = std::vector< InstanceIdentifier >
 
using KdTreeNodeType = KdTreeNode< TSample >
 
using MeasurementType = typename TSample::MeasurementType
 
using MeasurementVectorSizeType = unsigned int
 
using MeasurementVectorType = typename TSample::MeasurementVectorType
 
using NeighborType = std::pair< InstanceIdentifier, double >
 
using Pointer = SmartPointer< Self >
 
using SampleType = TSample
 
using Self = KdTree
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

Public Member Functions

virtual ::itk::LightObject::Pointer CreateAnother () const
 
KdTreeNodeTypeGetEmptyTerminalNode ()
 
virtual MeasurementVectorSizeType GetMeasurementVectorSize () const
 
virtual const char * GetNameOfClass () const
 
const TSample * GetSample () const
 
void SetBucketSize (unsigned int)
 
void SetSample (const TSample *)
 
SizeValueType Size () const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *)
 
unsigned long AddObserver (const EventObject &event, Command *) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag)
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 

Static Public Member Functions

static Pointer New ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 
using Iterator = typename TSample::Iterator
 
using ConstIterator = typename TSample::ConstIterator
 
const TSample * m_Sample
 
int m_BucketSize
 
KdTreeNodeTypem_Root
 
KdTreeNodeTypem_EmptyTerminalNode
 
DistanceMetricType::Pointer m_DistanceMetric
 
MeasurementVectorSizeType m_MeasurementVectorSize
 
void SetRoot (KdTreeNodeType *root)
 
KdTreeNodeTypeGetRoot ()
 
const MeasurementVectorTypeGetMeasurementVector (InstanceIdentifier id) const
 
AbsoluteFrequencyType GetFrequency (InstanceIdentifier id) const
 
DistanceMetricTypeGetDistanceMetric ()
 
void Search (const MeasurementVectorType &, unsigned int, InstanceIdentifierVectorType &) const
 
void Search (const MeasurementVectorType &, unsigned int, InstanceIdentifierVectorType &, std::vector< double > &) const
 
void Search (const MeasurementVectorType &, double, InstanceIdentifierVectorType &) const
 
bool BallWithinBounds (const MeasurementVectorType &, MeasurementVectorType &, MeasurementVectorType &, double) const
 
bool BoundsOverlapBall (const MeasurementVectorType &, MeasurementVectorType &, MeasurementVectorType &, double) const
 
void DeleteNode (KdTreeNodeType *)
 
void PrintTree (std::ostream &) const
 
void PrintTree (KdTreeNodeType *, unsigned int, unsigned int, std::ostream &os=std::cout) const
 
void PlotTree (std::ostream &os) const
 
void PlotTree (KdTreeNodeType *node, std::ostream &os=std::cout) const
 
 KdTree ()
 
 ~KdTree () override
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
int NearestNeighborSearchLoop (const KdTreeNodeType *, const MeasurementVectorType &, MeasurementVectorType &, MeasurementVectorType &, NearestNeighbors &) const
 
int SearchLoop (const KdTreeNodeType *, const MeasurementVectorType &, double, MeasurementVectorType &, MeasurementVectorType &, InstanceIdentifierVectorType &) const
 

Additional Inherited Members

- Protected Member Functions inherited from itk::Object
 Object ()
 
 ~Object () override
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 
- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount
 

Detailed Description

template<typename TSample>
class itk::Statistics::KdTree< TSample >

This class provides methods for k-nearest neighbor search and related data structures for a k-d tree.

An object of this class stores instance identifiers in a k-d tree that is a binary tree with childrens split along a dimension among k-dimensions. The dimension of the split (or partition) is determined for each nonterminal node that has two children. The split process is terminated when the node has no children (when the number of measurement vectors is less than or equal to the size set by the SetBucketSize. That is The split process is a recursive process in nature and in implementation. This implementation doesn't support dynamic insert and delete operations for the tree. Instead, we can use the KdTreeGenerator or WeightedCentroidKdTreeGenerator to generate a static KdTree object.

To search k-nearest neighbor, call the Search method with the query point in a k-d space and the number of nearest neighbors. The GetSearchResult method returns a pointer to a NearestNeighbors object with k-nearest neighbors.

Recent API changes: The static const macro to get the length of a measurement vector, 'MeasurementVectorSize' has been removed to allow the length of a measurement vector to be specified at run time. Please use the function GetMeasurementVectorSize() instead.

See also
KdTreeNode, KdTreeNonterminalNode, KdTreeWeightedCentroidNonterminalNode, KdTreeTerminalNode, KdTreeGenerator, WeightedCentroidKdTreeNode

Definition at line 527 of file itkKdTree.h.

Member Typedef Documentation

◆ AbsoluteFrequencyType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::AbsoluteFrequencyType = typename TSample::AbsoluteFrequencyType

Definition at line 549 of file itkKdTree.h.

◆ ConstIterator

template<typename TSample >
using itk::Statistics::KdTree< TSample >::ConstIterator = typename TSample::ConstIterator

Pointer to the input sample

Definition at line 789 of file itkKdTree.h.

◆ ConstPointer

template<typename TSample >
using itk::Statistics::KdTree< TSample >::ConstPointer = SmartPointer<const Self>

Definition at line 536 of file itkKdTree.h.

◆ DistanceMetricType

DistanceMetric type for the distance calculation and comparison

Definition at line 558 of file itkKdTree.h.

◆ InstanceIdentifier

template<typename TSample >
using itk::Statistics::KdTree< TSample >::InstanceIdentifier = typename TSample::InstanceIdentifier

Definition at line 548 of file itkKdTree.h.

◆ InstanceIdentifierVectorType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::InstanceIdentifierVectorType = std::vector<InstanceIdentifier>

Definition at line 568 of file itkKdTree.h.

◆ Iterator

template<typename TSample >
using itk::Statistics::KdTree< TSample >::Iterator = typename TSample::Iterator

Pointer to the input sample

Definition at line 788 of file itkKdTree.h.

◆ KdTreeNodeType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::KdTreeNodeType = KdTreeNode<TSample>

Node type of the KdTree

Definition at line 561 of file itkKdTree.h.

◆ MeasurementType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::MeasurementType = typename TSample::MeasurementType

Definition at line 547 of file itkKdTree.h.

◆ MeasurementVectorSizeType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::MeasurementVectorSizeType = unsigned int

Definition at line 551 of file itkKdTree.h.

◆ MeasurementVectorType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::MeasurementVectorType = typename TSample::MeasurementVectorType

Definition at line 546 of file itkKdTree.h.

◆ NeighborType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::NeighborType = std::pair<InstanceIdentifier, double>

Neighbor type. The first element of the std::pair is the instance identifier and the second one is the distance between the measurement vector identified by the first element and the query point.

Definition at line 566 of file itkKdTree.h.

◆ Pointer

template<typename TSample >
using itk::Statistics::KdTree< TSample >::Pointer = SmartPointer<Self>

Definition at line 535 of file itkKdTree.h.

◆ SampleType

template<typename TSample >
using itk::Statistics::KdTree< TSample >::SampleType = TSample

type alias alias for the source data container

Definition at line 545 of file itkKdTree.h.

◆ Self

template<typename TSample >
using itk::Statistics::KdTree< TSample >::Self = KdTree

Standard class type aliases

Definition at line 533 of file itkKdTree.h.

◆ Superclass

template<typename TSample >
using itk::Statistics::KdTree< TSample >::Superclass = Object

Definition at line 534 of file itkKdTree.h.

Constructor & Destructor Documentation

◆ KdTree()

template<typename TSample >
itk::Statistics::KdTree< TSample >::KdTree ( )
protected

Constructor

◆ ~KdTree()

template<typename TSample >
itk::Statistics::KdTree< TSample >::~KdTree ( )
overrideprotected

Destructor: deletes the root node and the empty terminal node.

Member Function Documentation

◆ BallWithinBounds()

template<typename TSample >
bool itk::Statistics::KdTree< TSample >::BallWithinBounds ( const MeasurementVectorType ,
MeasurementVectorType ,
MeasurementVectorType ,
double   
) const

Returns true if the intermediate k-nearest neighbors exist within the the bounding box defined by the lowerBound and the upperBound. Otherwise returns false. Returns false if the ball defined by the distance between the query point and the farthest neighbor touch the surface of the bounding box.

◆ BoundsOverlapBall()

template<typename TSample >
bool itk::Statistics::KdTree< TSample >::BoundsOverlapBall ( const MeasurementVectorType ,
MeasurementVectorType ,
MeasurementVectorType ,
double   
) const

Returns true if the ball defined by the distance between the query point and the farthest neighbor overlaps with the bounding box defined by the lower and the upper bounds.

◆ CreateAnother()

template<typename TSample >
virtual::itk::LightObject::Pointer itk::Statistics::KdTree< TSample >::CreateAnother ( ) const
virtual

Create an object from an instance, potentially deferring to a factory. This method allows you to create an instance of an object that is exactly the same type as the referring object. This is useful in cases where an object has been cast back to a base class.

Reimplemented from itk::Object.

◆ DeleteNode()

template<typename TSample >
void itk::Statistics::KdTree< TSample >::DeleteNode ( KdTreeNodeType )

Deletes the node recursively

◆ GetDistanceMetric()

template<typename TSample >
DistanceMetricType* itk::Statistics::KdTree< TSample >::GetDistanceMetric ( )
inline

Get the pointer to the distance metric.

Definition at line 734 of file itkKdTree.h.

◆ GetEmptyTerminalNode()

template<typename TSample >
KdTreeNodeType* itk::Statistics::KdTree< TSample >::GetEmptyTerminalNode ( )
inline

Returns the pointer to the empty terminal node. A KdTree object has a single empty terminal node in memory. when the split process has to create an empty terminal node, the single instance is reused for this case

Definition at line 691 of file itkKdTree.h.

◆ GetFrequency()

template<typename TSample >
AbsoluteFrequencyType itk::Statistics::KdTree< TSample >::GetFrequency ( InstanceIdentifier  id) const
inline

Returns the frequency of the measurement vector identified by the instance identifier

Definition at line 727 of file itkKdTree.h.

◆ GetMeasurementVector()

template<typename TSample >
const MeasurementVectorType& itk::Statistics::KdTree< TSample >::GetMeasurementVector ( InstanceIdentifier  id) const
inline

Returns the measurement vector identified by the instance identifier that is an identifier defiend for the input sample

Definition at line 719 of file itkKdTree.h.

◆ GetMeasurementVectorSize()

template<typename TSample >
virtual MeasurementVectorSizeType itk::Statistics::KdTree< TSample >::GetMeasurementVectorSize ( ) const
virtual

Get Macro to get the length of a measurement vector in the KdTree. The length is obtained from the input sample.

◆ GetNameOfClass()

template<typename TSample >
virtual const char* itk::Statistics::KdTree< TSample >::GetNameOfClass ( ) const
virtual

Run-time type information (and related methods)

Reimplemented from itk::Object.

◆ GetRoot()

template<typename TSample >
KdTreeNodeType* itk::Statistics::KdTree< TSample >::GetRoot ( )
inline

Returns the pointer to the root node.

Definition at line 711 of file itkKdTree.h.

◆ GetSample()

template<typename TSample >
const TSample* itk::Statistics::KdTree< TSample >::GetSample ( ) const
inline

Returns the pointer to the input sample

Definition at line 675 of file itkKdTree.h.

◆ NearestNeighborSearchLoop()

template<typename TSample >
int itk::Statistics::KdTree< TSample >::NearestNeighborSearchLoop ( const KdTreeNodeType ,
const MeasurementVectorType ,
MeasurementVectorType ,
MeasurementVectorType ,
NearestNeighbors  
) const
protected

search loop

◆ New()

template<typename TSample >
static Pointer itk::Statistics::KdTree< TSample >::New ( )
static

Method for creation through the object factory.

◆ PlotTree() [1/2]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::PlotTree ( KdTreeNodeType node,
std::ostream &  os = std::cout 
) const

Prints out the tree information

◆ PlotTree() [2/2]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::PlotTree ( std::ostream &  os) const

Draw out the tree information to a ostream using the format of the Graphviz dot tool.

◆ PrintSelf()

template<typename TSample >
void itk::Statistics::KdTree< TSample >::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

Pointer to the input sample

Reimplemented from itk::Object.

◆ PrintTree() [1/2]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::PrintTree ( KdTreeNodeType ,
unsigned int  ,
unsigned int  ,
std::ostream &  os = std::cout 
) const

Prints out the tree information

◆ PrintTree() [2/2]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::PrintTree ( std::ostream &  ) const

Prints out the tree information

◆ Search() [1/3]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::Search ( const MeasurementVectorType ,
double  ,
InstanceIdentifierVectorType  
) const

Searches the neighbors fallen into a hypersphere

◆ Search() [2/3]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::Search ( const MeasurementVectorType ,
unsigned int  ,
InstanceIdentifierVectorType  
) const

Searches the k-nearest neighbors

◆ Search() [3/3]

template<typename TSample >
void itk::Statistics::KdTree< TSample >::Search ( const MeasurementVectorType ,
unsigned int  ,
InstanceIdentifierVectorType ,
std::vector< double > &   
) const

Searches the k-nearest neighbors and returns the distance vector along with the distance measures.

◆ SearchLoop()

template<typename TSample >
int itk::Statistics::KdTree< TSample >::SearchLoop ( const KdTreeNodeType ,
const MeasurementVectorType ,
double  ,
MeasurementVectorType ,
MeasurementVectorType ,
InstanceIdentifierVectorType  
) const
protected

search loop

◆ SetBucketSize()

template<typename TSample >
void itk::Statistics::KdTree< TSample >::SetBucketSize ( unsigned int  )

Sets the number of measurement vectors that can be stored in a terminal node

◆ SetRoot()

template<typename TSample >
void itk::Statistics::KdTree< TSample >::SetRoot ( KdTreeNodeType root)
inline

Sets the root node of the KdTree that is a result of KdTreeGenerator or WeightedCentroidKdTreeGenerator.

Definition at line 699 of file itkKdTree.h.

◆ SetSample()

template<typename TSample >
void itk::Statistics::KdTree< TSample >::SetSample ( const TSample *  )

Sets the input sample that provides the measurement vectors to the k-d tree

◆ Size()

template<typename TSample >
SizeValueType itk::Statistics::KdTree< TSample >::Size ( ) const
inline

Definition at line 681 of file itkKdTree.h.

Member Data Documentation

◆ m_BucketSize

template<typename TSample >
int itk::Statistics::KdTree< TSample >::m_BucketSize
private

Number of measurement vectors can be stored in a terminal node.

Definition at line 823 of file itkKdTree.h.

◆ m_DistanceMetric

template<typename TSample >
DistanceMetricType::Pointer itk::Statistics::KdTree< TSample >::m_DistanceMetric
private

Distance metric smart pointer

Definition at line 832 of file itkKdTree.h.

◆ m_EmptyTerminalNode

template<typename TSample >
KdTreeNodeType* itk::Statistics::KdTree< TSample >::m_EmptyTerminalNode
private

Pointer to the empty terminal node

Definition at line 829 of file itkKdTree.h.

◆ m_MeasurementVectorSize

template<typename TSample >
MeasurementVectorSizeType itk::Statistics::KdTree< TSample >::m_MeasurementVectorSize
private

Measurement vector size

Definition at line 835 of file itkKdTree.h.

◆ m_Root

template<typename TSample >
KdTreeNodeType* itk::Statistics::KdTree< TSample >::m_Root
private

Pointer to the root node

Definition at line 826 of file itkKdTree.h.

◆ m_Sample

template<typename TSample >
const TSample* itk::Statistics::KdTree< TSample >::m_Sample
private

Pointer to the input sample

Definition at line 820 of file itkKdTree.h.


The documentation for this class was generated from the following file: