Changeset 2284


Ignore:
Timestamp:
02/15/07 15:41:59 (13 years ago)
Author:
sorber
Message:

New classes for drawing polylines. Typos and small changes.

Location:
trunk/loci/visbio/overlays
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/overlays/OverlayFreeform.java

    r2096 r2284  
    2424package loci.visbio.overlays; 
    2525 
    26 import java.rmi.RemoteException; 
    27 import java.util.Arrays; 
     26//import java.util.Arrays; 
    2827import visad.*; 
    29 import loci.visbio.util.MathUtil; 
    3028 
    3129/** 
    3230 * OverlayFreeform is a freeform overlay. 
    33  * @author Greg Meyer 
    3431 */ 
    3532 
    36 public class OverlayFreeform extends OverlayObject { 
     33public class OverlayFreeform extends OverlayNodedObject { 
    3734 
    3835  // -- Constructors -- 
     
    4542    float x1, float y1, float x2, float y2) 
    4643  { 
    47     super(overlay); 
    48     this.x1 = x1; 
    49     this.y1 = y1; 
    50     this.x2 = x2; 
    51     this.y2 = y2; 
    52     hasNodes = true; 
    53     maxNodes = 100; 
    54     nodes = new float[2][maxNodes]; 
    55     Arrays.fill(nodes[0], x1); 
    56     Arrays.fill(nodes[1], y1); 
    57     numNodes = 1; 
    58     computeGridParameters(); 
    59     computeLength(); 
     44    super(overlay, x1, y1, x2, y2); 
    6045  } 
    6146 
     47  /** Constructs a freeform from an array of nodes */ 
    6248  public OverlayFreeform(OverlayTransform overlay, float[][] nodes) { 
    63     super(overlay); 
    64     x1=x2=y1=y2=0f; 
    65     hasNodes = true; 
    66     this.nodes = nodes; 
    67     numNodes = nodes[0].length; 
    68     maxNodes = nodes[0].length; 
    69     updateBoundingBox(); 
    70     computeGridParameters(); 
    71     computeLength(); 
     49    super(overlay, nodes); 
    7250  } 
    7351 
    7452  // -- OverlayObject API methods -- 
    7553 
    76   /** Gets VisAD data object representing this overlay. */ 
    77   public DataImpl getData() { 
     54  // -- Internal OverlayObject API methods -- 
     55 
     56  // -- Object API methods -- 
     57 
     58  /** Gets a short string representation of this freeform. */ 
     59  public String toString() { return "Freeform"; } 
     60   
     61  /** 
     62   * Computes a grid to be superimposed on this overlay 
     63   * to indicate it is currently selected. 
     64   */ 
     65  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     66 
     67  /** 
     68   * Computes a grid to be superimposed on this overlay to 
     69   * indicate it is currently selected. 
     70   * If the outline flag is set, computes only an outline instead. 
     71   */ 
     72  public DataImpl getSelectionGrid(boolean outline) { 
     73    return super.getSelectionGrid(outline); 
     74    /* 
     75    try { 
     76      RealType index = new RealType("index"); 
     77      Set indexSet = new Integer1DSet(index, numNodes); 
     78    } 
     79    catch (VisADException ex) {} 
     80    float[][] setSamples = nodes; 
     81 
    7882    RealTupleType domain = overlay.getDomainType(); 
    7983    TupleType range = overlay.getRangeType(); 
    80  
    81     float[][] setSamples = nodes; 
    82     float r = color.getRed() / 255f; 
    83     float g = color.getGreen() / 255f; 
    84     float b = color.getBlue() / 255f; 
     84    FunctionType indexXY = (index, domain); 
     85    FlatField(indexXY, indexSet); 
     86 
     87    System.out.println(domain); 
     88    System.out.println(range); 
     89    return null; 
     90    */ 
     91 
     92    /* 
     93    float[][] setSamples = new float[nodes.length][numNodes]; 
     94    setSamples[0][0] = nodes[0][0]; // for now 
     95    setSamples[1][0] = nodes[1][0]; 
     96    for (int j=1; j<numNodes-1; j++) { 
     97      float x = nodes[0][j]; 
     98      float y = nodes[1][j]; 
     99      float dx = nodes[0][j+1] - nodes[0][j-1]; 
     100      float dy = nodes[1][j+1] - nodes[1][j-1]; // slope of perpendicular 
     101      float r = (float) Math.sqrt(dx*dx + dy*dy); 
     102      float scale = 1.0f; 
     103      float newX =  x + scale * dy / r; 
     104      float newY = y + scale * dx / r; 
     105      setSamples[0][j] = newX; 
     106      setSamples[1][j] = newY; 
     107    } 
     108    setSamples[0][numNodes-1] = nodes[0][numNodes-1]; 
     109    setSamples[0][numNodes-1] = nodes[1][numNodes-1]; 
     110 
     111    Color yellow = Color.YELLOW; 
     112    float r = yellow.getRed() / 255f; 
     113    float g = yellow.getGreen() / 255f; 
     114    float b = yellow.getBlue() / 255f; 
     115 
     116    System.out.println ("r = " + r + " g = " + g + " b = " + b ); //TEMP  
    85117 
    86118    FlatField field = null; 
     
    108140    catch (RemoteException exc) { exc.printStackTrace(); } 
    109141    return field; 
     142 
     143    // Grid computation relies on parameters: 
     144    //   (xGrid1, yGrid1): top-left endpoint of grid rectangle 
     145    //   (xGrid2, yGrid2): top-right endpoint of grid rectangle 
     146    //   (xGrid3, yGrid3): bottom-left endpoint of grid rectangle 
     147    //   (xGrid4, yGrid4): bottom-right endpoint of grid rectangle 
     148    //     horizGridCount: number of horizontal dividing lines 
     149    //      vertGridCount: number of vertical dividing lines 
     150 
     151    /* 
     152    // compute (X, Y) values along grid left and right edges 
     153    int numLR = outline ? 2 : (horizGridCount + 2); 
     154    float[] xl = new float[numLR]; 
     155    float[] xr = new float[numLR]; 
     156    float[] yl = new float[numLR]; 
     157    float[] yr = new float[numLR]; 
     158    for (int i=0; i<numLR; i++) { 
     159      float q = (float) i / (numLR - 1); 
     160      xl[i] = q * (xGrid3 - xGrid1) + xGrid1; 
     161      xr[i] = q * (xGrid4 - xGrid2) + xGrid2; 
     162      yl[i] = q * (yGrid3 - yGrid1) + yGrid1; 
     163      yr[i] = q * (yGrid4 - yGrid2) + yGrid2; 
     164    } 
     165 
     166    // compute (X, Y) values along grid top and bottom edges 
     167    int numTB = outline ? 2 : (vertGridCount + 2); 
     168    float[] xt = new float[numTB]; 
     169    float[] xb = new float[numTB]; 
     170    float[] yt = new float[numTB]; 
     171    float[] yb = new float[numTB]; 
     172    for (int i=0; i<numTB; i++) { 
     173      float q = (float) i / (numTB - 1); 
     174      xt[i] = q * (xGrid2 - xGrid1) + xGrid1; 
     175      xb[i] = q * (xGrid4 - xGrid3) + xGrid3; 
     176      yt[i] = q * (yGrid2 - yGrid1) + yGrid1; 
     177      yb[i] = q * (yGrid4 - yGrid3) + yGrid3; 
     178    } 
     179 
     180    RealTupleType domain = overlay.getDomainType(); 
     181    TupleType range = overlay.getRangeType(); 
     182 
     183    // compute zig-zagging grid mesh values 
     184    int count = 2 * (numLR + numTB) - 1; 
     185    float[][] setSamples = new float[2][count]; 
     186    for (int i=0; i<numLR; i++) { 
     187      int ndx = 2 * i; 
     188      boolean dir = i % 2 == 0; 
     189      setSamples[0][ndx] = dir ? xl[i] : xr[i]; 
     190      setSamples[1][ndx] = dir ? yl[i] : yr[i]; 
     191      setSamples[0][ndx + 1] = dir ? xr[i] : xl[i]; 
     192      setSamples[1][ndx + 1] = dir ? yr[i] : yl[i]; 
     193    } 
     194    boolean leftToRight = numLR % 2 == 0; 
     195    for (int i=0; i<numTB; i++) { 
     196      int ndx = 2 * (numLR + i) - 1; 
     197      boolean dir = i % 2 == 0; 
     198      int ii = leftToRight ? i : (numTB - i - 1); 
     199      setSamples[0][ndx] = dir ? xb[ii] : xt[ii]; 
     200      setSamples[1][ndx] = dir ? yb[ii] : yt[ii]; 
     201      setSamples[0][ndx + 1] = dir ? xt[ii] : xb[ii]; 
     202      setSamples[1][ndx + 1] = dir ? yt[ii] : yb[ii]; 
     203    } 
     204 
     205    // populate grid color values 
     206    Color c = outline ? Color.cyan : Color.yellow; 
     207    float r = c.getRed() / 255f; 
     208    float g = c.getGreen() / 255f; 
     209    float b = c.getBlue() / 255f; 
     210    float[][] fieldSamples = new float[4][count]; 
     211    for (int i=0; i<count; i++) { 
     212      fieldSamples[0][i] = r; 
     213      fieldSamples[1][i] = g; 
     214      fieldSamples[2][i] = b; 
     215      fieldSamples[3][i] = 1.0f; 
     216    } 
     217 
     218    // construct field 
     219    FlatField field = null; 
     220    try { 
     221      GriddedSet fieldSet = new Gridded2DSet(domain, 
     222        setSamples, setSamples[0].length, null, null, null, false); 
     223      FunctionType fieldType = new FunctionType(domain, range); 
     224      field = new FlatField(fieldType, fieldSet); 
     225      field.setSamples(fieldSamples, false); 
     226    } 
     227    catch (VisADException exc) { exc.printStackTrace(); } 
     228    catch (RemoteException exc) { exc.printStackTrace(); } 
     229    return field; 
     230    */ 
    110231  } 
    111232 
    112   /** 
    113    * Computes the shortest distance from this 
    114    * object's bounding box to the given point. 
    115    */ 
    116   public double getDistanceToBoundingBox(double x, double y) { 
    117     double xdist = 0; 
    118     if (x < x1 && x < x2) xdist = Math.min(x1, x2) - x; 
    119     else if (x > x1 && x > x2) xdist = x - Math.max(x1, x2); 
    120     double ydist = 0; 
    121     if (y < y1 && y < y2) ydist = Math.min(y1, y2) - y; 
    122     else if (y > y1 && y > y2) ydist = y - Math.max(y1, y2); 
    123     return Math.sqrt(xdist * xdist + ydist * ydist); 
    124   } 
    125  
    126   /** Compute the shortest distance from this object to the given point */ 
    127   public double getDistance (double x, double y) { 
    128      double[] distSegWt = MathUtil.getDistSegWt(nodes, (float) x, (float) y); 
    129      return distSegWt[0]; 
    130   } 
    131  
    132   /** Retrieves useful statistics about this overlay. */ 
    133   public String getStatistics() { 
    134     return "Bounds = (" + x1 + ", " + y1 + "), (" + x2 + ", " + y2 + ")\n" + 
    135       "Number of Nodes = " + numNodes + "\n" + 
    136       "Curve Length = " + (float) curveLength + "\n"; 
    137   } 
    138  
    139   /** True iff this overlay has an endpoint coordinate pair. */ 
    140   public boolean hasEndpoint() { return true; } 
    141  
    142   /** True iff this overlay has a second endpoint coordinate pair. */ 
    143   public boolean hasEndpoint2() { return true; } 
    144  
    145   /** True iff this overlay supports the filled parameter. */ 
    146   public boolean canBeFilled() { return true; } 
    147  
    148   // -- Internal OverlayObject API methods -- 
    149  
    150   /** Computes parameters needed for selection grid computation. */ 
    151   protected void computeGridParameters() { 
    152     float padding = 0.02f * overlay.getScalingValue(); 
    153     boolean flipX = x2 < x1; 
    154     float xx1 = flipX ? (x1 + padding) : (x1 - padding); 
    155     float xx2 = flipX ? (x2 - padding) : (x2 + padding); 
    156     boolean flipY = y2 < y1; 
    157     float yy1 = flipY ? (y1 + padding) : (y1 - padding); 
    158     float yy2 = flipY ? (y2 - padding) : (y2 + padding); 
    159  
    160     xGrid1 = xx1; yGrid1 = yy1; 
    161     xGrid2 = xx2; yGrid2 = yy1; 
    162     xGrid3 = xx1; yGrid3 = yy2; 
    163     xGrid4 = xx2; yGrid4 = yy2; 
    164     horizGridCount = 3; vertGridCount = 3; 
    165   } 
    166  
    167   // -- Object API methods -- 
    168  
    169   /** Gets a short string representation of this freeform. */ 
    170   public String toString() { return "Freeform"; } 
    171  
    172233} 
  • trunk/loci/visbio/overlays/OverlayIO.java

    r2096 r2284  
    260260          if (obj == null) continue; 
    261261 
    262           boolean hasNodes = false; 
    263           if (obj instanceof OverlayFreeform) { 
    264             loadedFreeforms.add(obj); 
    265             hasNodes = true; 
    266           } 
     262          if (obj instanceof OverlayFreeform) loadedFreeforms.add(obj); 
    267263 
    268264          int r = MathUtil.positionToRaster(lengths, pos); 
     
    285281          obj.group = group; 
    286282          obj.notes = notes; 
    287           obj.hasNodes = hasNodes; // necessary to distinguish freeforms 
    288283          obj.drawing = false; 
    289284          obj.selected = false; 
  • trunk/loci/visbio/overlays/OverlayObject.java

    r2254 r2284  
    2626import java.awt.Color; 
    2727import java.rmi.RemoteException; 
    28 import java.util.Arrays; 
    2928import visad.*; 
    30 import loci.visbio.util.MathUtil; 
    3129 
    3230/** OverlayObject is the superclass of all overlay objects. */ 
     
    4139  protected float x1, y1, x2, y2; 
    4240 
    43   /** Node array (for freeforms with intermediate points). */ 
    44   protected float[][] nodes; 
    45   protected int numNodes, maxNodes; 
    46   protected boolean hasNodes; 
    47  
    4841  /** Text string to render. */ 
    4942  protected String text; 
     
    8174  /** Number of horizontal and vertical dividing lines for selection grid. */ 
    8275  protected int horizGridCount, vertGridCount; 
    83  
    84   /** Length of curve of a noded object */ 
    85   protected double curveLength; 
    8676 
    8777  // -- Constructor -- 
     
    10090  /** Computes the shortest distance from this overlay to the given point. */ 
    10191  public abstract double getDistance(double x, double y); 
    102   //ACS TODO make sure this checks out in OverlayFreeform 
    10392 
    10493  /** Retrieves useful statistics about this overlay. */ 
     
    120109 
    121110  /** True iff this overlay can be resized using X1, X2, Y1, Y2 entry boxes */ 
    122   public boolean areBoundsEditable() { return !hasNodes; } 
    123   // currently, only noded objects can't be resized this way. 
     111  public boolean areBoundsEditable() { return true; } 
     112  // currently, only non-noded objects can be resized this way. 
    124113  // (Actually could perform some rad scaling on all nodes) 
    125114 
     
    244233  public void setCoords(float x1, float y1) { 
    245234    if (!hasEndpoint()) return; 
    246     float dx = x1-this.x1; 
    247     float dy = y1-this.y1; 
    248235    this.x1 = x1; 
    249236    this.y1 = y1; 
    250     if (hasNodes) { 
    251       for (int i=0; i<numNodes; i++) { 
    252         nodes[0][i] = nodes[0][i]+dx; 
    253         nodes[1][i] = nodes[1][i]+dy; 
    254       } 
    255     } 
    256     computeGridParameters(); 
    257   } 
    258  
    259   /** Returns coordinates of node at given index in the node array */ 
    260   public float[] getNodeCoords (int index) { 
    261     float[] retvals = new float[2]; 
    262     if (index < numNodes && index >= 0) { 
    263       retvals[0] = nodes[0][index]; 
    264       retvals[1] = nodes[1][index]; 
    265     } else { 
    266       retvals[0] = -1f; 
    267       retvals[1] = -1f; 
    268     } 
    269     return retvals; 
    270   } 
    271  
    272   /** Returns the node array */ 
    273   public float[][] getNodes() { return nodes; } 
    274  
    275   /** Returns the number of real nodes in the array */ 
    276   public int getNumNodes() { return numNodes; } 
    277  
    278   /** Returns total number of nodes in array */ 
    279   public int getMaxNodes() { return maxNodes; } 
    280  
     237    computeGridParameters(); 
     238  } 
     239   
    281240  /** Gets X coordinate of the overlay's first endpoint. */ 
    282241  public float getX() { return x1; } 
     
    285244  public float getY() { return y1; } 
    286245 
    287   /** Gets most recent x-coordinate in node array. */ 
    288   public float getLastNodeX() { 
    289     return nodes[0][numNodes-1]; 
    290   } 
    291  
    292   /** Gets most recent y-coordinate in node array. */ 
    293   public float getLastNodeY() { 
    294     return nodes[1][numNodes-1]; 
    295   } 
    296  
    297   /** Sets the node array to that provided--for loading from saved */ 
    298   public void setNodes(float[][] nodes) { 
    299     this.nodes = nodes; 
    300     numNodes = nodes[0].length; 
    301     maxNodes = numNodes; 
    302     computeLength(); 
    303     updateBoundingBox(); 
    304     computeGridParameters(); 
    305   } 
    306  
    307   /** Changes X coordinate of the overlay's second endpoint. */ 
     246   /** Changes X coordinate of the overlay's second endpoint. */ 
    308247  public void setX2(float x2) { 
    309248    if (!hasEndpoint2()) return; 
     
    333272  public float getY2() { return y2; } 
    334273 
    335   /** Updates the coordinates of the bounding box of a noded object */ 
    336   public void updateBoundingBox() { 
    337     if (!hasNodes || numNodes == 0) return; 
    338     float xmin, xmax, ymin, ymax; 
    339     xmin = xmax = nodes[0][0]; 
    340     ymin = ymax = nodes[1][0]; 
    341     for (int i=1; i < numNodes; i++) { 
    342       if (nodes[0][i] < xmin) xmin = nodes[0][i]; 
    343       if (nodes[0][i] > xmax) xmax = nodes[0][i]; 
    344       if (nodes[1][i] < ymin) ymin = nodes[1][i]; 
    345       if (nodes[1][i] > ymax) ymax = nodes[1][i]; 
    346     } 
    347     this.x1 = xmin; 
    348     this.y1 = ymin; 
    349     this.x2 = xmax; 
    350     this.y2 = ymax; 
    351   } 
    352  
    353274  /** Changes text to render. */ 
    354275  public void setText(String text) { 
     
    401322  /** Gets whether this overlay is still being initially drawn. */ 
    402323  public boolean isDrawing() { return drawing; } 
    403  
    404   /** Gets length of curve */ 
    405   public double getCurveLength() { return curveLength; } 
    406  
    407   /** Sets length of curve */ 
    408   public void setCurveLength(double len) { curveLength = len; } 
    409  
    410   /** Computes length of curve */ 
    411   public void computeLength() { 
    412     if (maxNodes != numNodes) truncateNodeArray(); 
    413     double length = 0; 
    414     for (int i=0; i<numNodes-1; i++) { 
    415       double[] a = {(double) nodes[0][i], (double)nodes[1][i]}; 
    416       double[] b = {(double) nodes[0][i+1], (double) nodes[1][i+1]}; 
    417       length += MathUtil.getDistance(a, b); 
    418     } 
    419     this.curveLength = length; 
    420   } 
    421  
    422   // -- OverlayObject API Methods: node array mutators -- 
    423   // note: call updateBoundingBox() after a series of changes to the node array 
    424  
    425   /** Sets coordinates of an existing node */ 
    426   public void setNodeCoords(int nodeIndex, float newX, float newY) { 
    427     if (nodeIndex >= 0 && nodeIndex < numNodes) { 
    428       nodes[0][nodeIndex] = newX; 
    429       nodes[1][nodeIndex] = newY; 
    430     } 
    431     else { 
    432       //TEMP: 
    433       //System.out.println("Out of bounds error. Can't reset node coordinates"); 
    434     } 
    435   } 
    436  
    437   /** Prints node array of current freeform; for debugging */ 
    438   private void printNodes(float[][] nodes) { 
    439     System.out.println("Printing nodes..."); 
    440     for (int i = 0; i < nodes[0].length; i++){ 
    441       System.out.println(i+":("+nodes[0][i]+","+nodes[1][i]+")"); 
    442     } 
    443   } 
    444  
    445   /** Sets next node coordinates. */ 
    446   public void setNextNode(float x, float y) { 
    447     //System.out.println("OverlayObject.setNextNode(...) called. " + 
    448     //  "numNodes = " + numNodes + ", maxNodes = " + maxNodes); 
    449     //printNodes(getNodes()); 
    450     if (numNodes >= maxNodes) { 
    451       maxNodes *= 2; 
    452       nodes = resizeNodeArray(nodes, maxNodes); 
    453     } 
    454     Arrays.fill(nodes[0], numNodes, maxNodes, x); 
    455     Arrays.fill(nodes[1], numNodes++, maxNodes, y); 
    456     // i.e., set all remaining nodes (as per maxNodes) to next node coords 
    457   } 
    458  
    459   /** 
    460    * Inserts a node at coordinates provided 
    461    * before the node at the index provided. 
    462    */ 
    463   public void insertNode(int index, float x, float y) { 
    464     if (index >= 0 && index < numNodes) { 
    465       // if array is full, make some more room. 
    466       if (numNodes >= maxNodes) { // numNodes should never exceed maxNodes but.. 
    467         maxNodes *= 2; 
    468         nodes = resizeNodeArray(nodes, maxNodes); 
    469       } 
    470       for (int j = 0; j < 2; j++) { 
    471         for (int i = numNodes; i > index; i--) { 
    472           // right shift every node right of index by 1 
    473           nodes[j][i] = nodes[j][i-1]; 
    474         } 
    475       } 
    476       nodes[0][index] = x; 
    477       nodes[1][index] = y; 
    478       numNodes++; 
    479     } 
    480     else { 
    481       //System.out.println("index not in range (0, numNodes). " + 
    482       //  "No node inserted"); 
    483     } 
    484   } 
    485  
    486   /** Deletes a range of nodes from the node array */ 
    487   public void deleteBetween (int i1, int i2) { 
    488     // assumes i1 < i2, both in bounds (less than numNodes) 
    489     // checks whether i1 + 1 < i2, i.e., is there a non-zero 
    490     // number of nodes to delete 
    491     if (0 <= i1 && i2 < numNodes && i1 + 1 < i2 ) { 
    492       int victims = i2 - i1 - 1; 
    493       float[][] newNodes = new float[2][maxNodes - victims]; 
    494       System.arraycopy(nodes[0], 0, newNodes[0], 0, i1 + 1); 
    495       System.arraycopy(nodes[1], 0, newNodes[1], 0, i1 + 1); 
    496       System.arraycopy(nodes[0], i2, newNodes[0], i1+1, maxNodes - i2); 
    497       System.arraycopy(nodes[1], i2, newNodes[1], i1+1, maxNodes - i2); 
    498       numNodes -= victims; 
    499       maxNodes -= victims; 
    500       nodes = newNodes; 
    501       if (numNodes == 0) overlay.removeObject(this); 
    502       if (numNodes <= 1) overlay.removeObject(this); 
    503     } else { 
    504       //System.out.println("deleteBetween(int, int) out of bounds error"); 
    505     } 
    506   } 
    507  
    508   /** Deletes a node from the node array */ 
    509   public void deleteNode(int index) { 
    510     if (index >=0 && index < numNodes) { 
    511       // built-in truncation 
    512       //System.out.println("OverlayObject.deleteNode(" + index +") called. " + 
    513       //  "numNodes = " + numNodes + ", maxNodes = " + maxNodes); 
    514       float [][] newNodes =  new float[2][numNodes-1]; 
    515       System.arraycopy(nodes[0], 0, newNodes[0], 0, index); 
    516       System.arraycopy(nodes[0], index+1, newNodes[0], index, numNodes-index-1); 
    517       System.arraycopy(nodes[1], 0, newNodes[1], 0, index); 
    518       System.arraycopy(nodes[1], index+1, newNodes[1], index, numNodes-index-1); 
    519       numNodes--; 
    520       maxNodes = numNodes; 
    521       nodes = newNodes; 
    522  
    523       if (numNodes == 0) { 
    524         //System.out.println("destroying " + this); 
    525         overlay.removeObject(this); 
    526       } 
    527       if (numNodes <= 1) overlay.removeObject(this); 
    528     } 
    529   } 
    530  
    531   /** Reverses the node array (and therefore its internal orientation) */ 
    532   public void reverseNodes() { 
    533     truncateNodeArray(); 
    534     // Q: Is the above call ever necessary? 
    535     // truncateNodeArray() is called at mouseUp in FreeformTool. 
    536     // Will there ever be an extension 
    537     // of the node array s.t. maxNodes > numNodes during an interior edit before 
    538     // an extension 
    539     // A: Yes, if extend mode is entered directly from edit mode 
    540     float[][] temp = new float[2][maxNodes]; 
    541     for (int j = 0; j < 2; j++) { 
    542       for (int i = 0; i < maxNodes; i++) { 
    543         temp[j][maxNodes-i-1] = nodes[j][i]; 
    544       } 
    545     } 
    546     nodes = temp; 
    547   } 
    548  
    549   /** Deletes buffer nodes from the tail of the node array */ 
    550   public void truncateNodeArray() { 
    551     nodes = resizeNodeArray(nodes, numNodes); 
    552   } 
    553  
    554   /** Resizes the node array, truncating if necessary. */ 
    555   protected float[][] resizeNodeArray(float[][] a, int newLength) { 
    556     //System.out.println("resizing node array to "+ newLength); // TEMP 
    557     int loopMax = Math.min(a[0].length, newLength); 
    558     float[][] a2 = new float[2][newLength]; 
    559     for (int j=0; j<2; j++) { //manually copy a to a2 
    560       for (int i=0; i<loopMax; i++) { 
    561         a2[j][i] = a[j][i]; 
    562       } 
    563       // case where newLength > a.length: 
    564       // fills rest of new array with nodes co-locational with last node 
    565       for (int i=loopMax; i < a2[0].length; i++) { 
    566         a2[j][i] = a[j][loopMax-1]; 
    567       } 
    568     } 
    569     maxNodes = newLength; 
    570     //System.out.println("resize completed. maxNodes = " + 
    571     //  maxNodes + " numNodes =  " + numNodes); 
    572     return a2; 
    573   } 
    574324 
    575325  // -- Internal OverlayObject API methods -- 
Note: See TracChangeset for help on using the changeset viewer.