T
- type of values stored in the tree.public class KDTree<T> extends Object implements EuclideanSpace, IterableRealInterval<T>
Modifier and Type | Class and Description |
---|---|
static class |
KDTree.DimComparator<L extends RealLocalizable>
Compare RealLocalizables by comparing their coordinates in dimension d.
|
class |
KDTree.KDTreeCursor |
protected static class |
KDTree.SamplerNode<T>
A KDTreeNode that stores it's value as a Sampler.
|
protected static class |
KDTree.ValueNode<T>
A KDTreeNode that stores it's value as a reference.
|
Modifier and Type | Field and Description |
---|---|
protected double[] |
max
maximum of each dimension.
|
protected double[] |
min
minimum of each dimension.
|
protected int |
n
the number of dimensions.
|
protected KDTreeNode<T> |
root |
protected long |
size
the number of nodes in the tree.
|
Constructor and Description |
---|
KDTree(IterableRealInterval<T> interval)
Construct a KDTree from the elements of the given
IterableRealInterval . |
KDTree(List<T> values,
List<L> positions)
Construct a KDTree from the elements in the given list.
|
Modifier and Type | Method and Description |
---|---|
KDTree.KDTreeCursor |
cursor()
Returns a
RealCursor that iterates with optimal speed without
calculating the location at each iteration step. |
T |
firstElement()
Get the first element of this
IterableRealInterval . |
KDTreeNode<T> |
getRoot()
Get the root node.
|
Object |
iterationOrder()
Returns the iteration order of this
IterableRealInterval . |
KDTree.KDTreeCursor |
iterator() |
KDTree.KDTreeCursor |
localizingCursor()
Returns a
RealLocalizable Iterator that calculates its
location at each iteration step. |
protected <L extends RealLocalizable> |
makeNode(List<L> elements,
int i,
int j,
int d)
|
protected <L extends RealLocalizable> |
makeNode(List<L> positions,
int i,
int j,
int d,
List<T> values,
int[] permutation)
Construct the tree by recursively adding nodes.
|
protected <L extends RealLocalizable> |
makeNode(ListIterator<L> first,
ListIterator<L> last,
int d)
|
protected <L extends RealLocalizable> |
makeNode(ListIterator<L> first,
ListIterator<L> last,
int d,
List<T> values,
int[] permutation)
Construct the tree by recursively adding nodes.
|
protected KDTree.SamplerNode<T> |
makeSamplerNode(List<RealCursor<T>> elements,
int i,
int j,
int d)
Construct the tree by recursively adding nodes.
|
int |
numDimensions()
Gets the space's number of dimensions.
|
void |
realMax(double[] m)
Write the maximum of each dimension into double[].
|
double |
realMax(int d)
Get the maximum in dimension d.
|
void |
realMax(RealPositionable m)
Sets a
RealPositionable to the maximum of this Interval |
void |
realMin(double[] m)
Write the minimum of each dimension into double[].
|
double |
realMin(int d)
Get the minimum in dimension d.
|
void |
realMin(RealPositionable m)
Sets a
RealPositionable to the minimum of this Interval |
long |
size()
Returns the number of elements in this
Function . |
String |
toString() |
String |
toString(KDTreeNode<T> left,
String indent) |
protected static <L extends RealLocalizable> |
verifyDimensions(List<L> positions,
int n)
Check whether all positions in the positions list have dimension n.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
maxAsDoubleArray, maxAsRealPoint, minAsDoubleArray, minAsRealPoint
forEach, spliterator
protected final int n
protected final KDTreeNode<T> root
protected final long size
protected final double[] min
protected final double[] max
public KDTree(List<T> values, List<L> positions)
Note that the constructor can be called with the same list for both
values == positions
if T extends RealLocalizable
.
values
- a list of valuespositions
- a list of positions corresponding to the valuespublic KDTree(IterableRealInterval<T> interval)
IterableRealInterval
.interval
- elements in the tree are obtained by iterating thisprotected static <L extends RealLocalizable> boolean verifyDimensions(List<L> positions, int n)
protected <L extends RealLocalizable> KDTree.ValueNode<T> makeNode(List<L> positions, int i, int j, int d, List<T> values, int[] permutation)
positions
- list of positionsi
- start index of sublist to processj
- end index of sublist to processd
- dimension along which to split the sublistvalues
- list of values corresponding to permuted positionspermutation
- the index of the values element at index k is permutation[k]protected <L extends RealLocalizable> KDTree.ValueNode<T> makeNode(ListIterator<L> first, ListIterator<L> last, int d, List<T> values, int[] permutation)
first
- first element of the sublist of positionslast
- last element of the sublist of positionsd
- dimension along which to split the sublistvalues
- list of values corresponding to permuted positionspermutation
- the index of the values element at index k is permutation[k]protected <L extends RealLocalizable> KDTree.ValueNode<T> makeNode(List<L> elements, int i, int j, int d)
makeNode(List, int, int, int, List, int[])
. Here, no values are
attached to the nodes (or rather the positions are the values).elements
- list of elements (positions and values at the same time)i
- start index of sublist to processj
- end index of sublist to processd
- dimension along which to split the sublistprotected <L extends RealLocalizable> KDTree.ValueNode<T> makeNode(ListIterator<L> first, ListIterator<L> last, int d)
makeNode(ListIterator, ListIterator, int, List, int[])
. Here, no
values are attached to the nodes (or rather the positions are the
values).first
- first element of the sublist to processlast
- last element of the sublist to processd
- dimension along which to split the sublistprotected KDTree.SamplerNode<T> makeSamplerNode(List<RealCursor<T>> elements, int i, int j, int d)
elements
- list of elements (positions and values at the same time)i
- start index of sublist to processj
- end index of sublist to processd
- dimension along which to split the sublistpublic KDTreeNode<T> getRoot()
public int numDimensions()
EuclideanSpace
numDimensions
in interface EuclideanSpace
public String toString(KDTreeNode<T> left, String indent)
public double realMin(int d)
RealInterval
realMin
in interface RealInterval
d
- dimensionpublic void realMin(double[] m)
RealInterval
realMin
in interface RealInterval
public void realMin(RealPositionable m)
RealInterval
RealPositionable
to the minimum of this Interval
realMin
in interface RealInterval
public double realMax(int d)
RealInterval
realMax
in interface RealInterval
d
- dimensionpublic void realMax(double[] m)
RealInterval
realMax
in interface RealInterval
public void realMax(RealPositionable m)
RealInterval
RealPositionable
to the maximum of this Interval
realMax
in interface RealInterval
public long size()
IterableRealInterval
Returns the number of elements in this Function
.
size
in interface IterableRealInterval<T>
public Object iterationOrder()
IterableRealInterval
IterableRealInterval
. If the
returned object equals (Object.equals(Object)
) the iteration
order of another IterableRealInterval
f then they can be
copied by synchronous iteration. That is, having an Iterator
on
this and another Iterator
on f, moving both in synchrony
will point both of them to corresponding locations in their source
domain. In other words, this and f have the same iteration order
and means and the same number of elements.iterationOrder
in interface IterableRealInterval<T>
IterableRealInterval
.FlatIterationOrder
public KDTree.KDTreeCursor iterator()
public KDTree.KDTreeCursor cursor()
IterableRealInterval
Returns a RealCursor
that iterates with optimal speed without
calculating the location at each iteration step. Localization is
performed on demand.
Use this where localization is required rarely/ not for each iteration.
cursor
in interface IterableRealInterval<T>
public KDTree.KDTreeCursor localizingCursor()
IterableRealInterval
Returns a RealLocalizable
Iterator
that calculates its
location at each iteration step. That is, localization is performed with
optimal speed.
Use this where localization is required often/ for each iteration.
localizingCursor
in interface IterableRealInterval<T>
public T firstElement()
IterableRealInterval
IterableRealInterval
. This is a
shortcut for cursor().next()
.
This can be used to create a new variable of type T using
firstElement().createVariable()
, which is useful in generic
methods to store temporary results, e.g., a running sum over pixels in
the IterableRealInterval
.firstElement
in interface IterableRealInterval<T>
Copyright © 2015–2022 ImgLib2. All rights reserved.