Package net.imglib2.kdtree
Class KDTreeImpl
- java.lang.Object
-
- net.imglib2.kdtree.KDTreeImpl
-
public class KDTreeImpl extends java.lang.ObjectRepresents the tree structure, and provides access to node coordinates (but not values).The nodes in the tree are arranged in Eytzinger layout (children of i are at 2i and 2i+1). Additionally, pivot indices are chosen such 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.
-
-
Field Summary
Fields Modifier and Type Field Description private intnumDimensionsprivate intnumPointsprivate KDTreePositionspositions
-
Constructor Summary
Constructors Constructor Description KDTreeImpl(KDTreePositions positions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdepth()doublegetDoublePosition(int i, int d)private intifExists(int i)If a node with indexiexists, returnsi.intleft(int i)Get the left child of nodei.intnumDimensions()intparent(int i)Get the parent of nodei.intright(int i)Get the right child of nodei.introot()Get the root node of the tree.intsize()intsplitDimension(int i)Get the dimension along which nodeidivides the space.doublesquDistance(int i, double[] pos)Compute the squared distance from nodeitopos.floatsquDistance(int i, float[] pos)Compute the squared distance from nodeitopos.doublesquDistance(int i, RealLocalizable pos)Compute the squared distance from nodeitopos.
-
-
-
Field Detail
-
numDimensions
private final int numDimensions
-
numPoints
private final int numPoints
-
positions
private final KDTreePositions positions
-
-
Constructor Detail
-
KDTreeImpl
public KDTreeImpl(KDTreePositions positions)
-
-
Method Detail
-
root
public int root()
Get the root node of the tree.- Returns:
- index of the root node
-
left
public int left(int i)
Get the left child of nodei.- Parameters:
i- node index- Returns:
- index of left child or
-1if no left child exists
-
right
public int right(int i)
Get the right child of nodei.- Parameters:
i- node index- Returns:
- index of right child or
-1if no right child exists
-
parent
public int parent(int i)
Get the parent of nodei.- Parameters:
i- node index- Returns:
- index of parent
-
ifExists
private int ifExists(int i)
If a node with indexiexists, returnsi. Otherwise, returns-1.
-
splitDimension
public int splitDimension(int i)
Get the dimension along which nodeidivides the space.- Parameters:
i- node index- Returns:
- splitting dimension.
-
getDoublePosition
public double getDoublePosition(int i, int d)
-
squDistance
public float squDistance(int i, float[] pos)Compute the squared distance from nodeitopos.
-
squDistance
public double squDistance(int i, double[] pos)Compute the squared distance from nodeitopos.
-
squDistance
public double squDistance(int i, RealLocalizable pos)Compute the squared distance from nodeitopos.
-
numDimensions
public int numDimensions()
-
size
public int size()
-
depth
public int depth()
-
-