Package net.imglib2.img.sparse
Class Ntree<T extends java.lang.Comparable<T>>
- java.lang.Object
-
- net.imglib2.img.sparse.Ntree<T>
-
public final class Ntree<T extends java.lang.Comparable<T>> extends java.lang.ObjectN-dimensional equivalent of a quad/oct-tree.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNtree.NtreeNode<T>
-
Field Summary
Fields Modifier and Type Field Description (package private) long[]dimensionsdimensions of tree(package private) intnnumber of dimensions.(package private) intnumChildrenhow many children (if any) each node has.(package private) intnumTreeLevelsmaximum depth of the tree.(package private) Ntree.NtreeNode<T>rootRoot of the tree
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Ntree.NtreeNode<T>copyRecursively(Ntree.NtreeNode<T> node, Ntree.NtreeNode<T> newParent)helper method for the copy constructorNtree(Ntree)to create a deep copy of the tree.(package private) Ntree.NtreeNode<T>createNode(long[] position)Create a node containing only position (if it does not exist already).(package private) Ntree.NtreeNode<T>createNodeWithValue(long[] position, T value)Set the value at position and get the lowest-level node containing position.(package private) Ntree.NtreeNode<T>getNode(long[] position)Get the lowest-level node containing position.Ntree.NtreeNode<T>getRootNode()Returns the root node of the ntree(package private) Ntree.NtreeNode<T>mergeUpwards(Ntree.NtreeNode<T> node)If all the children of our parent have the same value remove them all.
-
-
-
Field Detail
-
n
final int n
number of dimensions.
-
numTreeLevels
final int numTreeLevels
maximum depth of the tree.
-
numChildren
final int numChildren
how many children (if any) each node has.
-
root
Ntree.NtreeNode<T extends java.lang.Comparable<T>> root
Root of the tree
-
dimensions
final long[] dimensions
dimensions of tree
-
-
Constructor Detail
-
Ntree
public Ntree(long[] dimensions, T value)Create a ntree structure capable of representing an array of the given dimensions. Initially, the tree contains only a root node and represents an array of uniform values.- Parameters:
dimensions- of the arrayvalue- uniform value of all pixels in the array
-
-
Method Detail
-
copyRecursively
private Ntree.NtreeNode<T> copyRecursively(Ntree.NtreeNode<T> node, Ntree.NtreeNode<T> newParent)
helper method for the copy constructorNtree(Ntree)to create a deep copy of the tree.
-
getNode
Ntree.NtreeNode<T> getNode(long[] position)
Get the lowest-level node containing position. Note that position is not necessarily the only pixel inside the node. So use this for read-access to pixel values only.- Parameters:
position- a position inside the image.- Returns:
- the lowest-level node containing position.
-
createNode
Ntree.NtreeNode<T> createNode(long[] position)
Create a node containing only position (if it does not exist already). This may insert nodes at several levels in the tree.- Parameters:
position- a position inside the image.- Returns:
- node containing exactly position.
-
createNodeWithValue
Ntree.NtreeNode<T> createNodeWithValue(long[] position, T value)
Set the value at position and get the lowest-level node containing position. Note that position is not necessarily the only pixel inside the node, if the value matches neighboring values. If necessary, new nodes will be created. If possible, nodes will be merged.- Parameters:
position- a position inside the image.value- value to store at position.- Returns:
- node containing position.
-
mergeUpwards
Ntree.NtreeNode<T> mergeUpwards(Ntree.NtreeNode<T> node)
If all the children of our parent have the same value remove them all. Call recursively for parent.- Parameters:
node- the starting node (whose parents should be tested recursively).- Returns:
- node that the starting node was ultimately merged into.
-
getRootNode
public Ntree.NtreeNode<T> getRootNode()
Returns the root node of the ntree- Returns:
- root node
-
-