Class Ntree<T extends java.lang.Comparable<T>>


  • public final class Ntree<T extends java.lang.Comparable<T>>
    extends java.lang.Object
    N-dimensional equivalent of a quad/oct-tree.
    • 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.
      • 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 array
        value - uniform value of all pixels in the array
      • Ntree

        Ntree​(Ntree<T> ntree)
        Copy constructor. Create a deep copy of ntree.
    • Method Detail

      • 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