Package net.imglib2.kdtree
Class KDTreeUtils.MakeTree
- java.lang.Object
-
- net.imglib2.kdtree.KDTreeUtils.MakeTree
-
- Enclosing class:
- KDTreeUtils
private static final class KDTreeUtils.MakeTree extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private int[]indicesTemporary array to keep track of elements.private intnumDimensionsprivate intnumPointsprivate double[][]positionsThe coordinates for theith point are stored atpositions[d][k]wheredis the dimension.private int[]treeNode indices in a flattened (heap-like) array.
-
Constructor Summary
Constructors Modifier Constructor Description privateMakeTree(double[][] positions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidkthElement(int i, int j, int k, int compare_d)Partition a sublist of Nodes by their coordinate in the specified dimension, such that the k-th smallest value is at positionk, elements before the k-th are smaller or equal and elements after the k-th are larger or equal.private voidmakeNode(int i, int j, int d, int nodeIndex)private static intpivot(int len)Calculate pivot index such that the tree will be arranged in a way that "leaf layers" are filled from the left.
-
-
-
Field Detail
-
numDimensions
private final int numDimensions
-
numPoints
private final int numPoints
-
positions
private final double[][] positions
The coordinates for theith point are stored atpositions[d][k]wheredis the dimension.
-
indices
private final int[] indices
Temporary array to keep track of elements. Initialized to0, 1, ...and then permuted when sorting the elements into a tree.
-
tree
private final int[] tree
Node indices in a flattened (heap-like) array. For example: the index of the root node istree[0]. The coordinates of the root node are atpositions[d][tree[0]]wheredis the dimension. The children of the root node are attree[1]andtree[2], and so on.
-
-
Method Detail
-
pivot
private static int pivot(int len)
Calculate pivot index such that the tree will be arranged in a way that "leaf layers" are filled from the left. For example 10 nodes will always be arranged like this:0 / \ 1 2 / \ / \ 3 4 5 6 / \ / 7 8 9never like this:0 / \ 1 2 / \ / \ 3 4 5 6 / / / 7 8 9By choosing pivots in this way, the tree structure is fully determined. For every node index, the child indices can be calculated without dependent reads. And iff the calculated child index is less than the number of nodes, the child exists.
-
makeNode
private void makeNode(int i, int j, int d, int nodeIndex)
-
kthElement
private void kthElement(int i, int j, int k, int compare_d)Partition a sublist of Nodes by their coordinate in the specified dimension, such that the k-th smallest value is at positionk, elements before the k-th are smaller or equal and elements after the k-th are larger or equal.- Parameters:
i- index of first element of the sublistj- index of last element of the sublistk- index for k-th smallest value.i <= k <= j.compare_d- dimension by which to order the sublist
-
-