Example #1
0
  /**
   * Generate a list of line segments that construct a dendogram of the tree rooted at node tn.
   *
   * @param tn the root of the tree
   * @return the segements comprising the dendogram
   */
  private double[] dendogram(TreeNode tn) {
    double distance = 0.;
    nodemap = new TreeNode[getNodeCount(tn)];
    int[] leafmap = new int[getLeafCount(tn)]; // record order of rows
    int[] nodeidx = new int[1];
    double[] segs = null;
    double[] childpos = new double[2];

    nodeidx[0] = 0;
    if (tn instanceof Cluster) {
      distance = ((Cluster) tn).getSimilarity();
    } else {
      distance = ((DefaultMutableTreeNode) tn).getDepth();
    }
    segs = new double[getNodeCount(tn) * 8];
    // start recursive depth first traversal
    traverse(tn, 0, distance, nodeidx, nodemap, leafmap, segs, childpos);
    // set map of row index to leafnode ordinal
    idxMap.setIndex(leafmap);
    return segs;
  }