br.usp.ime.klava.segmentit.structures
Class TreeOfCriticalLakes

java.lang.Object
  extended by br.usp.ime.klava.segmentit.structures.TreeOfCriticalLakes

public class TreeOfCriticalLakes
extends java.lang.Object

Represents an hierarchical set of nested partitions.

Extensions of this class can be used in SegmentIt by setting an implementation of TreeOfCriticalLakesBuilderIF in HierarchyManager.setTreeOfCriticalLakesBuilder(TreeOfCriticalLakesBuilderIF).

Author:
Bruno Klava

Constructor Summary
TreeOfCriticalLakes(PrimitiveCatchmentBasinsGraph graph, HierarchyCriterion criterion, int[] labels, java.awt.Point selectedPixel, int[] desiredLabels)
          Creates a hierarchy of nested partitions.
 
Method Summary
 boolean belongsToEnabledRegion(int x, int y)
          Returns if the pixel located at (x,y) belongs to the region where the hierarchy operations are restricted to.
 HierarchyNode getActiveBasin(int x, int y)
          Returns the the active basin that contains the pixel located at ( x,y).
 int[] getActiveLabels()
          Returns the active labels of each leaf node of the hierarchy.
 int getEdgeWeightIndex(int index)
          Returns the hierarchy weight associated with index
 HierarchyCriterion getHierarchyCriterion()
          Returns the HierarchyCriterion utilized to build the nested partitions set.
 HierarchyNode getHierarchyRoot()
          Returns the root node of the hierarchy.
 int getLabelActiveBasin(int x, int y)
          Returns the label of the active basin that contains the pixel located at (x,y).
 int getMaxEdgeValue()
          Returns the greatest edge weight existing in the spanning tree from which the hierarchy was built.
 int getMaxLabel()
          Returns the last nextAvailableLabel used for a HierarchyNode in this hierarchy.
 int getNextAvailableLabel()
          Returns the nextAvailableLabel for a HierarchyNode in this hierarchy, incrementing in.
 HierarchyNode getNode(int label)
          Returns the PrimitiveCatchmentBasin labeled by label.
 int getNumNodes()
          Returns the number of nodes in this hierarchy.
 PrimitiveCatchmentBasinsGraph getRAG()
          Returns the PrimitiveCatchmentBasinsGraph from which this hierarchy was built.
 int[] getWeights()
          Returns the weights of the edges in the hierarchy.
 boolean isDerivedFromInitialPartition()
           
 boolean isMergeEnabled(int x, int y)
          Returns if the merge local operation is available for the current active region that contains the pixel located at (x,y ).
 boolean isRefineEnabled(int x, int y)
          Returns if the split local operation is available in the current active region that contains the pixel located at (x,y ).
 boolean isRootActive()
          Returns if the hierarchy root is active (the selected partitions is the coarsest possible).
 HierarchyNode merge(int x, int y)
          Merges the region that contains the pixel located at (x, y).
 java.awt.image.BufferedImage paintSelectedPartition(boolean onlySelectedRegion)
          Returns an image with the selected partition painted.
 java.awt.image.BufferedImage paintSelectedPartition(HierarchyNode hierarchyNode)
          Returns an image with the selected partition painted.
 void randomizeColors()
          Randomizes the Colors associated with the HierarchyNodes of this TreeOfCriticalLakes.
 void rebuildTCLUsingLabels(int[] desiredLabels)
          Rebuilds the hierarchy in order to contain and selecting the partition defined by desiredLabels.
 HierarchyNode refine(int x, int y)
          Splits the region that contains the pixel located at (x, y).
 void setThreshold(int threshold)
          Selects a partition on the hierarchy according to a threshold value.
 void weldLabels(java.util.Collection<java.lang.Integer> labelsToWeld)
          Rebuilds the hierarchy welding the regions whose labels are in labelsToWeld.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeOfCriticalLakes

public TreeOfCriticalLakes(PrimitiveCatchmentBasinsGraph graph,
                           HierarchyCriterion criterion,
                           int[] labels,
                           java.awt.Point selectedPixel,
                           int[] desiredLabels)
Creates a hierarchy of nested partitions. The initial selected partition will be the one defined by desiredLabels.

Parameters:
graph - the PrimitiveCatchmentBasinsGraph which nodes will be the leafs of this hierarchy
criterion - the HierarchyCriterion used to build the hierarchy
labels - a labeling for the hierarchy nodes that defines an initial partition that must be localized in the hierarchy
selectedPixel - a Pixel belonging to the region of the initial partition
desiredLabels - a labeling for the hierarchy nodes that defines a partition that must be localized in the hierarchy, partition which will be the active (selected) one
Method Detail

getHierarchyCriterion

public HierarchyCriterion getHierarchyCriterion()
Returns the HierarchyCriterion utilized to build the nested partitions set.

Returns:
the HierarchyCriterion utilized to build the nested partitions set

getNextAvailableLabel

public int getNextAvailableLabel()
Returns the nextAvailableLabel for a HierarchyNode in this hierarchy, incrementing in.

Returns:
the nextAvailableLabel for a HierarchyNode in this hierarchy

getMaxLabel

public int getMaxLabel()
Returns the last nextAvailableLabel used for a HierarchyNode in this hierarchy.

Returns:
the last nextAvailableLabel used for a HierarchyNode in this hierarchy

getRAG

public PrimitiveCatchmentBasinsGraph getRAG()
Returns the PrimitiveCatchmentBasinsGraph from which this hierarchy was built.

Returns:
the PrimitiveCatchmentBasinsGraph from which this hierarchy was built

getMaxEdgeValue

public int getMaxEdgeValue()
Returns the greatest edge weight existing in the spanning tree from which the hierarchy was built.

Returns:
the greatest edge weight existing in the hierarchy was built

getNumNodes

public int getNumNodes()
Returns the number of nodes in this hierarchy.

Returns:
the number of nodes in this hierarchy

weldLabels

public void weldLabels(java.util.Collection<java.lang.Integer> labelsToWeld)
Rebuilds the hierarchy welding the regions whose labels are in labelsToWeld.

Parameters:
labelsToWeld - the labels of the regions to be welded

rebuildTCLUsingLabels

public void rebuildTCLUsingLabels(int[] desiredLabels)
Rebuilds the hierarchy in order to contain and selecting the partition defined by desiredLabels.

Parameters:
desiredLabels - a labeling for this hierarchy leaf nodes, defining a desired partition

getLabelActiveBasin

public int getLabelActiveBasin(int x,
                               int y)
Returns the label of the active basin that contains the pixel located at (x,y).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
the label of the active basin that contains the pixel located at (x,y)

getActiveBasin

public HierarchyNode getActiveBasin(int x,
                                    int y)
Returns the the active basin that contains the pixel located at ( x,y).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
the active basin that contains the pixel located at ( x,y)

getNode

public HierarchyNode getNode(int label)
Returns the PrimitiveCatchmentBasin labeled by label.

Parameters:
label - a label associate to a PrimitiveCatchmentBasin
Returns:
the PrimitiveCatchmentBasin labeled by label

getWeights

public int[] getWeights()
Returns the weights of the edges in the hierarchy.

Returns:
the weights of the edges in the hierarchy

setThreshold

public void setThreshold(int threshold)
Selects a partition on the hierarchy according to a threshold value.

Parameters:
threshold - the threshold value to select a partition in the hierarchy

paintSelectedPartition

public java.awt.image.BufferedImage paintSelectedPartition(boolean onlySelectedRegion)
Returns an image with the selected partition painted.

Returns:
an image with the selected partition painted

paintSelectedPartition

public java.awt.image.BufferedImage paintSelectedPartition(HierarchyNode hierarchyNode)
Returns an image with the selected partition painted.

Parameters:
hierarchyNode - the HierarchyNode that needs to be painted
Returns:
an image with the selected partition painted

getActiveLabels

public int[] getActiveLabels()
Returns the active labels of each leaf node of the hierarchy.

Returns:
the active labels of each leaf node of the hierarchy

refine

public HierarchyNode refine(int x,
                            int y)
Splits the region that contains the pixel located at (x, y).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
the HierarchyNode that was refined, null if the refine operation was not enabled

isRefineEnabled

public boolean isRefineEnabled(int x,
                               int y)
Returns if the split local operation is available in the current active region that contains the pixel located at (x,y ).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
true if the split local operation is available for the current active region that contains the pixel located at ( x,y)

merge

public HierarchyNode merge(int x,
                           int y)
Merges the region that contains the pixel located at (x, y).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
the HierarchyNode selected by this merging operation, null if the merge operation was not enabled

isMergeEnabled

public boolean isMergeEnabled(int x,
                              int y)
Returns if the merge local operation is available for the current active region that contains the pixel located at (x,y ).

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
true if the merge local operation is available for the current active region that contains the pixel located at ( x,y)

belongsToEnabledRegion

public boolean belongsToEnabledRegion(int x,
                                      int y)
Returns if the pixel located at (x,y) belongs to the region where the hierarchy operations are restricted to.

Parameters:
x - the x-coordinate of a pixel
y - the y-coordinate of a pixel
Returns:
true if the pixel located at (x, y) belongs to the region where the hierarchy operations are restricted to

isRootActive

public boolean isRootActive()
Returns if the hierarchy root is active (the selected partitions is the coarsest possible).

Returns:
if the hierarchy root is active

getEdgeWeightIndex

public int getEdgeWeightIndex(int index)
Returns the hierarchy weight associated with index

Parameters:
index - the order of the desired weight in the ordered weights
Returns:
the hierarchy weight associated with index

isDerivedFromInitialPartition

public boolean isDerivedFromInitialPartition()

getHierarchyRoot

public HierarchyNode getHierarchyRoot()
Returns the root node of the hierarchy.

Returns:
the root node of the hierarchy

randomizeColors

public void randomizeColors()
Randomizes the Colors associated with the HierarchyNodes of this TreeOfCriticalLakes.