net.sourceforge.olduvai.accordiondrawer
Class SplitAxis

java.lang.Object
  extended by net.sourceforge.olduvai.accordiondrawer.SplitAxis
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
StaticSplitAxis

public class SplitAxis
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A SplitAxis object represents either the X or Y axis of accordionDrawer (set using the horizontal boolean). This is a heavily modified implementation of red-black trees based off of Sun Java's TreeMap class API. This object contains the set of ALL SplitLine objects for this axis as well as the partitionedList of SplitLine objects for this axis.

Author:
Peter McLachlan (spark343@cs.ubc.ca)
See Also:
AccordionDrawer, Serialized Form

Nested Class Summary
 class SplitAxis.AxisIterator
          Iterator for the SplitAxis class of objects.
 class SplitAxis.Debug
          Internal class for debugging the split axis class.
protected  class SplitAxis.MovingSplitLine
          Wrapper class for storing end position and Split line state for a moving split line.
 
Field Summary
private  AccordionDrawer ad
          Link to the accordion drawer using this SplitAxis object
static boolean BLACK
          Value for black nodes in CRT implementation of red-black trees.
private static boolean createMax
          Used for resizeForest(AbstractRangeList, int, Hashtable, double) true when the last range was to the left of the max stuck position
private static boolean createMin
          Used for resizeForest(AbstractRangeList, int, Hashtable, double) true when the first range was to the right of the min stuck position
 SplitAxis.Debug debug
          Object for debugging.
static double defaultMaxStuckValue
          Default value of maximum stuck line in X and Y directions.
static double defaultMinStuckValue
          Default value of minimum stuck line in X and Y directions.
static double defaultSplitValue
          Default value of split line value for all bounded split lines.
protected  boolean horizontal
          Whether this Split Axis is horizontal (true) or vertical (false).
protected  int LEFT
          array index for left bounds
static int maxBound
          Useful quick index for the array returned from the getBounds() method.
protected  SplitLine maxStuckLine
          Maximum stuck line for doing direct == comparisons But NOT ACTUALLY IN THE TREE STRUCTURE!! Also stores the current maxStuck Value, which is a world-space bound for the drawing canvas.
static int minBound
          Useful quick index for the array returned from the getBounds() method.
protected  SplitLine minStuckLine
          Minimum stuck line for doing direct == comparisons But NOT ACTUALLY IN THE TREE STRUCTURE!! Also stores the current minStuck Value, which is a world-space bound for the drawing canvas.
private  int modCount
          The number of structural modifications to the tree.
protected  java.util.TreeSet partitionedList
          This contains the 'partitioned' list of splitLines to draw, including potentially 'fake' split lines that represent the center line of a single cell (and whose absoluteValue is never referenced, used only for the purposes of their min and max bounds.)
static boolean RED
          Value for red nodes in CRT implementation of red-black trees.
protected  int RIGHT
          array index for right bounds
private  SplitLine root
          The root split line for the represented treemap object.
private static long serialVersionUID
          ID for serialization purposes.
private  int size
          The number of entries in the tree.
protected static double small
          Small number used to avoid division by 0 in computeFinalRelative(double, double, double).
private  boolean staticLines
          Hook flag for TJ: true when we use static split lines.
 
Constructor Summary
SplitAxis()
          Test constructor.
SplitAxis(AccordionDrawer ad, boolean horizontal, double minStuckValue, double maxStuckValue, int initLines, boolean reset, boolean staticLines)
          Constructor for initializing split axes with pre-determined values.
 
Method Summary
 void addCell(GridCell cell, SplitLine leftSplitLine)
          Set the cell's boundaries given a known left (or top) split line for the cell.
 void addCell(GridCell cell, SplitLine leftSplitLine, SplitLine rightSplitLine)
          Set the cell's boundaries given a known left (or top) split line for the cell.
 void animatedReset(java.util.Hashtable newToMove, int numSteps)
          Enqueue SplitTransitions to reset the entire display back to its default position.
 void clear()
          Removes all mappings from this TreeMap.
private static boolean colorOf(SplitLine p)
          Returns the color of a given node (split line)
private  void computeAllSL(SplitLine currentSL, int frameNum)
          For debugging: compute positions of all split lines.
 int[] computeBoundIndices(StaticSplitLine currRoot)
          Gets the indices for the bounds of the given split line
private static double computeFinalAbsolute(double initLeft, double initMid, double initRight, double finalLeft, double finalRight)
          Helper function for moveSplitLineSet.
private static double computeFinalRelative(double finalLeft, double finalMid, double finalRight)
          Helper function for moveSplitLineSet.
private  SplitLine computeLeftBound(SplitLine line)
          Computes and returns line's first left bound.
 void computePlaceThisFrame(SplitLine splitline, int frameNum)
          Computes a position for the given splitline for the frame number given.
private  SplitLine computeRightBound(SplitLine line)
          Computes and Returns line's first right bound.
private  SplitLine[] createIndexRanges(AbstractRangeList group)
          Helper function for resizeForest.
private  void decrementSize()
          Decrements counters modCount and size.
private  void decrementTreeRecursive(SplitLine line)
          Ascend recursively decrementing subtree counters as we go.
 void deleteEntry(SplitLine p)
          Delete node p, and then rebalance the tree.
private  void fixAfterDeletion(SplitLine x)
          Update the tree structure following a delete operation.
private  void fixAfterInsertion(SplitLine x)
          Update the tree structure following an insert operation.
 double getAbsoluteValue(int index, int frameNum)
          Returns the absolute position of the split line at the specified offset from the left of the tree, in world coordinates.
 double getAbsoluteValue(SplitLine line, int frameNum)
          Returns the absolute position of the specified split line.
 SplitLine[] getBounds(SplitLine line, int framenum)
          Retrieve left and right first bounds into an array.
 java.util.List<SplitLine> getChildren(SplitLine line, java.util.List<SplitLine> list)
          Recursively retrieves an pre-ordered list of the child splitlines of the specified line (min -> max)
 SplitLine getMaxBound(SplitLine line, int framenum)
          Retrieve the given line's right (max) Split Line bound.
 int getMaxBoundI(SplitLine line, int framenum)
          Get the index of the max bound split line for the given line.
 SplitLine getMaxLine()
          Get the line in the maximum position in the tree.
 SplitLine getMaxLineForPixelValue(double worldPosition, int frameNum)
          Returns the next line greater than the specified world space coordinate for this axis.
 SplitLine getMaxLineForPixelValue(int pixelPosition, int frameNum)
          Returns the next line over (successor).
 SplitLine getMaxStuckLine()
          The max stuck value is a world space double value from 0 ..
 double getMaxStuckValue()
          The max stuck value is a world space double value from 0 ..
 SplitLine getMinBound(SplitLine line, int framenum)
          Retrieve the given line's left (min) Split Line bound.
 int getMinBoundI(SplitLine line, int framenum)
          Get the index of the min bound split line for the given line.
 SplitLine getMinLine()
          Get the line in the minimum position in the tree.
 SplitLine getMinLineForPixelValue(double worldLocation, int frameNum)
          This does the same thing as getSplitFromAbsolute and returns a minimum split line given an absolute position.
 SplitLine getMinLineForPixelValue(int pixelPosition, int frameNum)
          This does the same thing as getSplitFromAbsolute and returns a minimum split line given an absolute position.
 SplitLine getMinStuckLine()
          The min stuck value is a world space double value from 0 ..
 double getMinStuckValue()
          The min stuck value is a world space double value from 0 ..
 SplitLine getNextSplit(SplitLine line)
          Returns the next splitline greater than the parameter.
 java.util.TreeSet getPartitionedList()
          Get the partitioned list, the list created prior to rendering to determine the visible objects and culling limit.
 SplitLine getPreviousSplit(SplitLine line)
          Returns the splitLine previous to the parameter.
 SplitLine getRoot()
          Gets the root split line for this axis.
 int getRootIndex()
          Returns ths index of the root split line.
 int getSize()
          Get the number of split lines on the axis, not including min and max stuck lines.
 SplitLine getSplitFromAbsolute(double worldCoords, double pixelSize, int frameNum)
          Find a split line using absolute values to return the minimum bounding split line at the screen position.
 SplitLine getSplitFromIndex(int index)
          Returns the split line at the specified offset in the tree.
private  SplitLine getSplitFromIndexRecursive(int index, int fromLeft, SplitLine node)
          Recursive helper function for 'getSplitFromIndex()'.
 int getSplitIndex(SplitLine line)
          Calculate the index number of any splitline from the left side of the tree.
 int getSplitIndexFromAbsolute(double worldCoord, double pixelSize, int frameNum)
          Wrapper for getSplitFromAbsolute for places where we want the index number instead of a pointer to the SplitLine object.
private static double getTotalExtent(double[] extent)
          Helper function for resizeForest.
 boolean greaterThan(SplitLine baseLine, SplitLine comparator)
          Returns true if baseLine is a successor to comparator O(2 log n)
private  void incrementSize()
          Increments counters modCount and size.
private  void incrementTreeRecursive(SplitLine line)
          Ascend recursively incrementing subtree counters as we go.
private  void initSplitValues(int initSize, boolean staticLines)
          This initializes a split line tree (empty) of size 'size'.
private  void initStaticSplitSubtree(StaticSplitLine currRoot)
          Recursively initialize binary tree structure.
 boolean isHorizontal()
          Determines if this is a horizontal SplitAxis
 boolean isReal(SplitLine line)
          Some split lines are 'fake' leaf lines that are created to be loaded into the partitioned set.
private  boolean isRoot(SplitLine en)
          Checks whether param is the root of this split axis.
private  boolean isSplitLeftChild(SplitLine en)
          Checks whether parameter is a left child of its parent.
 java.util.Iterator<SplitLine> iterator()
          Returns an iterator over the axis.
private static SplitLine leftOf(SplitLine p)
          Gets the left child of a given split line.
 boolean lessThan(SplitLine baseLine, SplitLine comparator)
          Returns true if baseLine is previous to comparator O(2 log n)
private  void makePixelRangeRecursive(java.util.TreeSet partitionSet, SplitLine line, double pixelSize, int frameNum)
          This is the recursive call that builds the partition list for this SplitAxis object.
 void makePixelRanges(double pixelSizeMultiple, int frameNum)
          Create list of SplitLines for this axis that are larger than the specified blockSize (ad.getPixelSize).
 void makePixelRanges(int frameNum)
          Create list of SplitLines for this axis that are larger than the specified blockSize: AccordionDrawer.getPixelSize(int).
 void moveLine(SplitLine dragLine, int dragPixelEnd, SplitLine fixedLine, int numSteps, java.util.Hashtable newToMove)
          Handles the case of the user drawing an interaction box and dragging on it.
private  void moveSplitLineSet(SplitLine currRoot, SplitAxis.MovingSplitLine[] toMove, java.util.Hashtable transitions, int numSteps)
          This moves an array of split lines whose final positions have been specified through user interation.
private static SplitLine parentOf(SplitLine p)
          Returns the parent of a given node (split line)
private  SplitLine previous(SplitLine t)
          Returns the previous of the specified Entry, or null if no such.
protected static void print(java.lang.String s)
          Error printing function, displays string in stderr.
 boolean putAt(SplitLine newSplit, SplitLine adjacentSplit)
          We know which node of the tree we want to insert next to so the metricName is generated inside of this function.
 void resetSplitValues()
          Wrapper to call resetSplitValuesRecurse() Must call computePlaceThisFrame before drawing anything after a reset.
private  void resetSplitValuesRecurse(SplitLine splitline)
          Recursively reset a subtree of split line values Previously n log n operation.
 void resizeForest(AbstractRangeList group, int numSteps, java.util.Hashtable newToMove, double inflateIncr)
          Resize the group by the inflation increment, in the given number of steps, and add the transitions to the hashtable for successive redraws.
private static SplitLine rightOf(SplitLine p)
          Gets the right child of a given split line.
private  void rotateLeft(SplitLine p)
          Based on CLR Do a left rotate at the given node.
private  void rotateRight(SplitLine p)
          Based on CLR Do a right rotate at the given node.
private  void setBounds(SplitLine line)
          Depending on whether line is a left or right child node, set the opBound value of line to be the left or right bound.
private static void setColor(SplitLine p, boolean c)
          Sets the value of SplitLine.color for a given split line.
 void setMaxStuckValue(double f)
          The max stuck value is a world space double value from 0 ..
 void setMinStuckValue(double f)
          The min stuck value is a world space double value from 0 ..
private  SplitLine successor(SplitLine t)
          Returns the successor (next) of the specified Entry, or null if no such.
 java.lang.String toString()
          String output routine for splitaxes, displays SplitLine.toLongString() for root of axis.
private  void updateBoundLeftEchelon(SplitLine line)
          Repair left subtree following a delete
private  void updateBoundRightEchelon(SplitLine line)
          Repair right subtree following a delete
private  void updateEchelonBounds(SplitLine line)
          Repairs tree structure around the given split line following a delete operation.
 void updateSubtreeSize(SplitLine currRoot)
          Recursively update the size of subtrees under the given current split line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

root

private transient SplitLine root
The root split line for the represented treemap object.


staticLines

private boolean staticLines
Hook flag for TJ: true when we use static split lines. False for dynamic grids.


size

private transient int size
The number of entries in the tree.


modCount

private transient int modCount
The number of structural modifications to the tree. Monotonic increase on any add, delete, or clear of split lines from axis.


RED

public static final boolean RED
Value for red nodes in CRT implementation of red-black trees.

See Also:
Constant Field Values

BLACK

public static final boolean BLACK
Value for black nodes in CRT implementation of red-black trees.

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
ID for serialization purposes.

See Also:
Constant Field Values

debug

public final SplitAxis.Debug debug
Object for debugging. Checks for bounds, tree sizes, and tree properties done with this object.


defaultMinStuckValue

public static final double defaultMinStuckValue
Default value of minimum stuck line in X and Y directions.

See Also:
Constant Field Values

defaultMaxStuckValue

public static final double defaultMaxStuckValue
Default value of maximum stuck line in X and Y directions.

See Also:
Constant Field Values

defaultSplitValue

public static final double defaultSplitValue
Default value of split line value for all bounded split lines. For axes that have (2^n-1) split lines, this results in a uniformly spaced axis, if the tree is kept balanced.

See Also:
Constant Field Values

minStuckLine

protected SplitLine minStuckLine
Minimum stuck line for doing direct == comparisons But NOT ACTUALLY IN THE TREE STRUCTURE!! Also stores the current minStuck Value, which is a world-space bound for the drawing canvas.


maxStuckLine

protected SplitLine maxStuckLine
Maximum stuck line for doing direct == comparisons But NOT ACTUALLY IN THE TREE STRUCTURE!! Also stores the current maxStuck Value, which is a world-space bound for the drawing canvas.


minBound

public static final int minBound
Useful quick index for the array returned from the getBounds() method.

See Also:
Constant Field Values

maxBound

public static final int maxBound
Useful quick index for the array returned from the getBounds() method.

See Also:
Constant Field Values

ad

private AccordionDrawer ad
Link to the accordion drawer using this SplitAxis object


horizontal

protected boolean horizontal
Whether this Split Axis is horizontal (true) or vertical (false).


partitionedList

protected java.util.TreeSet partitionedList
This contains the 'partitioned' list of splitLines to draw, including potentially 'fake' split lines that represent the center line of a single cell (and whose absoluteValue is never referenced, used only for the purposes of their min and max bounds.)


createMin

private static boolean createMin
Used for resizeForest(AbstractRangeList, int, Hashtable, double) true when the first range was to the right of the min stuck position


createMax

private static boolean createMax
Used for resizeForest(AbstractRangeList, int, Hashtable, double) true when the last range was to the left of the max stuck position


LEFT

protected final int LEFT
array index for left bounds

See Also:
Constant Field Values

RIGHT

protected final int RIGHT
array index for right bounds

See Also:
Constant Field Values

small

protected static final double small
Small number used to avoid division by 0 in computeFinalRelative(double, double, double).

See Also:
Constant Field Values
Constructor Detail

SplitAxis

public SplitAxis(AccordionDrawer ad,
                 boolean horizontal,
                 double minStuckValue,
                 double maxStuckValue,
                 int initLines,
                 boolean reset,
                 boolean staticLines)
Constructor for initializing split axes with pre-determined values. Calls initSplitValues(int, boolean)

Parameters:
ad - Drawer that uses this split axis: ad
horizontal - True if horizontal axis, false for vertical: horizontal
minStuckValue - Position of minimum stuck line: minStuckLine
maxStuckValue - Position of maximum stuck line: maxStuckLine
initLines - Number of split lines to insert into the axis
reset - True: balance the split line tree after inserting initLines, false: do not balance, use default value for each split line: defaultSplitValue
staticLines - True if using static split lines (TJ), false otherwise: staticLines

SplitAxis

public SplitAxis()
Test constructor.

Method Detail

incrementSize

private void incrementSize()
Increments counters modCount and size.


decrementSize

private void decrementSize()
Decrements counters modCount and size.


clear

public void clear()
Removes all mappings from this TreeMap.


colorOf

private static boolean colorOf(SplitLine p)
Returns the color of a given node (split line)

Parameters:
p - Split line to get color of.
Returns:
Value of SplitLine.color, or BLACK if split line is null.

parentOf

private static SplitLine parentOf(SplitLine p)
Returns the parent of a given node (split line)

Parameters:
p - Split line to get parent of.
Returns:
Value of SplitLine.getParent() for p, or null if p is null.

setColor

private static void setColor(SplitLine p,
                             boolean c)
Sets the value of SplitLine.color for a given split line.

Parameters:
p - Split line to set.
c - New color value for p.

leftOf

private static SplitLine leftOf(SplitLine p)
Gets the left child of a given split line.

Parameters:
p - Node to get child from.
Returns:
Value of SplitLine.getLeftChild(), or null if p is null.

rightOf

private static SplitLine rightOf(SplitLine p)
Gets the right child of a given split line.

Parameters:
p - Node to get child from.
Returns:
Value of SplitLine.getRightChild(), or null if p is null.

fixAfterInsertion

private void fixAfterInsertion(SplitLine x)
Update the tree structure following an insert operation. Based on CLR implementation.

Parameters:
x - Split line that has just been inserted. x changes (ascends) during this function as tree is fixed.

fixAfterDeletion

private void fixAfterDeletion(SplitLine x)
Update the tree structure following a delete operation. Based on CLR implementation.

Parameters:
x - Parent of split line that has just been removed. x changes (ascends) during this function as tree is fixed.

successor

private SplitLine successor(SplitLine t)
Returns the successor (next) of the specified Entry, or null if no such. Returns max stuck line if no successor elements in tree.

Parameters:
t - Split line to get successor for
Returns:
Successor split line, or max stuck line if given max stuck line as parameter

previous

private SplitLine previous(SplitLine t)
Returns the previous of the specified Entry, or null if no such. Returns minimum stuck line if no previous elements in tree.

Parameters:
t - Split line to get previous for
Returns:
Previous split line, or min stuck line if given min stuck line as parameter

rotateLeft

private void rotateLeft(SplitLine p)
Based on CLR Do a left rotate at the given node. Helper function called by the fix functions.

Parameters:
p - Node to rotate at: this node becomes the left child of its right child, and gains that child's left child as its new right child.

rotateRight

private void rotateRight(SplitLine p)
Based on CLR Do a right rotate at the given node. Helper function called by the fix functions.

Parameters:
p - Node to rotate at: this node becomes the right child of its left child, and gains that child's right child as its new left child.

getNextSplit

public SplitLine getNextSplit(SplitLine line)
Returns the next splitline greater than the parameter. This can be maxStuckLine if line is the last line in the tree.

Parameters:
line -
Returns:
the next splitline greater than the parameter.

getPreviousSplit

public SplitLine getPreviousSplit(SplitLine line)
Returns the splitLine previous to the parameter. This can be minStuckLine if line is the first movable line in the tree. Note: wrapper call for the private previous() method.

Parameters:
line - Line to get the previous split for
Returns:
The previous split line for the given split line

getSplitFromIndex

public SplitLine getSplitFromIndex(int index)
Returns the split line at the specified offset in the tree.

Parameters:
index - The position of the splitLine in a 'flattened' view of the tree.
Returns:
A splitline object

getSplitFromIndexRecursive

private SplitLine getSplitFromIndexRecursive(int index,
                                             int fromLeft,
                                             SplitLine node)
Recursive helper function for 'getSplitFromIndex()'.

Parameters:
index - - the index of the splitLine we are searching for
fromLeft - - how far we are from the left of the tree up until now
node - - current node in the tree
Returns:
the given split line from the initial index of interest

updateEchelonBounds

private void updateEchelonBounds(SplitLine line)
Repairs tree structure around the given split line following a delete operation.

Parameters:
line - Initial successor to the deleted split line

updateBoundLeftEchelon

private void updateBoundLeftEchelon(SplitLine line)
Repair left subtree following a delete

Parameters:
line - Initially the successor to the deleted split line, the children of this line will be repaired.
See Also:
updateEchelonBounds(SplitLine)

updateBoundRightEchelon

private void updateBoundRightEchelon(SplitLine line)
Repair right subtree following a delete

Parameters:
line - Initially the successor to the deleted split line, the children of this line will be repaired.
See Also:
updateEchelonBounds(SplitLine)

deleteEntry

public void deleteEntry(SplitLine p)
Delete node p, and then rebalance the tree. Code is derived from CLR red-black tree implementation

Parameters:
p - SplitLine to delete

incrementTreeRecursive

private void incrementTreeRecursive(SplitLine line)
Ascend recursively incrementing subtree counters as we go. O(log n) operation. Follows an add operation (putAt(SplitLine, SplitLine)).

Parameters:
line - The current line in the recursive process to increment.

decrementTreeRecursive

private void decrementTreeRecursive(SplitLine line)
Ascend recursively decrementing subtree counters as we go. Log(n) operation. Follows a delete operation (deleteEntry(SplitLine)).

Parameters:
line - The current line in the recursive process to decrement.

putAt

public boolean putAt(SplitLine newSplit,
                     SplitLine adjacentSplit)
We know which node of the tree we want to insert next to so the metricName is generated inside of this function. If you are inserting the first splitline the adjacentSplit argument is ignored and can be null. O(log n)

Parameters:
newSplit - The new split line object.
adjacentSplit - The split line you want to insert adjacent to. (Left or Top depending on whether this is a vertical or horizontal split line.) Inserting after minStuckLine is valid.
Returns:
true on success, false otherwise.

computeAllSL

private void computeAllSL(SplitLine currentSL,
                          int frameNum)
For debugging: compute positions of all split lines. Only really needs to be called on all leaves, but both operations are O(n) with caching

Parameters:
currentSL - Current split line to compute, recurse on children of this split line
frameNum - frame number to use for computing locations

animatedReset

public void animatedReset(java.util.Hashtable newToMove,
                          int numSteps)
Enqueue SplitTransitions to reset the entire display back to its default position. Queued entries are returned by means of the passed in parameter

Parameters:
newToMove - Hashtable to act as the current move queue.
numSteps - Number of steps to animate.

resetSplitValues

public void resetSplitValues()
Wrapper to call resetSplitValuesRecurse() Must call computePlaceThisFrame before drawing anything after a reset. Previous technique: O(n log n) behavior, is now O(n)


resetSplitValuesRecurse

private void resetSplitValuesRecurse(SplitLine splitline)
Recursively reset a subtree of split line values Previously n log n operation. Made this o(n) by eliminating calls to getSplitIndex Note: this distributes split lines uniformly with split line indices, uses subtree sizes to place split lines accordingly

Parameters:
splitline - Current subtree root to reset.

getSplitIndex

public int getSplitIndex(SplitLine line)
Calculate the index number of any splitline from the left side of the tree. WARNING: O(log n) operation.

Parameters:
line - Line to compute index number for.
Returns:
Index of split line in tree, or Integer.MIN_VALUE if line is null

initSplitValues

private void initSplitValues(int initSize,
                             boolean staticLines)
This initializes a split line tree (empty) of size 'size'. O(2(n log n)) operation

Parameters:
initSize - Initial seed size of the split line hierarchy
staticLines - true if we are using static split lines for this axis, false for dynamic

computeBoundIndices

public int[] computeBoundIndices(StaticSplitLine currRoot)
Gets the indices for the bounds of the given split line

Parameters:
currRoot - Split line to compute bounding split lines
Returns:
pair of indices for LEFT and RIGHT bounds of this split line

initStaticSplitSubtree

private void initStaticSplitSubtree(StaticSplitLine currRoot)
Recursively initialize binary tree structure. Set properties of currRoot before this function

Parameters:
currRoot - Current subtree root split line that is being initialized.

addCell

public void addCell(GridCell cell,
                    SplitLine leftSplitLine)
Set the cell's boundaries given a known left (or top) split line for the cell. This is for cells with a single unit in length/width.

Parameters:
cell - The cell whose splitline boundaries are being defined
leftSplitLine - The split line on the left (or top) side of the cell

addCell

public void addCell(GridCell cell,
                    SplitLine leftSplitLine,
                    SplitLine rightSplitLine)
Set the cell's boundaries given a known left (or top) split line for the cell. This is for cells with potentially many units in length/width.

Parameters:
cell - The cell whose splitline boundaries are being defined
leftSplitLine - The split line on the left (or top) side of the cell
rightSplitLine - The split line on the right (bottom) side of the cell

getAbsoluteValue

public double getAbsoluteValue(SplitLine line,
                               int frameNum)
Returns the absolute position of the specified split line. This function caches the values for the given frame number.

Parameters:
line - Split line to get absolute position
frameNum - Current frame number
Returns:
Absolute position in world coordinates for the given split line.

getAbsoluteValue

public double getAbsoluteValue(int index,
                               int frameNum)
Returns the absolute position of the split line at the specified offset from the left of the tree, in world coordinates. This function caches the values for the given frame number.

Parameters:
index - Index of a split line to get the position for.
frameNum - Current frame number.
Returns:
Absolute position in world coordinates for the given split line.

getSplitIndexFromAbsolute

public int getSplitIndexFromAbsolute(double worldCoord,
                                     double pixelSize,
                                     int frameNum)
Wrapper for getSplitFromAbsolute for places where we want the index number instead of a pointer to the SplitLine object. Renamed from getSplitLineIndex.

Parameters:
worldCoord - World coordinate to search for a split line.
pixelSize - Current block size, in world-space coordinates.
frameNum - Current frame number.
Returns:
The index number of the split line, or -2 if you are outside of the stuck positions or there is an error.

setMaxStuckValue

public void setMaxStuckValue(double f)
The max stuck value is a world space double value from 0 .. 1 that defines where the max boundary split line is located in world space for this axis.

Parameters:
f - Value from [0,1] that places the max stuck value for this split axis.

setMinStuckValue

public void setMinStuckValue(double f)
The min stuck value is a world space double value from 0 .. 1 that defines where the min boundary split line is located in world space for this axis.

Parameters:
f - Value from [0,1] that places the min stuck value for this split axis.

getMaxStuckValue

public double getMaxStuckValue()
The max stuck value is a world space double value from 0 .. 1 that defines where the max boundary split line is located in world space for this axis.

Returns:
World-space position of max stuck line.

getMaxStuckLine

public SplitLine getMaxStuckLine()
The max stuck value is a world space double value from 0 .. 1 that defines where the max boundary split line is located in world space for this axis. This line contains the max stuck value in its absoluteValue property.

Returns:
Split line that represents the maximum boundary for this axis.

getMinStuckValue

public double getMinStuckValue()
The min stuck value is a world space double value from 0 .. 1 that defines where the min boundary split line is located in world space for this axis.

Returns:
World-space position of min stuck line.

getMinStuckLine

public SplitLine getMinStuckLine()
The min stuck value is a world space double value from 0 .. 1 that defines where the min boundary split line is located in world space for this axis. This line contains the min stuck value in its absoluteValue property.

Returns:
Split line that represents the minimum boundary for this axis.

getSplitFromAbsolute

public SplitLine getSplitFromAbsolute(double worldCoords,
                                      double pixelSize,
                                      int frameNum)
Find a split line using absolute values to return the minimum bounding split line at the screen position. This uses the main split data structures and NOT the partitioned list. This method may return the minStuckLine but never the maxStuckLine

Parameters:
worldCoords - World coordinate to search for a split line.
pixelSize - Current block size, in world-space coordinates.
frameNum - Current frame number.
Returns:
Closest minimum split line to the given world-space coordinate

getMinLine

public SplitLine getMinLine()
Get the line in the minimum position in the tree. (NOT the minStuckLine.) O(log n) (approx)

Returns:
Left-most split line, the minimum non-stuck split line.
See Also:
to get the minStuckLine

getMaxLine

public SplitLine getMaxLine()
Get the line in the maximum position in the tree. (NOT the maxStuckLine.) O(log n) (approx)

Returns:
Right-most split line, the maximum non-stuck split line.

getMinLineForPixelValue

public SplitLine getMinLineForPixelValue(int pixelPosition,
                                         int frameNum)
This does the same thing as getSplitFromAbsolute and returns a minimum split line given an absolute position. The only difference is that it doesn't stop when it reaches minimum block size and it takes a screen space coordinate as a parameter. TODO: these two methods should probably be merged.

Parameters:
pixelPosition - Screen space coordinate.
frameNum - Current frame number.
Returns:
Minimum split line adjacent to screen space coordinate.

getMinLineForPixelValue

public SplitLine getMinLineForPixelValue(double worldLocation,
                                         int frameNum)
This does the same thing as getSplitFromAbsolute and returns a minimum split line given an absolute position. The only difference is that it doesn't stop when it reaches minimum block size and it takes a screen space coordinate as a parameter. TODO: these two methods should probably be merged. TODO: probably shouldn't take pixel-space coordinate

Parameters:
worldLocation - Screen space coordinate
frameNum - Current frame number
Returns:
Minimum split line adjacent to screen space coordinate.

getMaxLineForPixelValue

public SplitLine getMaxLineForPixelValue(int pixelPosition,
                                         int frameNum)
Returns the next line over (successor).

Parameters:
pixelPosition - Screen-space coordinate
frameNum - Current frame number.
Returns:
Split line for the successor at the current pixel position.

getMaxLineForPixelValue

public SplitLine getMaxLineForPixelValue(double worldPosition,
                                         int frameNum)
Returns the next line greater than the specified world space coordinate for this axis.

Parameters:
worldPosition - World-space coordinate.
frameNum - Current frame number.
Returns:
Split line for the successor at the current world position.

isHorizontal

public boolean isHorizontal()
Determines if this is a horizontal SplitAxis

Returns:
true if horizontal, false if vertical

getRootIndex

public int getRootIndex()
Returns ths index of the root split line.

Returns:
The integer index to the current value of the root node.

isRoot

private boolean isRoot(SplitLine en)
Checks whether param is the root of this split axis.

Parameters:
en - Split line to test for root.
Returns:
true if the parameter is the root of the axis hierarchy

isSplitLeftChild

private boolean isSplitLeftChild(SplitLine en)
Checks whether parameter is a left child of its parent.

Parameters:
en - Split line to test for being left child
Returns:
true if this split line has a parent and is the left child.

computePlaceThisFrame

public void computePlaceThisFrame(SplitLine splitline,
                                  int frameNum)
Computes a position for the given splitline for the frame number given. Frame numbers in the past are not supported (no memory), this is just to know when a splitline is out of date with the current view (caching, don't recompute positions when nothing moves)

Parameters:
splitline - splitline to compute a location for
frameNum - frame number to check for cached splitline positions

getChildren

public java.util.List<SplitLine> getChildren(SplitLine line,
                                             java.util.List<SplitLine> list)
Recursively retrieves an pre-ordered list of the child splitlines of the specified line (min -> max)

Parameters:
line - Current split line being recursed through.
list - Recursive collector
Returns:
Value of list after adding child split lines.

makePixelRanges

public void makePixelRanges(int frameNum)
Create list of SplitLines for this axis that are larger than the specified blockSize: AccordionDrawer.getPixelSize(int). Initializes and fills partitionedList.

Parameters:
frameNum - Current frame number

makePixelRanges

public void makePixelRanges(double pixelSizeMultiple,
                            int frameNum)
Create list of SplitLines for this axis that are larger than the specified blockSize (ad.getPixelSize). Initializes and fills partitionedList.

Parameters:
frameNum - Current frame number
pixelSizeMultiple - factor used to divide the size of a single pixel to determine block size.

makePixelRangeRecursive

private void makePixelRangeRecursive(java.util.TreeSet partitionSet,
                                     SplitLine line,
                                     double pixelSize,
                                     int frameNum)
This is the recursive call that builds the partition list for this SplitAxis object. It descends the tree structure computing place this frame until it begins to produce results which subtend pixelSize. When this happens, recursion is finished. NOTE: You will notice two cases where 'Virtual' split lines are being added. This is because the final 'leaf' layer of the tree is virtualized. Drawing always takes place using the absolutePosition of a SplitLine's parent & opAncestor (their equivelent of min and max bounds) and therefore nothing about the SplitLine object that is enqueued matters except that these two bounds are valid & have valid absolutePositions. See AccordionSequenceDrawer.drawRange for details.

Parameters:
partitionSet - TreeSet of SplitLines that represent the partition list
line - splitline, initially the root line then recursively left & right descends
pixelSize - minimal size of a block in absolute [0,1] size. This is what stops the recursion from descending indefinitely.

resizeForest

public void resizeForest(AbstractRangeList group,
                         int numSteps,
                         java.util.Hashtable newToMove,
                         double inflateIncr)
Resize the group by the inflation increment, in the given number of steps, and add the transitions to the hashtable for successive redraws. 3 major steps: 1) compute "unshrinkable" space, and subtract that from the inflate increment. Also computes component resize ratios for growing and shrinking regions. 2) handle edge cases where we either start with a range list on the stuck line, or shrink a region adjacent to a stuck line (min and max) 3) handle interior cases in the same way as 2), but with the generic for loop stucture After those steps, we run moveSplitLineSet(SplitLine, net.sourceforge.olduvai.accordiondrawer.SplitAxis.MovingSplitLine[], Hashtable, int) to create transitions from the sanely computed movement distances (stored in an array).

Parameters:
group - Set of split adjacent split lines usually marked in the same color that are being resized
numSteps - The number of animated transition steps
newToMove - The new transition hash table
inflateIncr - The inflate increment. All components of group will divide this world-space value among them, with larger subgroups growing more than smaller ones, size ratios are preserved.

createIndexRanges

private SplitLine[] createIndexRanges(AbstractRangeList group)
Helper function for resizeForest. create range of indices of split lines for ranges in group this includes the min/max stuck position split lines (if not already in a group)

Parameters:
group - Group to parse for split lines to retrieve indices
Returns:
Array of pairs of split line indices, 2 for each region (even/odd).

getTotalExtent

private static final double getTotalExtent(double[] extent)
Helper function for resizeForest. Computes the total extent between pairs of distances given as the parameter.

Parameters:
extent - Array of distances to add up.
Returns:
Sum of all extents. This will be used to compute the non-extent, aka the squishable space.

moveLine

public void moveLine(SplitLine dragLine,
                     int dragPixelEnd,
                     SplitLine fixedLine,
                     int numSteps,
                     java.util.Hashtable newToMove)
Handles the case of the user drawing an interaction box and dragging on it. In this case, only one split line is actually being moved per axis, either the left, right, top or bottom line depending on the axis and the direction of the drag motion.

Parameters:
dragLine - line to be moved
dragPixelEnd - screen coords of destination position
fixedLine - non-moving line in interaction box
numSteps - animation steps
newToMove - hashmap to be filled with animated transition steps

computeFinalAbsolute

private static final double computeFinalAbsolute(double initLeft,
                                                 double initMid,
                                                 double initRight,
                                                 double finalLeft,
                                                 double finalRight)
Helper function for moveSplitLineSet. Gets new position of mid: finalMid = (initMid-initLeft)/(initRight-initLeft)*(finalRight-finalLeft)+finalLeft (translate, rescale, translate) All params are absolute positions.

Parameters:
initLeft - Left line's initial absolute position.
initMid - Mid line's initial absolute position.
initRight - Right line's initial absolute position.
finalLeft - Left line's final absolute position.
finalRight - Right line's final absolute position.
Returns:
new final absolute value for initMid's split line ( = finalMid)

computeFinalRelative

private static final double computeFinalRelative(double finalLeft,
                                                 double finalMid,
                                                 double finalRight)
Helper function for moveSplitLineSet. All params are absolute positions.

Parameters:
finalLeft - Final position for left split line
finalMid - Final position for mid split line
finalRight - Final position for right split line
Returns:
Final relative position (split line position between its bounds) for mid.

moveSplitLineSet

private void moveSplitLineSet(SplitLine currRoot,
                              SplitAxis.MovingSplitLine[] toMove,
                              java.util.Hashtable transitions,
                              int numSteps)
This moves an array of split lines whose final positions have been specified through user interation. The array is toMove[]. This is a recursive function. On the first call, currRoot should always be the root of the tree. Note that the MovingSplitLine class is a simple wrapper class (inner class of SplitAxis) that wraps a SplitLine object with a double finalPosition.

Parameters:
currRoot - The root of the tree on the first call, left or right descends on recursive calls
toMove - The array of split lines with computed final absolute positions (specified by user or stuck lines)
transitions - The hashtable containing a list of SplitTransition objects that will be used to queue animations later.
numSteps - The number of steps of animation.

lessThan

public boolean lessThan(SplitLine baseLine,
                        SplitLine comparator)
Returns true if baseLine is previous to comparator O(2 log n)

Parameters:
baseLine - split line to test
comparator - second split line to compare
Returns:
true if baseline < comparator

greaterThan

public boolean greaterThan(SplitLine baseLine,
                           SplitLine comparator)
Returns true if baseLine is a successor to comparator O(2 log n)

Parameters:
baseLine - split line to test
comparator - second split line to compare
Returns:
true if baseline > comparator

setBounds

private void setBounds(SplitLine line)
Depending on whether line is a left or right child node, set the opBound value of line to be the left or right bound.

Parameters:
line - Split line to repair, will get new opbound value

getRoot

public SplitLine getRoot()
Gets the root split line for this axis.

Returns:
current root node of this tree.

getBounds

public SplitLine[] getBounds(SplitLine line,
                             int framenum)
Retrieve left and right first bounds into an array. NOTE: this returns cached bound values.

Parameters:
line - split line to get bounds from.
framenum - current frame number.
Returns:
array of size 2 containing left and right bounds respectively. Uses helper functions.

isReal

public boolean isReal(SplitLine line)
Some split lines are 'fake' leaf lines that are created to be loaded into the partitioned set. This detects "fake" leaf lines.

Parameters:
line - Line to be tested.
Returns:
true if the line is real, otherwise false if it is a fake leaf

getMinBound

public SplitLine getMinBound(SplitLine line,
                             int framenum)
Retrieve the given line's left (min) Split Line bound. The bound is either the parent of this line, or the opbound (off parent bound).

Parameters:
line - Line to get min bound of.
framenum - Current frame number.
Returns:
Split line that is either the parent, the min stuck line, or the opbound of this line. Null on error.

getMinBoundI

public int getMinBoundI(SplitLine line,
                        int framenum)
Get the index of the min bound split line for the given line.

Parameters:
line - Line to get min bound of.
framenum - Current frame number.
Returns:
Index of split line returned by getMinBound(SplitLine, int).

getMaxBound

public SplitLine getMaxBound(SplitLine line,
                             int framenum)
Retrieve the given line's right (max) Split Line bound. The bound is either the parent of this line, or the opbound (off parent bound).

Parameters:
line - Line to get max bound of.
framenum - Current frame number.
Returns:
Split line that is either the parent, the max stuck line, or the opbound of this line. Null on error.

getMaxBoundI

public int getMaxBoundI(SplitLine line,
                        int framenum)
Get the index of the max bound split line for the given line.

Parameters:
line - Line to get max bound of.
framenum - Current frame number.
Returns:
Index of split line returned by getMaxBound(SplitLine, int).

computeRightBound

private SplitLine computeRightBound(SplitLine line)
Computes and Returns line's first right bound. NOTE: YOU SHOULD USE getRightBound to retrieve cached version, this is only for initialization or verification/debugging. O(log n)

Parameters:
line - Line to compute right (max) bound of.
Returns:
first right bound, possibly the 'virtual' max stuck position. Null if you pass in a null line.

computeLeftBound

private SplitLine computeLeftBound(SplitLine line)
Computes and returns line's first left bound. NOTE: YOU SHOULD USE getLeftBound to retrieve cached version, this is only for initialization or verification/debugging. O(log n).

Parameters:
line - Line to compute left (min) bound of.
Returns:
first left bound, possibly the 'virtual' min stuck position. Null if you pass in a null line.

getPartitionedList

public java.util.TreeSet getPartitionedList()
Get the partitioned list, the list created prior to rendering to determine the visible objects and culling limit.

Returns:
Returns the partitionedList.

getSize

public int getSize()
Get the number of split lines on the axis, not including min and max stuck lines.

Returns:
number of splitlines on this axis, does not include minStuckLine or maxStuckLine

print

protected static final void print(java.lang.String s)
Error printing function, displays string in stderr.

Parameters:
s - String to send to stderr, shortcut for System.err.println(String).

toString

public java.lang.String toString()
String output routine for splitaxes, displays SplitLine.toLongString() for root of axis.

Overrides:
toString in class java.lang.Object
Returns:
String value for root.toLongString().

updateSubtreeSize

public void updateSubtreeSize(SplitLine currRoot)
Recursively update the size of subtrees under the given current split line. O(n) operation, currRoot is initially the root node.

Parameters:
currRoot - Current split line being updated

iterator

public java.util.Iterator<SplitLine> iterator()
Returns an iterator over the axis. Note that this iterator contains the minStuckLine and maxStuckLine. Uses the AxisIterator internal class.

Returns:
new AxisIterator object for this set of split lines.