Class KDTree<T>
- java.lang.Object
-
- net.imglib2.KDTree<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>,EuclideanSpace,IterableRealInterval<T>,RealInterval,Typed<T>
public class KDTree<T> extends java.lang.Object implements EuclideanSpace, IterableRealInterval<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classKDTree.KDTreeCursor
-
Field Summary
Fields Modifier and Type Field Description (package private) KDTreeImplimplprivate static intMAX_ARRAY_SIZEprivate KDTreeData<T>treeData
-
Constructor Summary
Constructors Constructor Description KDTree(int numPoints, java.lang.Iterable<T> values, java.lang.Iterable<L> positions)KDTree(java.util.List<T> values, java.util.List<L> positions)Construct a KDTree from the elements in the given list.KDTree(IterableRealInterval<T> interval)Construct a KDTree from the elements of the givenIterableRealInterval.KDTree(KDTreeData<T> data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description KDTreeNode<T>createNode()Create a re-usableKDTreeNodeproxy linked to this tree.KDTree.KDTreeCursorcursor()Returns aRealCursorthat iterates with optimal speed without calculating the location at each iteration step.KDTreeNode<T>getRoot()Deprecated.KDTreeNodeis now a re-usable proxy (likeNativeType).TgetType()Get an instance ofT.KDTreeImplimpl()Access to pure coordinate kD Tree implementation.java.lang.ObjectiterationOrder()Returns the iteration order of thisIterableRealInterval.KDTree.KDTreeCursoriterator()(package private) KDTreeNode<T>left(KDTreeNode<T> parent)KDTree.KDTreeCursorlocalizingCursor()Returns aRealLocalizableIteratorthat calculates its location at each iteration step.intnumDimensions()Gets the space's number of dimensions.private static <A> java.lang.Iterable<RealLocalizable>positionsIterable(IterableRealInterval<A> sourceInterval)doublerealMax(int d)Get the maximum in dimension d.doublerealMin(int d)Get the minimum in dimension d.(package private) KDTreeNode<T>right(KDTreeNode<T> parent)longsize()Returns the number of elements in thisFunction.java.lang.StringtoString()private java.lang.StringtoString(int node, java.lang.String indent, KDTreeNode<T> ref)KDTreeData<T>treeData()Access to underlying data for serialization.private static intverifySize(java.util.List<?> values, java.util.List<?> positions)private static intverifySize(IterableRealInterval<?> interval)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.imglib2.IterableRealInterval
firstElement, localizingSpliterator, parallelStream, spliterator, stream
-
Methods inherited from interface net.imglib2.RealInterval
maxAsDoubleArray, maxAsRealPoint, minAsDoubleArray, minAsRealPoint, realMax, realMax, realMin, realMin
-
-
-
-
Field Detail
-
treeData
private final KDTreeData<T> treeData
-
impl
final KDTreeImpl impl
-
MAX_ARRAY_SIZE
private static final int MAX_ARRAY_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
KDTree
public KDTree(java.util.List<T> values, java.util.List<L> positions)
Construct a KDTree from the elements in the given list.Note that the constructor can be called with the same list for both
values == positionsifT extends RealLocalizable.- Parameters:
values- a list of valuespositions- a list of positions corresponding to the values
-
KDTree
public KDTree(IterableRealInterval<T> interval)
Construct a KDTree from the elements of the givenIterableRealInterval.- Parameters:
interval- elements in the tree are obtained by iterating this
-
KDTree
public KDTree(int numPoints, java.lang.Iterable<T> values, java.lang.Iterable<L> positions)
-
KDTree
public KDTree(KDTreeData<T> data)
-
-
Method Detail
-
treeData
public KDTreeData<T> treeData()
Access to underlying data for serialization.
-
impl
public KDTreeImpl impl()
Access to pure coordinate kD Tree implementation.
-
verifySize
private static int verifySize(java.util.List<?> values, java.util.List<?> positions)
-
verifySize
private static int verifySize(IterableRealInterval<?> interval)
-
positionsIterable
private static <A> java.lang.Iterable<RealLocalizable> positionsIterable(IterableRealInterval<A> sourceInterval)
-
getRoot
@Deprecated public KDTreeNode<T> getRoot()
Deprecated.KDTreeNodeis now a re-usable proxy (likeNativeType). To work with existing code,KDTreeNode.left(),KDTreeNode.right(),getRoot()etc create new objects in each call, instead of re-using existing proxies. Code using that should be rewritten to reuse proxies, if possible.Get the root node.- Returns:
- the root node.
-
getType
public T getType()
Description copied from interface:IterableRealIntervalGet an instance ofT.It should not be assumed that the returned
Tinstance is an independent copy. In particular, repeated calls togetType()may return the same instance.The default implementation returns
IterableRealInterval.firstElement(). Derived classes may choose different implementations for improved performance.
-
numDimensions
public int numDimensions()
Description copied from interface:EuclideanSpaceGets the space's number of dimensions.- Specified by:
numDimensionsin interfaceEuclideanSpace
-
realMin
public double realMin(int d)
Description copied from interface:RealIntervalGet the minimum in dimension d.- Specified by:
realMinin interfaceRealInterval- Parameters:
d- dimension- Returns:
- minimum in dimension d.
-
realMax
public double realMax(int d)
Description copied from interface:RealIntervalGet the maximum in dimension d.- Specified by:
realMaxin interfaceRealInterval- Parameters:
d- dimension- Returns:
- maximum in dimension d.
-
cursor
public KDTree.KDTreeCursor cursor()
Description copied from interface:IterableRealIntervalReturns a
RealCursorthat 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.
- Specified by:
cursorin interfaceIterableRealInterval<T>- Returns:
- fast iterating iterator
-
localizingCursor
public KDTree.KDTreeCursor localizingCursor()
Description copied from interface:IterableRealIntervalReturns a
RealLocalizableIteratorthat 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.
- Specified by:
localizingCursorin interfaceIterableRealInterval<T>- Returns:
- fast localizing iterator
-
iterator
public KDTree.KDTreeCursor iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<T>- Specified by:
iteratorin interfaceIterableRealInterval<T>
-
size
public long size()
Description copied from interface:IterableRealIntervalReturns the number of elements in this
Function.- Specified by:
sizein interfaceIterableRealInterval<T>- Returns:
- number of elements
-
iterationOrder
public java.lang.Object iterationOrder()
Description copied from interface:IterableRealIntervalReturns the iteration order of thisIterableRealInterval. If the returned object equals (Object.equals(Object)) the iteration order of anotherIterableRealIntervalf then they can be copied by synchronous iteration. That is, having anIteratoron this and anotherIteratoron 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.- Specified by:
iterationOrderin interfaceIterableRealInterval<T>- Returns:
- the iteration order of this
IterableRealInterval. - See Also:
FlatIterationOrder
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
private java.lang.String toString(int node, java.lang.String indent, KDTreeNode<T> ref)
-
createNode
public KDTreeNode<T> createNode()
Create a re-usableKDTreeNodeproxy linked to this tree.KDTreeNode.setNodeIndex(int)can be used to point the proxy to a particular node in the tree.
-
left
KDTreeNode<T> left(KDTreeNode<T> parent)
-
right
KDTreeNode<T> right(KDTreeNode<T> parent)
-
-