Class KDTreeUtils.MakeTree
java.lang.Object
net.imglib2.kdtree.KDTreeUtils.MakeTree
- Enclosing class:
KDTreeUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]Temporary array to keep track of elements.private final intprivate final intprivate final double[][]The coordinates for theith point are stored atpositions[d][k]wheredis the dimension.private final int[]Node indices in a flattened (heap-like) array. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate 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 Details
-
numDimensions
private final int numDimensions -
numPoints
private final int numPoints -
positions
private final double[][] positionsThe coordinates for theith point are stored atpositions[d][k]wheredis the dimension. -
indices
private final int[] indicesTemporary array to keep track of elements. Initialized to0, 1, ...and then permuted when sorting the elements into a tree. -
tree
private final int[] treeNode 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.
-
-
Constructor Details
-
MakeTree
private MakeTree(double[][] positions)
-
-
Method Details
-
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
-