Class gpjpp.GPGenePrint
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gpjpp.GPGenePrint

java.lang.Object
   |
   +----gpjpp.GPObject
           |
           +----gpjpp.GPContainer
                   |
                   +----gpjpp.GPGene
                           |
                           +----gpjpp.GPGenePrint

public class GPGenePrint
extends GPGene
Formats a gene tree for printing in graphic or pseudo-graphic format. GPGenePrint extends GPGene to add an x position which it computes by spreading out the nodes of the tree just enough to prevent them from overlapping at all levels of the tree. Note that GPGenePrint formats just a single branch of a complete GP, which would frequently be too wide to print on standard paper.

The three key methods of the class are the constructor, GPGenePrint(GPGene), which clones a GPGene tree onto a new tree with the extra fields, printOn(), which prints the tree in pseudo-graphic format to a PrintStream, and drawOn(), which prints the tree as a true graphic gif file.

Several static public fields of the class can be used to adjust the appearance of the tree: xMargin, xSpacing, rectMargin, arcRadius, rowsPerNode.

Version:
1.0

Variable Index

 o arcRadius
The pixel radius of the arc at each corner of a node rectangle.
 o peer
A reference to the original gene of which the GPGenePrint object is an extended copy.
 o rectMargin
The number of pixels separating the node rectangle from the node text that it surrounds in a graphic tree.
 o rowsPerNode
The number of character heights per node level in a graphic tree.
 o x
The computed x position of this node, in character units.
 o xMargin
The number of blank columns printed at the left edge of the tree by printOn().
 o xSpacing
The minimum number of columns (character widths) that separate adjacent nodes.

Method Index

 o adjustOverlaps(double[], double[], int)
Adjusts the x coordinate of this node and its children whenever the node overlaps the region of the node to its left.
 o calcContainerCenter()
Returns the x coordinate of the horizontal center of the arguments to this node at their current positions.
 o calcMaxX()
Returns the largest x value anywhere in the tree.
 o calcMaxX(double)
Returns the largest x value anywhere in the tree.
 o calcMinX()
Returns the smallest x value anywhere in the tree.
 o calcMinX(double)
Returns the smallest x value anywhere in the tree.
 o calcPackedContainerWidth()
Returns the minimum width of the arguments to this node taking into account the node width of each argument and the minimum spacing between nodes, xSpacing.
 o calcPackedPos(double[], int)
Calculates the x coordinates of all the nodes below this level assuming that all can be packed to minimum spacing and each container is centered under its parent.
 o calcXPositions()
Calculates the x coordinates of all nodes so that none overlap, otherwise-unconstrained nodes are evenly spaced, and parent nodes are centered over their children as much as possible.
 o clone()
Disables the cloning operation inherited from GPGene, since GPGenePrint does not need to be cloned.
 o drawGifNode(GPDrawing, int)
Draws all the nodes recursively starting with this one, including each node's text, a rounded rectangle surrounding it, and connectors to all of its children.
 o drawOn(GPDrawing, String, String, GPVariables)
Computes the x coordinates for all nodes in this gene tree and writes the tree in gif format to the specified file.
 o getNodeRight()
Returns the x coordinate of the right edge of the node text in characters.
 o getNodeWidth()
Returns the length of the node representation string in characters.
 o hBox(GPDrawing)
Computes the pixel height of the node rectangle.
 o isA()
Returns a code identifying the class.
 o load(DataInputStream)
Disables the load operation inherited from GPGene, since GPGenePrint does not need to be streamed.
 o printConnectors(PrintStream, int, int, double[])
Prints pseudo-graphic connectors between nodes at level depToPrint and nodes at level depToPrint+1.
 o printLevel(PrintStream, int, int, double[])
Prints all nodes at level depToPrint in left-to-right order.
 o printOn(PrintStream, GPVariables)
Computes the x coordinates for all nodes in this gene tree and writes the tree in pseudo-graphic format to the specified PrintStream.
 o save(DataOutputStream)
Disables the save operation inherited from GPGene, since GPGenePrint does not need to be streamed.
 o shiftX(double)
Shifts the x coordinates of all nodes by subtracting dx.
 o spaceTo(PrintStream, int, double[], double)
Prints spaces until curX[curDepth] equals or exceeds rx.
 o spreadTerminals()
Spreads terminal nodes so that they are equally spaced within the boundaries of the container.
 o wBox(GPDrawing, String)
Computes the pixel width of the node rectangle given the string to appear within the rectangle.
 o xBox(GPDrawing, double)
Converts the x coordinate of a node to the corresponding x pixel position for the left edge of the surrounding node rectangle.
 o xText(GPDrawing, double)
Converts the x coordinate of a node to the corresponding x pixel position for the start of the node text.
 o yBox(GPDrawing, int)
Converts the depth of a node to the corresponding y pixel position for the top edge of the surrounding node rectangle.
 o yText(GPDrawing, int)
Converts the depth of a node to the corresponding y pixel position for the node text.

Variables

 o xMargin
  public static double xMargin
The number of blank columns printed at the left edge of the tree by printOn(). Default 2.
 o xSpacing
  public static double xSpacing
The minimum number of columns (character widths) that separate adjacent nodes. Default 3.
 o rectMargin
  public static int rectMargin
The number of pixels separating the node rectangle from the node text that it surrounds in a graphic tree. Default 2.
 o arcRadius
  public static int arcRadius
The pixel radius of the arc at each corner of a node rectangle. Default 10.
 o rowsPerNode
  public static int rowsPerNode
The number of character heights per node level in a graphic tree. Default 3.
 o x
  protected double x
The computed x position of this node, in character units. The number is non-negative when the algorithm is finished. It is a floating point number that is rounded to integer columns by printOn() and converted to integer pixels by drawOn().
 o peer
  protected GPGene peer
A reference to the original gene of which the GPGenePrint object is an extended copy. The purpose for peer is to call methods in a user subclass of GPGene. Specifically, GPGenePrint calls the geneRep() method of GPGene to get the string representation of each node. When the gene represents a randomly generated constant, geneRep() can return the constant value instead of the generic representation of the node type. See the Lawnmower problem for an example.

Methods

 o clone
  protected synchronized Object clone()
Disables the cloning operation inherited from GPGene, since GPGenePrint does not need to be cloned. This version of clone() always returns null.
Overrides:
clone in class GPGene
 o isA
  public byte isA()
Returns a code identifying the class. GPGenePrint is not stored in streams, but it is given the unique code GENEPRINTID just for completeness.
Overrides:
isA in class GPGene
 o load
  protected synchronized void load(DataInputStream is)
Disables the load operation inherited from GPGene, since GPGenePrint does not need to be streamed. This version of load() does nothing.
Overrides:
load in class GPGene
 o save
  protected void save(DataOutputStream os)
Disables the save operation inherited from GPGene, since GPGenePrint does not need to be streamed. This version of save() does nothing.
Overrides:
save in class GPGene
 o getNodeWidth
  protected double getNodeWidth()
Returns the length of the node representation string in characters.
See Also:
peer
 o getNodeRight
  protected double getNodeRight()
Returns the x coordinate of the right edge of the node text in characters.
 o calcPackedContainerWidth
  protected double calcPackedContainerWidth()
Returns the minimum width of the arguments to this node taking into account the node width of each argument and the minimum spacing between nodes, xSpacing.
 o calcContainerCenter
  protected double calcContainerCenter()
Returns the x coordinate of the horizontal center of the arguments to this node at their current positions.
 o calcPackedPos
  protected void calcPackedPos(double minX[],
                               int curDepth)
Calculates the x coordinates of all the nodes below this level assuming that all can be packed to minimum spacing and each container is centered under its parent. This is a first-order approximation to the final position but generally leads to overlaps between adjacent node groups. The x coordinate of this node must be initialized before calling calcPackedPos().
Parameters:
minX - an array holding the minimum x coordinate at each level of the tree. This array is updated for every node that is processed here.
curDepth - the current node depth, where the root of the tree is depth 0.
 o adjustOverlaps
  protected boolean adjustOverlaps(double minX[],
                                   double curX[],
                                   int curDepth)
Adjusts the x coordinate of this node and its children whenever the node overlaps the region of the node to its left. This spreads the nodes to the right just enough to get rid of overlaps. Two additional adjustments are also made: terminal nodes dangling at more than minimum spacing to the left or right of their node groups are tightened to minimum spacing; and parent nodes are recentered over their children after the other adjustments have been made.

This method is called repeatedly until no further adjustments are needed or an iteration limit is reached.

Parameters:
minX - an array holding the minimum x coordinate at each level of the tree. This array is updated for every node that is processed here.
curX - an array holding the largest x coordinate used by a node at each depth level so far. This allows the detection of overlaps.
curDepth - the current node depth, where the root of the tree is depth 0.
Returns:
true if the position of any node was adjusted.
 o spreadTerminals
  protected void spreadTerminals()
Spreads terminal nodes so that they are equally spaced within the boundaries of the container.
 o calcMinX
  protected double calcMinX()
Returns the smallest x value anywhere in the tree.
 o calcMinX
  protected double calcMinX(double minSoFar)
Returns the smallest x value anywhere in the tree.
 o calcMaxX
  protected double calcMaxX()
Returns the largest x value anywhere in the tree.
 o calcMaxX
  protected double calcMaxX(double maxSoFar)
Returns the largest x value anywhere in the tree.
 o shiftX
  protected void shiftX(double dx)
Shifts the x coordinates of all nodes by subtracting dx.
 o calcXPositions
  protected int calcXPositions()
Calculates the x coordinates of all nodes so that none overlap, otherwise-unconstrained nodes are evenly spaced, and parent nodes are centered over their children as much as possible. The minimum x value is 0.0 upon return.
Returns:
the depth of the tree.
 o spaceTo
  protected void spaceTo(PrintStream os,
                         int curDepth,
                         double curX[],
                         double rx)
Prints spaces until curX[curDepth] equals or exceeds rx.
 o printLevel
  protected void printLevel(PrintStream os,
                            int depToPrint,
                            int curDepth,
                            double curX[])
Prints all nodes at level depToPrint in left-to-right order. This forms one line of pseudo-graphic output.
 o printConnectors
  protected void printConnectors(PrintStream os,
                                 int depToPrint,
                                 int curDepth,
                                 double curX[])
Prints pseudo-graphic connectors between nodes at level depToPrint and nodes at level depToPrint+1.
 o printOn
  public void printOn(PrintStream os,
                      GPVariables cfg)
Computes the x coordinates for all nodes in this gene tree and writes the tree in pseudo-graphic format to the specified PrintStream. None of the configuration variables in cfg are used by default.
Overrides:
printOn in class GPGene
 o xText
  protected final int xText(GPDrawing ods,
                            double x)
Converts the x coordinate of a node to the corresponding x pixel position for the start of the node text.
 o yText
  protected final int yText(GPDrawing ods,
                            int depth)
Converts the depth of a node to the corresponding y pixel position for the node text.
 o xBox
  protected final int xBox(GPDrawing ods,
                           double x)
Converts the x coordinate of a node to the corresponding x pixel position for the left edge of the surrounding node rectangle.
 o yBox
  protected final int yBox(GPDrawing ods,
                           int depth)
Converts the depth of a node to the corresponding y pixel position for the top edge of the surrounding node rectangle.
 o wBox
  protected final int wBox(GPDrawing ods,
                           String nodeName)
Computes the pixel width of the node rectangle given the string to appear within the rectangle.
 o hBox
  protected final int hBox(GPDrawing ods)
Computes the pixel height of the node rectangle.
 o drawGifNode
  protected void drawGifNode(GPDrawing ods,
                             int curDepth)
Draws all the nodes recursively starting with this one, including each node's text, a rounded rectangle surrounding it, and connectors to all of its children.
 o drawOn
  public void drawOn(GPDrawing ods,
                     String fname,
                     String title,
                     GPVariables cfg) throws IOException
Computes the x coordinates for all nodes in this gene tree and writes the tree in gif format to the specified file.
Parameters:
ods - a surface to draw on.
fname - the name of a gif file to create.
title - a title to draw on the image, usually "RPB", "ADF0", etc. The title is always placed on the first row of the drawing, to the left of the root node if possible, otherwise at the right edge of the image.
cfg - a set of global configuration variables. Only the TreeFontSize variable is used here, to set the font size for text within the image.
Overrides:
drawOn in class GPGene

All Packages  Class Hierarchy  This Package  Previous  Next  Index