Changeset 1384


Ignore:
Timestamp:
08/29/06 15:30:21 (14 years ago)
Author:
greg
Message:

Initial version of freeform line overlay type.

Location:
trunk/loci/visbio/overlays
Files:
4 added
2 edited

Legend:

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

    r1264 r1384  
    2626import java.awt.Color; 
    2727import java.rmi.RemoteException; 
     28import java.util.Arrays; 
    2829import visad.*; 
    2930 
     
    3839  /** Endpoint coordinates. */ 
    3940  protected float x1, y1, x2, y2; 
    40  
     41   
     42  /** Node array (for freeforms with intermediate points) */ 
     43  protected float[][] nodes;  
     44  protected int numNodes, maxNodes; 
     45  protected boolean hasNodes; 
     46  
    4147  /** Text string to render. */ 
    4248  protected String text; 
     
    229235  public void setCoords(float x1, float y1) { 
    230236    if (!hasEndpoint()) return; 
     237    float dx = x1-this.x1; 
     238    float dy = y1-this.y1; 
    231239    this.x1 = x1; 
    232240    this.y1 = y1; 
     241    if (hasNodes) { 
     242        for (int i=0; i<numNodes; i++) { 
     243            nodes[0][i] = nodes[0][i]+dx; 
     244            nodes[1][i] = nodes[1][i]+dy; 
     245        } 
     246    } 
    233247    computeGridParameters(); 
    234248  } 
     
    239253  /** Gets Y coordinate of the overlay's first endpoint. */ 
    240254  public float getY() { return y1; } 
     255 
     256  /** Gets most recent x-coordinate in node array */ 
     257  public float getLastNodeX() { 
     258    return nodes[0][numNodes-1]; 
     259  } 
     260   
     261  /** Gets most recent y-coordinate in node array */ 
     262  public float getLastNodeY() { 
     263    return nodes[1][numNodes-1]; 
     264  } 
     265 
     266  /** Sets next node coordinates */ 
     267  public void setNextNode(float x, float y) { 
     268    if (numNodes >= maxNodes) { 
     269        maxNodes *= 2; 
     270        nodes = resizeNodeArray(nodes,maxNodes); 
     271    } 
     272    Arrays.fill(nodes[0],numNodes,maxNodes,x); 
     273    Arrays.fill(nodes[1],numNodes++,maxNodes,y); 
     274  } 
     275   
     276  public void truncateNodeArray() { 
     277    nodes = resizeNodeArray(nodes,numNodes); 
     278  } 
    241279 
    242280  /** Changes X coordinate of the overlay's second endpoint. */ 
     
    267305  /** Gets Y coordinate of the overlay's second endpoint. */ 
    268306  public float getY2() { return y2; } 
    269  
     307   
     308  /** Gets value of largest and smallest x,y values. */ 
     309  protected void setBoundaries(float x, float y) { 
     310    x1 = Math.min(x1,x); 
     311    x2 = Math.max(x2,x); 
     312    y1 = Math.min(y1,y); 
     313    y2 = Math.max(y2,y); 
     314  } 
     315  
    270316  /** Changes text to render. */ 
    271317  public void setText(String text) { 
     
    318364  /** Gets whether this overlay is still being initially drawn. */ 
    319365  public boolean isDrawing() { return drawing; } 
    320  
    321  
     366   
    322367  // -- Internal OverlayObject API methods -- 
    323368 
    324369  /** Computes parameters needed for selection grid computation. */ 
    325370  protected abstract void computeGridParameters(); 
     371   
     372  /** Resizes the node array, truncating if necessary. */ 
     373  protected float[][] resizeNodeArray(float[][] A, int newLength) { 
     374        int loopMax = Math.min(A[0].length,newLength); 
     375        float[][] A2 = new float[2][newLength]; 
     376        for (int j=0; j<2; j++) { 
     377            for (int i=0; i<loopMax; i++) { 
     378                A2[j][i] = A[j][i]; 
     379            } 
     380        } 
     381        return A2;       
     382  } 
    326383 
    327384} 
  • trunk/loci/visbio/overlays/OverlayWidget.java

    r1264 r1384  
    151151      new PointerTool(overlay), 
    152152      new LineTool(overlay), 
     153      new FreeformTool(overlay), 
    153154      new MarkerTool(overlay), 
    154155      new TextTool(overlay), 
Note: See TracChangeset for help on using the changeset viewer.