using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KDTree
{
///
/// A KDTree class represents the root of a variable-dimension KD-Tree.
///
/// The generic data type we want this tree to contain.
/// This is based on this: https://bitbucket.org/rednaxela/knn-benchmark/src/tip/ags/utils/dataStructures/trees/thirdGenKD/
public class KDTree : KDNode
{
///
/// Create a new KD-Tree given a number of dimensions.
///
/// The number of data sorting dimensions. i.e. 3 for a 3D point.
public KDTree(int iDimensions)
: base(iDimensions, 24)
{
}
///
/// Create a new KD-Tree given a number of dimensions and initial bucket capacity.
///
/// The number of data sorting dimensions. i.e. 3 for a 3D point.
/// The default number of items that can be stored in each node.
public KDTree(int iDimensions, int iBucketCapacity)
: base(iDimensions, iBucketCapacity)
{
}
///
/// Get the nearest neighbours to a point in the kd tree using a square euclidean distance function.
///
/// The point of interest.
/// The maximum number of points which can be returned by the iterator.
/// A threshold distance to apply. Optional. Negative values mean that it is not applied.
/// A new nearest neighbour iterator with the given parameters.
public NearestNeighbour NearestNeighbors(double[] tSearchPoint, int iMaxReturned, double fDistance = -1)
{
DistanceFunctions distanceFunction = new SquareEuclideanDistanceFunction();
return NearestNeighbors(tSearchPoint, distanceFunction, iMaxReturned, fDistance);
}
///
/// Get the nearest neighbours to a point in the kd tree using a user defined distance function.
///
/// The point of interest.
/// The maximum number of points which can be returned by the iterator.
/// The distance function to use.
/// A threshold distance to apply. Optional. Negative values mean that it is not applied.
/// A new nearest neighbour iterator with the given parameters.
public NearestNeighbour NearestNeighbors(double[] tSearchPoint, DistanceFunctions kDistanceFunction, int iMaxReturned, double fDistance)
{
return new NearestNeighbour(this, tSearchPoint, kDistanceFunction, iMaxReturned, fDistance);
}
}
}