public class IncrementalDoubleKDTree extends Object
double[]
s. Includes
support for range search, neighbour search, and radius search. The tree created
by this class will usually be rather unbalanced.
The KDTree allows fast search for points in relatively low-dimension spaces.
Constructor and Description |
---|
IncrementalDoubleKDTree()
Create an empty KDTree object
|
IncrementalDoubleKDTree(Collection<double[]> coords)
Create a KDTree object and populate it with the given data.
|
IncrementalDoubleKDTree(double[][] coords)
Create a KDTree object and populate it with the given data.
|
Modifier and Type | Method and Description |
---|---|
protected static double |
distance(double[] a,
double[] b) |
ObjectDoublePair<double[]> |
findNearestNeighbour(double[] query)
Find the nearest neighbour.
|
List<ObjectDoublePair<double[]>> |
findNearestNeighbours(double[] query,
int k)
Find the K nearest neighbours.
|
void |
insert(double[] point)
Inserts a point into the tree, preserving the spatial ordering.
|
void |
insertAll(Collection<double[]> coords)
Insert all the points from the given collection into the index.
|
void |
insertAll(double[][] coords)
Insert all the points from the given collection into the index.
|
List<ObjectDoublePair<double[]>> |
radiusDistanceSearch(double[] centre,
double radius)
Find all the points within the given radius of the given point.
|
List<double[]> |
radiusSearch(double[] centre,
double radius)
Find all the points within the given radius of the given point
|
List<double[]> |
rangeSearch(double[] lowerExtreme,
double[] upperExtreme)
Searches the tree for all points contained within the bounding box
defined by the given upper and lower extremes
|
public IncrementalDoubleKDTree()
public IncrementalDoubleKDTree(Collection<double[]> coords)
coords
- the data to populate the index with.public IncrementalDoubleKDTree(double[][] coords)
coords
- the data to populate the index with.public void insertAll(Collection<double[]> coords)
coords
- The points to add.public void insertAll(double[][] coords)
coords
- The points to add.public void insert(double[] point)
point
- Point to insert.public List<double[]> rangeSearch(double[] lowerExtreme, double[] upperExtreme)
lowerExtreme
- upperExtreme
- protected static final double distance(double[] a, double[] b)
public ObjectDoublePair<double[]> findNearestNeighbour(double[] query)
query
- query coordinatepublic List<ObjectDoublePair<double[]>> findNearestNeighbours(double[] query, int k)
query
- query coordinatek
- the number of neighbours to findpublic List<double[]> radiusSearch(double[] centre, double radius)
centre
- the centre pointradius
- the radiuspublic List<ObjectDoublePair<double[]>> radiusDistanceSearch(double[] centre, double radius)
centre
- the centre pointradius
- the radius