ini.trakem2.display
Class Node<T>

java.lang.Object
  extended by ini.trakem2.display.Node<T>
All Implemented Interfaces:
Taggable
Direct Known Subclasses:
AreaTree.AreaNode, Treeline.RadiusNode

public abstract class Node<T>
extends java.lang.Object
implements Taggable

Can only have one parent, so there aren't cyclic graphs.


Nested Class Summary
static class Node.BranchAndEndNodeIterator<I>
           
static class Node.BranchNodeIterator<I>
           
static class Node.BreadthFirstSubtreeIterator<I>
          For a given starting node, iterates over the complete set of children nodes, recursively and breadth-first.
static class Node.EndNodeIterator<I>
           
static class Node.FilteredIterator<I>
           
static class Node.NodeCollection<I>
          Read-only Collection with a very expensive size().
static class Node.NodeIterator<I>
          Stateful abstract Node iterator.
static interface Node.Operation<I>
          An operation to be applied to a specific Node.
static class Node.SlabIterator<I>
          For a given starting node, iterates all the way to the next end node or branch node, inclusive.
static class Node.SubtreeIterator<I>
           
 
Field Summary
protected  Node<T>[] children
           
protected  java.awt.Color color
           
protected  byte confidence
          The confidence value of the edge towards the parent; in other words, how much this node can be trusted to continue from its parent node.
protected static int FALSE
           
protected  Layer la
           
static byte MAX_EDGE_CONFIDENCE
          Maximum possible confidence in an edge (ranges from 0 to 5, inclusive).
protected  Node<T> parent
           
protected static int TEST
           
protected static int TRUE
           
protected  float x
           
protected  float y
           
 
Fields inherited from interface ini.trakem2.display.Taggable
DASHED_STROKE, TAG_BACKGROUND
 
Constructor Summary
Node(float x, float y, Layer la)
           
Node(java.util.HashMap<java.lang.String,java.lang.String> attr)
          To reconstruct from XML, without a layer.
 
Method Summary
 int add(Node<T> child, byte conf)
          Returns -1 when not added (e.g.
 boolean addTag(Tag tag)
           
 boolean adjustConfidence(int inc)
          Adjust the confidence value of this node with its parent.
 void apply(mpicbg.models.CoordinateTransform ct, java.awt.geom.Area roi)
           
protected  void apply(Node.Operation<T> op, java.util.Iterator<Node<T>> nodes)
           
 void apply(VectorDataTransform vlocal)
           
 void applyToSlab(Node.Operation<T> op)
          Apply @param op to this Node and all its subtree nodes until reaching a branch node or end node, inclusive.
 void applyToSubtree(Node.Operation<T> op)
          Apply @param op to this Node and all its subtree nodes.
 javax.vecmath.Point3f asPoint()
           
 Node<T> clone(Project pr)
          Returns a recursive copy of this Node subtree, where the copy of this Node is the root.
 java.util.HashMap<Node<T>,java.lang.Integer> computeAllDegrees()
          Return a map of node vs degree of that node, for the entire subtree (including this node).
 int computeDegree()
          Traverse the tree from this node all the way to the root node, and count how many nodes apart this node is from the root node: that is the degree.
protected  void copyProperties(Node<?> nd)
           
 java.util.Collection<Displayable> findLinkTargets(java.awt.geom.AffineTransform to_world)
          Returns a list of Patch to link, which lay under the node.
 Node<T> findNextBranchOrEndPoint()
          Assumes there aren't any cycles.
static
<I> java.util.List<Node<I>>
findPath(Node<I> a, Node<I> b)
          Obtain the (only) list from node a to node b, including both a (the first element) and b (the last element).
 Node<T> findPreviousBranchOrRootPoint()
           
 java.awt.geom.Area getArea()
          Returns area in local coords.
 java.util.Collection<Node<T>> getBranchAndEndNodes()
          Returns a lazy read-only Collection of all branch and end nodes under this node.
 java.util.Collection<Node<T>> getBranchNodes()
          Returns a lazy read-only Collection of all branch nodes under this node.
 java.util.Map<Node<T>,java.lang.Byte> getChildren()
           
 int getChildrenCount()
           
 java.util.ArrayList<Node<T>> getChildrenNodes()
           
 java.awt.Color getColor()
           
 byte getConfidence()
           
abstract  T getData()
           
abstract  T getDataCopy()
           
 java.util.List<java.lang.Byte> getEdgeConfidence()
           
 byte getEdgeConfidence(Node<T> child)
           
 java.util.Collection<Node<T>> getEndNodes()
          Returns a lazy read-only Collection of all end nodes under this node.
 Layer getLayer()
           
 Node<T> getParent()
           
 java.util.Collection<Node<T>> getSlabNodes()
          Returns a lazy read-only Collection of the nodes from this node up to the next branch node or end node, inclusive.
 java.util.Collection<Node<T>> getSubtreeNodes()
          Returns a lazy read-only Collection of the nodes belonging to the subtree of this node, including the node itself as the root.
 java.util.Set<Tag> getTags()
           
 float getX()
           
 float getY()
           
 boolean hasChildren()
           
 boolean hasSameTags(Node<?> other)
           
 boolean hasTag(Tag t)
           
abstract  boolean intersects(java.awt.geom.Area a)
          Expects Area in local coords.
 boolean isRoughlyInside(java.awt.Rectangle localbox)
          May return a false positive but never a false negative.
abstract  Node<T> newInstance(float x, float y, Layer layer)
           
abstract  void paintData(java.awt.Graphics2D g, java.awt.Rectangle srcRect, Tree<T> tree, java.awt.geom.AffineTransform to_screen, java.awt.Color cc, Layer active_layer)
           
protected  void paintHandle(java.awt.Graphics2D g, java.awt.Rectangle srcRect, double magnification, Tree<T> t)
           
protected  void paintHandle(java.awt.Graphics2D g, java.awt.Rectangle srcRect, double magnification, Tree<T> t, boolean paint_background)
          Paint in the context of offscreen space, without transformations.
 boolean remove(Node<T> child)
           
 java.util.Set<Tag> removeAllTags()
           
 boolean removeTag(Tag tag)
           
 void setColor(java.awt.Color c)
           
 boolean setConfidence(byte conf)
          Set the confidence value of this node with its parent.
abstract  boolean setData(T t)
           
 void setLayer(Layer la)
           
 java.lang.String toString()
           
protected  void transformData(java.awt.geom.AffineTransform aff)
          Apply @param aff to the data, not to the x,y position.
 void translate(float dx, float dy)
          Only this node, not any of its children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_EDGE_CONFIDENCE

public static final byte MAX_EDGE_CONFIDENCE
Maximum possible confidence in an edge (ranges from 0 to 5, inclusive).

See Also:
Constant Field Values

parent

protected Node<T> parent

x

protected float x

y

protected float y

color

protected java.awt.Color color

confidence

protected byte confidence
The confidence value of the edge towards the parent; in other words, how much this node can be trusted to continue from its parent node. Defaults to MAX_EDGE_CONFIDENCE for full trust, and 0 for none.


la

protected Layer la

children

protected Node<T>[] children

TRUE

protected static final int TRUE
See Also:
Constant Field Values

FALSE

protected static final int FALSE
See Also:
Constant Field Values

TEST

protected static final int TEST
See Also:
Constant Field Values
Constructor Detail

Node

public Node(float x,
            float y,
            Layer la)
Parameters:
parent - The parent Node, which has an edge of a certain confidence value towards this Node.
x - The X in local coordinates.
y - The Y in local coordinates.
layer - The Layer where the point represented by this Node sits.

Node

public Node(java.util.HashMap<java.lang.String,java.lang.String> attr)
To reconstruct from XML, without a layer. WARNING this method doesn't do any error checking. If "x" or "y" are not present in @param attr, it will simply fail with a NumberFormatException.

Method Detail

getParent

public Node<T> getParent()

getX

public float getX()

getY

public float getY()

getColor

public java.awt.Color getColor()

setColor

public void setColor(java.awt.Color c)

getConfidence

public byte getConfidence()

getLayer

public Layer getLayer()

getChildrenNodes

public java.util.ArrayList<Node<T>> getChildrenNodes()

getChildren

public java.util.Map<Node<T>,java.lang.Byte> getChildren()
Returns:
a map of child node vs edge confidence to that child.

getEdgeConfidence

public java.util.List<java.lang.Byte> getEdgeConfidence()

getEdgeConfidence

public byte getEdgeConfidence(Node<T> child)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setLayer

public void setLayer(Layer la)

add

public final int add(Node<T> child,
                     byte conf)
Returns -1 when not added (e.g. if child is null).


remove

public final boolean remove(Node<T> child)

paintHandle

protected void paintHandle(java.awt.Graphics2D g,
                           java.awt.Rectangle srcRect,
                           double magnification,
                           Tree<T> t)

paintHandle

protected void paintHandle(java.awt.Graphics2D g,
                           java.awt.Rectangle srcRect,
                           double magnification,
                           Tree<T> t,
                           boolean paint_background)
Paint in the context of offscreen space, without transformations.


getSubtreeNodes

public final java.util.Collection<Node<T>> getSubtreeNodes()
Returns a lazy read-only Collection of the nodes belonging to the subtree of this node, including the node itself as the root. Non-recursive, avoids potential stack overflow.


getSlabNodes

public final java.util.Collection<Node<T>> getSlabNodes()
Returns a lazy read-only Collection of the nodes from this node up to the next branch node or end node, inclusive.


getBranchAndEndNodes

public final java.util.Collection<Node<T>> getBranchAndEndNodes()
Returns a lazy read-only Collection of all branch and end nodes under this node.


getBranchNodes

public final java.util.Collection<Node<T>> getBranchNodes()
Returns a lazy read-only Collection of all branch nodes under this node.


getEndNodes

public final java.util.Collection<Node<T>> getEndNodes()
Returns a lazy read-only Collection of all end nodes under this node.


translate

public final void translate(float dx,
                            float dy)
Only this node, not any of its children.


clone

public final Node<T> clone(Project pr)
Returns a recursive copy of this Node subtree, where the copy of this Node is the root. Non-recursive to avoid stack overflow.


hasChildren

public final boolean hasChildren()

getChildrenCount

public final int getChildrenCount()

computeDegree

public final int computeDegree()
Traverse the tree from this node all the way to the root node, and count how many nodes apart this node is from the root node: that is the degree. Thanks to Johannes Schindelin.


findPath

public static <I> java.util.List<Node<I>> findPath(Node<I> a,
                                                   Node<I> b)
Obtain the (only) list from node a to node b, including both a (the first element) and b (the last element). Thanks to Johannes Schindelin.


computeAllDegrees

public java.util.HashMap<Node<T>,java.lang.Integer> computeAllDegrees()
Return a map of node vs degree of that node, for the entire subtree (including this node).


setConfidence

public final boolean setConfidence(byte conf)
Set the confidence value of this node with its parent.


adjustConfidence

public final boolean adjustConfidence(int inc)
Adjust the confidence value of this node with its parent.


findPreviousBranchOrRootPoint

public final Node<T> findPreviousBranchOrRootPoint()

findNextBranchOrEndPoint

public final Node<T> findNextBranchOrEndPoint()
Assumes there aren't any cycles.


setData

public abstract boolean setData(T t)

getData

public abstract T getData()

getDataCopy

public abstract T getDataCopy()

newInstance

public abstract Node<T> newInstance(float x,
                                    float y,
                                    Layer layer)

paintData

public abstract void paintData(java.awt.Graphics2D g,
                               java.awt.Rectangle srcRect,
                               Tree<T> tree,
                               java.awt.geom.AffineTransform to_screen,
                               java.awt.Color cc,
                               Layer active_layer)

intersects

public abstract boolean intersects(java.awt.geom.Area a)
Expects Area in local coords.


isRoughlyInside

public boolean isRoughlyInside(java.awt.Rectangle localbox)
May return a false positive but never a false negative. Checks only for itself and towards its parent.


getArea

public java.awt.geom.Area getArea()
Returns area in local coords.


findLinkTargets

public java.util.Collection<Displayable> findLinkTargets(java.awt.geom.AffineTransform to_world)
Returns a list of Patch to link, which lay under the node. Use the given @param aff to transform the Node data before looking up targets.


addTag

public boolean addTag(Tag tag)
Specified by:
addTag in interface Taggable
Returns:
true if the tag wasn't there already.

removeTag

public boolean removeTag(Tag tag)
Specified by:
removeTag in interface Taggable
Returns:
true if the tag was there.

copyProperties

protected final void copyProperties(Node<?> nd)

hasTag

public boolean hasTag(Tag t)

getTags

public java.util.Set<Tag> getTags()
Specified by:
getTags in interface Taggable
Returns:
a shallow copy of the tags set, if any, or null.

removeAllTags

public java.util.Set<Tag> removeAllTags()
Specified by:
removeAllTags in interface Taggable
Returns:
the tags, if any, or null.

apply

public void apply(mpicbg.models.CoordinateTransform ct,
                  java.awt.geom.Area roi)

apply

public void apply(VectorDataTransform vlocal)

asPoint

public javax.vecmath.Point3f asPoint()

transformData

protected void transformData(java.awt.geom.AffineTransform aff)
Apply @param aff to the data, not to the x,y position.


apply

protected final void apply(Node.Operation<T> op,
                           java.util.Iterator<Node<T>> nodes)
                    throws java.lang.Exception
Throws:
java.lang.Exception

applyToSubtree

public void applyToSubtree(Node.Operation<T> op)
                    throws java.lang.Exception
Apply @param op to this Node and all its subtree nodes.

Throws:
java.lang.Exception

applyToSlab

public void applyToSlab(Node.Operation<T> op)
                 throws java.lang.Exception
Apply @param op to this Node and all its subtree nodes until reaching a branch node or end node, inclusive.

Throws:
java.lang.Exception

hasSameTags

public boolean hasSameTags(Node<?> other)