Changeset 2524


Ignore:
Timestamp:
03/30/07 16:29:49 (13 years ago)
Author:
sorber
Message:

Added (preliminary) new, translucent selection layers to all overlays

Location:
trunk/loci/visbio/overlays
Files:
12 edited

Legend:

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

    r2024 r2524  
    2424package loci.visbio.overlays; 
    2525 
     26import java.awt.Color; 
    2627import java.rmi.RemoteException; 
    2728import java.util.Arrays; 
     
    8889    catch (VisADException exc) { exc.printStackTrace(); } 
    8990 
    90     float r = color.getRed() / 255f; 
    91     float g = color.getGreen() / 255f; 
    92     float b = color.getBlue() / 255f; 
     91    Color col = selected ? GLOW_COLOR : color;  
     92    float r = col.getRed() / 255f; 
     93    float g = col.getGreen() / 255f; 
     94    float b = col.getBlue() / 255f; 
     95     
    9396    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    9497    Arrays.fill(rangeSamples[0], r); 
     
    112115    return MathUtil.getDistance(new double[] {x1, y1}, 
    113116      new double[] {x2, y2}, new double[] {x, y}, true); 
     117  } 
     118 
     119  /** Gets a selection grid for this object */ 
     120  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     121 
     122  /** Gets a selection grid for this object */ 
     123  public DataImpl getSelectionGrid(boolean outline) { 
     124    if (outline) return super.getSelectionGrid(true); 
     125 
     126    RealTupleType domain = overlay.getDomainType(); 
     127    TupleType range = overlay.getRangeType(); 
     128 
     129    // compute corners of arrow tail 
     130    float padding = 0.02f * overlay.getScalingValue(); 
     131    double xx = x2 - x1; 
     132    double yy = y2 - y1; 
     133    double dist = Math.sqrt(xx * xx + yy * yy); 
     134    double mult = padding / dist; 
     135    float qx = (float) (mult * xx); 
     136    float qy = (float) (mult * yy); 
     137 
     138    // determine internal coordinate sys. basis vectors 
     139    // assuming arrow is oriented like this: 
     140    // 
     141    // (x1, y1) <--------{{{ (x2, y2) 
     142    // 
     143    // 
     144    double[] x = {xx / dist, yy / dist}; 
     145    double[] y = {-yy / dist, xx /dist}; 
     146 
     147    // arrow lengths: 
     148    double a, b, c; 
     149    a = Math.sqrt(qx * qx + qy * qy); 
     150    b = dist; 
     151    c = Math.sqrt(a * a + b * b); 
     152 
     153    double scl = 1; // for now 
     154    double d = GLOW_WIDTH * scl; 
     155 
     156    // compute four corners of highlighted zone 
     157    float c1x = (float) (x1 - x[0] * d + y[0] * (d * c) / b); 
     158    float c1y = (float) (y1 - x[1] * d + y[1] * (d * c) / b); 
     159    float c2x = (float) (x2 + x[0] * d + y[0] * (a + d * (a + c) / b)); 
     160    float c2y = (float) (y2 + x[1] * d + y[1] * (a + d * (a + c) / b)); 
     161    float c3x = (float) (x2 + x[0] * d - y[0] * (a + d * (a + c) / b)); 
     162    float c3y = (float) (y2 + x[1] * d - y[1] * (a + d * (a + c) / b)); 
     163    float c4x = (float) (x1 - x[0] * d - y[0] * (d * c) / b); 
     164    float c4y = (float) (y1 - x[1] * d - y[1] * (d * c) / b); 
     165 
     166    // order and combine the coordinates for a Gridded2DSet [2 2] 
     167    float[][] setSamples = { 
     168      {c1x, c2x, c4x, c3x}, 
     169      {c1y, c2y, c4y, c3y} 
     170    }; 
     171     
     172    // construct range samples 
     173    float r = GLOW_COLOR.getRed() / 255f; 
     174    float g = GLOW_COLOR.getGreen() / 255f; 
     175    float bl = GLOW_COLOR.getBlue() / 255f; 
     176     
     177    float[][] rangeSamples = new float[4][setSamples[0].length]; 
     178    Arrays.fill(rangeSamples[0], r); 
     179    Arrays.fill(rangeSamples[1], g); 
     180    Arrays.fill(rangeSamples[2], bl); 
     181    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     182 
     183    // construct Field 
     184    Gridded2DSet domainSet = null; 
     185    FlatField field = null; 
     186    try { 
     187      domainSet = new Gridded2DSet(domain, setSamples, 
     188        2, 2, null, null, null, false); 
     189      FunctionType fieldType = new FunctionType(domain, range); 
     190      field = new FlatField(fieldType, domainSet); 
     191      field.setSamples(rangeSamples); 
     192    } 
     193    catch (VisADException exc) { exc.printStackTrace(); } 
     194    catch (RemoteException exc) { exc.printStackTrace(); } 
     195    return field; 
    114196  } 
    115197 
  • trunk/loci/visbio/overlays/OverlayBox.java

    r2114 r2524  
    2424package loci.visbio.overlays; 
    2525 
     26import java.awt.Color; 
    2627import java.rmi.RemoteException; 
    2728import java.util.Arrays; 
     
    7980    catch (VisADException exc) { exc.printStackTrace(); } 
    8081 
    81     float r = color.getRed() / 255f; 
    82     float g = color.getGreen() / 255f; 
    83     float b = color.getBlue() / 255f; 
     82    Color col = selected ? GLOW_COLOR : color; 
     83    float r = col.getRed() / 255f; 
     84    float g = col.getGreen() / 255f; 
     85    float b = col.getBlue() / 255f; 
     86 
    8487    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    8588    Arrays.fill(rangeSamples[0], r); 
     
    161164  public String toString() { return "Box"; } 
    162165 
     166  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     167 
     168  public DataImpl getSelectionGrid(boolean outline) { 
     169    RealTupleType domain = overlay.getDomainType(); 
     170    TupleType range = overlay.getRangeType(); 
     171 
     172    float delta = GLOW_WIDTH; 
     173 
     174    // Determine orientation of (x1, y1) relative to (x2, y2) 
     175    // and flip if need be. 
     176    // I've set up the code in this section based on the  
     177    // suppositioin that the box is oriented like this: 
     178    // 
     179    // (x1, y1) +--------+ 
     180    //          |        | 
     181    //          |        | 
     182    //          +--------+ (x2, y2) 
     183    // 
     184    // which means x1 is supposed to be _less_ than x2, but inconsistently, 
     185    // y1 is supposed to be _greater_ than y2. 
     186    float[][] c; 
     187    boolean flipX = x2 > x1; 
     188    float xx1 = flipX ? x1 : x2; 
     189    float xx2 = flipX ? x2 : x1; 
     190    boolean flipY = y2 < y1; 
     191    float yy1 = flipY ? y1 : y2; 
     192    float yy2 = flipY ? y2 : y1; 
     193 
     194    int rangeSamplesLength = 16; 
     195    SampledSet domainSet = null; 
     196    if (2 * delta > xx2 - xx1 || 2 * delta > yy1 - yy2) { 
     197      // if box is narrower than twice the width the highlighting 
     198      // band would be, 
     199      // just throw down a translucent rectangle over the box 
     200 
     201      rangeSamplesLength = 4; 
     202       
     203      float[][] setSamples = { 
     204        {xx1 - delta, xx2 + delta, xx1 - delta, xx2 + delta}, 
     205        {yy1 + delta, yy1 + delta, yy2 - delta, yy2 - delta}}; 
     206 
     207      try { 
     208        domainSet = new Gridded2DSet(domain, setSamples, 2, 2, 
     209          null, null, null, false); 
     210      } 
     211      catch (VisADException ex) { ex.printStackTrace(); } 
     212    } 
     213    else { 
     214      // construct a trapezoidal highlighting band for each of the  
     215      // four line segments which constitute the box 
     216      c = new float[][]{{xx1, yy1}, {xx2, yy2}}; 
     217 
     218      float[][] s1 =  
     219        {{c[0][0] - delta, c[1][0] + delta, c[0][0] + delta, c[1][0] - delta}, 
     220        {c[0][1] + delta, c[0][1] + delta, c[0][1] - delta, c[0][1] - delta}}; 
     221      float[][] s2 =  
     222        {{c[1][0] + delta, c[1][0] + delta, c[1][0] - delta, c[1][0] - delta}, 
     223        {c[0][1] + delta, c[1][1] - delta, c[0][1] - delta, c[1][1] + delta}}; 
     224      float[][] s3 =  
     225        {{c[1][0] + delta, c[0][0] - delta, c[1][0] - delta, c[0][0] + delta}, 
     226        {c[1][1] - delta, c[1][1] - delta, c[1][1] + delta, c[1][1] + delta}}; 
     227      float[][] s4 =  
     228        {{c[0][0] - delta, c[0][0] - delta, c[0][0] + delta, c[0][0] + delta}, 
     229        {c[1][1] - delta, c[0][1] + delta, c[1][1] + delta, c[0][1] - delta}}; 
     230 
     231      float[][][] setSamples = {s1, s2, s3, s4}; 
     232 
     233      Gridded2DSet[] segments = new Gridded2DSet[4]; 
     234      for (int i=0; i<4; i++) { 
     235        Gridded2DSet segment = null; 
     236        try { 
     237          segment = new Gridded2DSet (domain, setSamples[i], 2, 2, null, null, 
     238              null, 
     239              false); 
     240        } 
     241        catch (VisADException exc) { exc.printStackTrace(); } 
     242        segments[i] = segment; 
     243      } 
     244 
     245      try { domainSet = new UnionSet(domain, segments); } 
     246      catch (VisADException exc) { exc.printStackTrace(); } 
     247    } // end else  
     248 
     249    //**************************************************************  
     250     
     251    // construct range samples 
     252    float[][] rangeSamples = new float[4][rangeSamplesLength]; 
     253    float r = GLOW_COLOR.getRed() / 255f; 
     254    float g = GLOW_COLOR.getGreen() / 255f; 
     255    float b = GLOW_COLOR.getBlue() / 255f; 
     256    Arrays.fill(rangeSamples[0], r); 
     257    Arrays.fill(rangeSamples[1], g); 
     258    Arrays.fill(rangeSamples[2], b); 
     259    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     260 
     261    // construct field 
     262    FlatField field = null; 
     263    try { 
     264      FunctionType fieldType = new FunctionType(domain, range); 
     265      field = new FlatField(fieldType, domainSet); 
     266      field.setSamples(rangeSamples); 
     267    } 
     268    catch (VisADException exc) { exc.printStackTrace(); } 
     269    catch (RemoteException exc) { exc.printStackTrace(); } 
     270 
     271    return field; 
     272  } 
    163273} 
  • trunk/loci/visbio/overlays/OverlayFreeform.java

    r2284 r2524  
    2323 
    2424package loci.visbio.overlays; 
    25  
    26 //import java.util.Arrays; 
    27 import visad.*; 
    2825 
    2926/** 
     
    5855  /** Gets a short string representation of this freeform. */ 
    5956  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  
    82     RealTupleType domain = overlay.getDomainType(); 
    83     TupleType range = overlay.getRangeType(); 
    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  
    117  
    118     FlatField field = null; 
    119     try { 
    120       SampledSet fieldSet = new Gridded2DSet(domain, 
    121         setSamples, setSamples[0].length, null, null, null, false); 
    122       if (filled) { 
    123         Irregular2DSet roiSet = 
    124           DelaunayCustom.fillCheck((Gridded2DSet) fieldSet, false); 
    125         if (roiSet != null) fieldSet = roiSet; 
    126       } 
    127  
    128       int len = fieldSet.getSamples(false)[0].length; 
    129       float[][] rangeSamples = new float[4][len]; 
    130       Arrays.fill(rangeSamples[0], r); 
    131       Arrays.fill(rangeSamples[1], g); 
    132       Arrays.fill(rangeSamples[2], b); 
    133       Arrays.fill(rangeSamples[3], 1.0f); 
    134  
    135       FunctionType fieldType = new FunctionType(domain, range); 
    136       field = new FlatField(fieldType, fieldSet); 
    137       field.setSamples(rangeSamples); 
    138     } 
    139     catch (VisADException exc) { exc.printStackTrace(); } 
    140     catch (RemoteException exc) { exc.printStackTrace(); } 
    141     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     */ 
    231   } 
    232  
     57  
    23358} 
  • trunk/loci/visbio/overlays/OverlayLine.java

    r2024 r2524  
    2424package loci.visbio.overlays; 
    2525 
     26import java.awt.Color; 
    2627import java.rmi.RemoteException; 
    2728import java.util.Arrays; 
     
    5758 
    5859    float[][] setSamples = {{x1, x2}, {y1, y2}}; 
    59     float r = color.getRed() / 255f; 
    60     float g = color.getGreen() / 255f; 
    61     float b = color.getBlue() / 255f; 
     60 
     61    Color col = selected ? GLOW_COLOR : color;  
     62    float r = col.getRed() / 255f; 
     63    float g = col.getGreen() / 255f; 
     64    float b = col.getBlue() / 255f; 
     65 
    6266    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    6367    Arrays.fill(rangeSamples[0], r); 
     
    148152  } 
    149153 
     154  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     155 
     156  public DataImpl getSelectionGrid(boolean outline) { 
     157    RealTupleType domain = overlay.getDomainType(); 
     158    TupleType range = overlay.getRangeType(); 
     159 
     160    float delta = GLOW_WIDTH; 
     161 
     162    float[] v = new float[]{x2 - x1, y2 - y1}; 
     163 
     164    // angle of vector perpendicular to line 
     165    double theta =  Math.PI / 2 + Math.atan2(v[1], v[0]);  
     166 
     167    float dx = (float) (delta * Math.cos(theta)); 
     168    float dy = (float) (delta * Math.sin(theta)); 
     169 
     170    float[] p1 = {x1 + dx, y1 + dy}; 
     171    float[] p2 = {x2 + dx, y2 + dy}; 
     172    float[] p3 = {x1 - dx, y1 - dy}; 
     173    float[] p4 = {x2 - dx, y2 - dy}; 
     174 
     175    float[][] setSamples = {{p1[0], p2[0], p3[0], p4[0]}, 
     176                            {p1[1], p2[1], p3[1], p4[1]}}; 
     177 
     178    // construct range samples; 
     179    Color col = GLOW_COLOR; 
     180 
     181    float r = col.getRed() / 255f; 
     182    float g = col.getGreen() / 255f; 
     183    float b = col.getBlue() / 255f; 
     184 
     185    float[][] rangeSamples = new float[4][4]; 
     186    Arrays.fill(rangeSamples[0], r); 
     187    Arrays.fill(rangeSamples[1], g); 
     188    Arrays.fill(rangeSamples[2], b); 
     189    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     190 
     191    Gridded2DSet domainSet = null; 
     192    FlatField field = null; 
     193    try { 
     194      domainSet = new Gridded2DSet(domain, setSamples, 
     195            2, 2, null, null, null, false); 
     196      FunctionType fieldType = new FunctionType(domain, range); 
     197      field = new FlatField(fieldType, domainSet); 
     198      field.setSamples(rangeSamples); 
     199    } 
     200    catch (VisADException exc) { exc.printStackTrace(); } 
     201    catch (RemoteException exc) { exc.printStackTrace(); } 
     202 
     203    return field; 
     204  } 
     205 
    150206} 
  • trunk/loci/visbio/overlays/OverlayMarker.java

    r2024 r2524  
    2424package loci.visbio.overlays; 
    2525 
     26import java.awt.Color; 
    2627import java.rmi.RemoteException; 
    2728import java.util.Arrays; 
     
    5657      {y1 + size, y1 - size, y1, y1, y1} 
    5758    }; 
    58     float r = color.getRed() / 255f; 
    59     float g = color.getGreen() / 255f; 
    60     float b = color.getBlue() / 255f; 
     59    Color col = selected ? GLOW_COLOR : color; 
     60    float r = col.getRed() / 255f; 
     61    float g = col.getGreen() / 255f; 
     62    float b = col.getBlue() / 255f; 
    6163    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    6264    Arrays.fill(rangeSamples[0], r); 
     
    7880  } 
    7981 
     82  /** Gets a DataImpl overlay indicating that this object is selected */ 
     83  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     84 
     85  /** Gets a DataImpl overlay indicating that this object is selected */ 
     86  public DataImpl getSelectionGrid(boolean outline) { 
     87    if (outline) return super.getSelectionGrid(outline); 
     88 
     89    RealTupleType domain = overlay.getDomainType(); 
     90    TupleType range = overlay.getRangeType(); 
     91 
     92    float size = 0.02f * overlay.getScalingValue(); 
     93    float scl = .1f; // for now 
     94    float delta = GLOW_WIDTH * scl; 
     95 
     96    //System.out.println("x1 - size = " + (x1 - size)); // TEMP 
     97    //System.out.println("x1 + size = " + (x1 + size)); // TEMP 
     98    //System.out.println("y1 - size = " + (y1 - size)); // TEMP 
     99    //System.out.println("y1 + size = " + (y1 + size)); // TEMP 
     100 
     101    float xx1 = x1 - size - delta; 
     102    float xx2 = x1 + size + delta; 
     103    float yy1 = y1 + size + delta; 
     104    float yy2 = y1 - size - delta; 
     105 
     106    float dx = 0.0001f; // TEMP 
     107 
     108    float[][] setSamples; 
     109    if (true || 2 * delta > size) { 
     110      // return box 
     111      setSamples = new float[][]{ 
     112        {xx1, xx2, xx1, xx2}, 
     113        {yy1, yy1, yy2, yy2} 
     114      }; 
     115    } 
     116    else { 
     117      // return cross 
     118      /* 
     119      setSamples = new float[][]{ 
     120        {xx1, x1 - delta, x1 - delta + dx, x1 + delta - dx, x1 + delta, xx2, 
     121          xx1, x1 - delta, x1 - delta + dx, x1 + delta - dx, x1 + delta, xx2}, 
     122        {y1 + delta, y1 + delta, yy1, yy1, y1 + delta, y1 + delta, 
     123          y1 - delta, y1 - delta, yy2, yy2, y1 - delta, y1 - delta} 
     124      };*/ 
     125      setSamples = new float[][] { 
     126        {xx1, x1 - delta, x1 - delta + dx, 
     127          xx1, x1 - delta, x1 -delta + dx}, 
     128        {y1 + delta, y1 + delta, y1 + size + delta,  
     129          y1 - delta, y1 - delta, y1 - size - delta} 
     130      }; 
     131    } 
     132 
     133    //System.out.println("coords ==========================="); // TEMP 
     134    /* 
     135    for (int i=0; i<setSamples[0].length; i++) { 
     136      System.out.println("(" + setSamples[0][i] + "," + setSamples[1][i] + ")"); 
     137    } 
     138    */ 
     139 
     140    // construct range samples 
     141    float r = GLOW_COLOR.getRed() / 255f; 
     142    float g = GLOW_COLOR.getGreen() / 255f; 
     143    float b = GLOW_COLOR.getBlue() / 255f; 
     144 
     145    float[][] rangeSamples = new float[4][setSamples[0].length]; 
     146    Arrays.fill(rangeSamples[0], r); 
     147    Arrays.fill(rangeSamples[1], g); 
     148    Arrays.fill(rangeSamples[2], b); 
     149    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     150 
     151    // construct field 
     152    Gridded2DSet domainSet = null; 
     153    FlatField field = null; 
     154    try { 
     155      domainSet = new Gridded2DSet(domain, setSamples, setSamples[0].length / 
     156          2, 2, null, null, null, false); 
     157      FunctionType fieldType = new FunctionType (domain, range); 
     158      field = new FlatField(fieldType, domainSet); 
     159      field.setSamples(rangeSamples); 
     160    } 
     161    catch (VisADException ex) { ex.printStackTrace(); } 
     162    catch (RemoteException ex) { ex.printStackTrace(); } 
     163    return field; 
     164  } 
     165     
     166 
    80167  /** Computes the shortest distance from this object to the given point. */ 
    81168  public double getDistance(double x, double y) { 
  • trunk/loci/visbio/overlays/OverlayNodedObject.java

    r2393 r2524  
    197197    float b = color.getBlue() / 255f; 
    198198 
     199    if (selected) { 
     200      r = 1.0f; 
     201      g = 1.0f; 
     202      b = 0.0f; 
     203    } 
     204 
    199205    Arrays.fill(rangeSamples[0], 0, maxNodes, r); 
    200206    Arrays.fill(rangeSamples[1], 0, maxNodes, g); 
     
    277283 
    278284    return field;  
     285  } 
     286 
     287  /** 
     288   * Computes a grid to be superimposed on this overlay 
     289   * to indicate it is currently selected. 
     290   */ 
     291  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     292 
     293  /** 
     294   * Computes a grid to be superimposed on this overlay to 
     295   * indicate it is currently selected. 
     296   * Computes only an outline regardless of the flag 'outline'  
     297   */ 
     298  public DataImpl getSelectionGrid(boolean outline) { 
     299    //return super.getSelectionGrid(true); 
     300 
     301    RealTupleType domain = overlay.getDomainType(); 
     302    TupleType range = overlay.getRangeType(); 
     303 
     304    float scl = display == null ? 1.0f : getScalingValue(display); 
     305    float delta = GLOW_WIDTH * scl; 
     306 
     307    Gridded2DSet[] segments = new Gridded2DSet[numNodes-1]; 
     308    for (int i=0; i<numNodes - 1; i++) { 
     309      float[] v = new float[]{nodes[0][i+1] - nodes[0][i], nodes[1][i+1] - 
     310          nodes[1][i]}; 
     311      // angle of vector perpendicular to line 
     312      double theta =  Math.PI / 2 + Math.atan2(v[1], v[0]);  
     313 
     314      float dx = (float) (delta * Math.cos(theta)); 
     315      float dy = (float) (delta * Math.sin(theta)); 
     316 
     317      float[] p1 = {nodes[0][i] + dx, nodes[1][i] + dy}; 
     318      float[] p2 = {nodes[0][i+1] + dx, nodes[1][i+1] + dy}; 
     319      float[] p3 = {nodes[0][i] - dx, nodes[1][i] - dy}; 
     320      float[] p4 = {nodes[0][i+1] - dx, nodes[1][i+1] - dy}; 
     321 
     322      float[][] setSamples = {{p1[0], p2[0], p3[0], p4[0]}, 
     323                              {p1[1], p2[1], p3[1], p4[1]}}; 
     324 
     325      try { 
     326        segments[i] = new Gridded2DSet(domain, setSamples, 
     327            2, 2, null, null, null, false); 
     328      } 
     329      catch (VisADException exc) { exc.printStackTrace(); } 
     330    } 
     331 
     332    // construct range samples; 
     333    Color col = Color.YELLOW; 
     334 
     335    float r = col.getRed() / 255f; 
     336    float g = col.getGreen() / 255f; 
     337    float b = col.getBlue() / 255f; 
     338 
     339 
     340    float[][] rangeSamples = new float[4][4*(numNodes-1)]; 
     341    Arrays.fill(rangeSamples[0], r); 
     342    Arrays.fill(rangeSamples[1], g); 
     343    Arrays.fill(rangeSamples[2], b); 
     344    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     345 
     346    FlatField field = null; 
     347    UnionSet fieldSet = null; 
     348    try { 
     349      fieldSet = new UnionSet (domain, segments); 
     350 
     351      FunctionType fieldType = new FunctionType(domain, range); 
     352      field = new FlatField(fieldType, fieldSet); 
     353      field.setSamples(rangeSamples); 
     354    } 
     355    catch (VisADException exc) { exc.printStackTrace(); } 
     356    catch (RemoteException exc) { exc.printStackTrace(); } 
     357 
     358    return field; 
     359 
    279360  } 
    280361 
     
    635716  } 
    636717 
    637   /** Returns a domain/pixel scaling value */ 
     718  /** Returns a scaling value [domain length units/pixel] */ 
    638719  protected float getScalingValue(DisplayImpl d) { 
    639720    double[] oDom = DisplayUtil.pixelToDomain(d, 0, 0); 
  • trunk/loci/visbio/overlays/OverlayObject.java

    r2284 r2524  
    3030/** OverlayObject is the superclass of all overlay objects. */ 
    3131public abstract class OverlayObject { 
     32 
     33  // -- Constants -- 
     34  protected static final float GLOW_WIDTH = 3.0f; // (pixels) 
     35 
     36  protected static final float GLOW_ALPHA = 0.15f;  
     37 
     38  protected static final Color GLOW_COLOR = Color.YELLOW; 
    3239 
    3340  // -- Fields -- 
  • trunk/loci/visbio/overlays/OverlayOval.java

    r2114 r2524  
    2424package loci.visbio.overlays; 
    2525 
     26import java.awt.Color; 
    2627import java.rmi.RemoteException; 
    2728import java.util.Arrays; 
     
    125126    catch (VisADException exc) { exc.printStackTrace(); } 
    126127 
    127     float r = color.getRed() / 255f; 
    128     float g = color.getGreen() / 255f; 
    129     float b = color.getBlue() / 255f; 
     128    Color col = selected ? GLOW_COLOR : color; 
     129    float r = col.getRed() / 255f; 
     130    float g = col.getGreen() / 255f; 
     131    float b = col.getBlue() / 255f; 
    130132    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    131133    Arrays.fill(rangeSamples[0], r); 
     
    136138    FlatField field = null; 
    137139    try { 
     140      FunctionType fieldType = new FunctionType(domain, range); 
     141      field = new FlatField(fieldType, fieldSet); 
     142      field.setSamples(rangeSamples); 
     143    } 
     144    catch (VisADException exc) { exc.printStackTrace(); } 
     145    catch (RemoteException exc) { exc.printStackTrace(); } 
     146    return field; 
     147  } 
     148 
     149  /** Gets a layer indicating this overlay is selected */ 
     150  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     151 
     152  /** Gets a layer indicating this overlay is selected */ 
     153  public DataImpl getSelectionGrid(boolean outline) { 
     154    if (x1 == x2 || y1 == y2) return null;  
     155    // don't try to render a zero-area ellipse 
     156 
     157    RealTupleType domain = overlay.getDomainType(); 
     158    TupleType range = overlay.getRangeType(); 
     159 
     160    float cx = (x1 + x2) / 2; 
     161    float cy = (y1 + y2) / 2; 
     162    float rrx = cx > x1 ? cx - x1 : cx - x2; 
     163    float rry = cy > y1 ? cy - y1 : cy - y2; 
     164 
     165    float scl = 1; // for now 
     166    float rx = rrx + GLOW_WIDTH * scl; 
     167    float ry = rry + GLOW_WIDTH * scl; 
     168 
     169    int arcLen = ARC[0].length; 
     170    int len = 2 * arcLen; 
     171    float[][] setSamples = new float[2][len]; 
     172 
     173    // top half of circle 
     174    for (int i=0; i<arcLen; i++) { 
     175      setSamples[0][i] = cx + rx * ARC[0][i]; 
     176      setSamples[1][i] = cy + ry * ARC[1][i]; 
     177    } 
     178 
     179    // bottom half of circle 
     180    for (int i=0; i<arcLen; i++) { 
     181      int ndx = arcLen + i; 
     182      setSamples[0][ndx] = cx + rx * ARC[0][i]; 
     183      setSamples[1][ndx] = cy - ry * ARC[1][i]; 
     184    } 
     185 
     186    // construct range samples 
     187    float r = GLOW_COLOR.getRed() / 255f; 
     188    float g = GLOW_COLOR.getGreen() / 255f; 
     189    float b = GLOW_COLOR.getBlue() / 255f; 
     190 
     191    float[][] rangeSamples = new float[4][setSamples[0].length]; 
     192    Arrays.fill(rangeSamples[0], r); 
     193    Arrays.fill(rangeSamples[1], g); 
     194    Arrays.fill(rangeSamples[2], b); 
     195    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     196 
     197    GriddedSet fieldSet = null; 
     198    FlatField field = null; 
     199    try { 
     200      fieldSet = new Gridded2DSet(domain, 
     201        setSamples, arcLen, 2, null, null, null, false); 
     202 
    138203      FunctionType fieldType = new FunctionType(domain, range); 
    139204      field = new FlatField(fieldType, fieldSet); 
  • trunk/loci/visbio/overlays/OverlayPolyline.java

    r2332 r2524  
    2424package loci.visbio.overlays; 
    2525 
    26 import visad.*; 
    27  
    2826/** 
    2927 * OverlayFreeform is a freeform overlay. 
     
    3129 
    3230public class OverlayPolyline extends OverlayNodedObject { 
    33  
     31   
    3432  // -- Fields -- 
    3533   
     
    5957  /** Gets a short string representation of this freeform. */ 
    6058  public String toString() { return "Polyline"; } 
    61    
    62   /** 
    63    * Computes a grid to be superimposed on this overlay 
    64    * to indicate it is currently selected. 
    65    */ 
    66   public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
    67  
    68   /** 
    69    * Computes a grid to be superimposed on this overlay to 
    70    * indicate it is currently selected. 
    71    * If the outline flag is set, computes only an outline instead. 
    72    */ 
    73   public DataImpl getSelectionGrid(boolean outline) { 
    74     return super.getSelectionGrid(outline); 
    75     /* 
    76     try { 
    77       RealType index = new RealType("index"); 
    78       Set indexSet = new Integer1DSet(index, numNodes); 
    79     } 
    80     catch (VisADException ex) {} 
    81     float[][] setSamples = nodes; 
    82  
    83     RealTupleType domain = overlay.getDomainType(); 
    84     TupleType range = overlay.getRangeType(); 
    85     FunctionType indexXY = (index, domain); 
    86     FlatField(indexXY, indexSet); 
    87  
    88     System.out.println(domain); 
    89     System.out.println(range); 
    90     return null; 
    91     */ 
    92  
    93     /* 
    94     float[][] setSamples = new float[nodes.length][numNodes]; 
    95     setSamples[0][0] = nodes[0][0]; // for now 
    96     setSamples[1][0] = nodes[1][0]; 
    97     for (int j=1; j<numNodes-1; j++) { 
    98       float x = nodes[0][j]; 
    99       float y = nodes[1][j]; 
    100       float dx = nodes[0][j+1] - nodes[0][j-1]; 
    101       float dy = nodes[1][j+1] - nodes[1][j-1]; // slope of perpendicular 
    102       float r = (float) Math.sqrt(dx*dx + dy*dy); 
    103       float scale = 1.0f; 
    104       float newX =  x + scale * dy / r; 
    105       float newY = y + scale * dx / r; 
    106       setSamples[0][j] = newX; 
    107       setSamples[1][j] = newY; 
    108     } 
    109     setSamples[0][numNodes-1] = nodes[0][numNodes-1]; 
    110     setSamples[0][numNodes-1] = nodes[1][numNodes-1]; 
    111  
    112     Color yellow = Color.YELLOW; 
    113     float r = yellow.getRed() / 255f; 
    114     float g = yellow.getGreen() / 255f; 
    115     float b = yellow.getBlue() / 255f; 
    116  
    117     System.out.println ("r = " + r + " g = " + g + " b = " + b ); //TEMP  
    118  
    119     FlatField field = null; 
    120     try { 
    121       SampledSet fieldSet = new Gridded2DSet(domain, 
    122         setSamples, setSamples[0].length, null, null, null, false); 
    123       if (filled) { 
    124         Irregular2DSet roiSet = 
    125           DelaunayCustom.fillCheck((Gridded2DSet) fieldSet, false); 
    126         if (roiSet != null) fieldSet = roiSet; 
    127       } 
    128  
    129       int len = fieldSet.getSamples(false)[0].length; 
    130       float[][] rangeSamples = new float[4][len]; 
    131       Arrays.fill(rangeSamples[0], r); 
    132       Arrays.fill(rangeSamples[1], g); 
    133       Arrays.fill(rangeSamples[2], b); 
    134       Arrays.fill(rangeSamples[3], 1.0f); 
    135  
    136       FunctionType fieldType = new FunctionType(domain, range); 
    137       field = new FlatField(fieldType, fieldSet); 
    138       field.setSamples(rangeSamples); 
    139     } 
    140     catch (VisADException exc) { exc.printStackTrace(); } 
    141     catch (RemoteException exc) { exc.printStackTrace(); } 
    142     return field; 
    143  
    144     // Grid computation relies on parameters: 
    145     //   (xGrid1, yGrid1): top-left endpoint of grid rectangle 
    146     //   (xGrid2, yGrid2): top-right endpoint of grid rectangle 
    147     //   (xGrid3, yGrid3): bottom-left endpoint of grid rectangle 
    148     //   (xGrid4, yGrid4): bottom-right endpoint of grid rectangle 
    149     //     horizGridCount: number of horizontal dividing lines 
    150     //      vertGridCount: number of vertical dividing lines 
    151  
    152     /* 
    153     // compute (X, Y) values along grid left and right edges 
    154     int numLR = outline ? 2 : (horizGridCount + 2); 
    155     float[] xl = new float[numLR]; 
    156     float[] xr = new float[numLR]; 
    157     float[] yl = new float[numLR]; 
    158     float[] yr = new float[numLR]; 
    159     for (int i=0; i<numLR; i++) { 
    160       float q = (float) i / (numLR - 1); 
    161       xl[i] = q * (xGrid3 - xGrid1) + xGrid1; 
    162       xr[i] = q * (xGrid4 - xGrid2) + xGrid2; 
    163       yl[i] = q * (yGrid3 - yGrid1) + yGrid1; 
    164       yr[i] = q * (yGrid4 - yGrid2) + yGrid2; 
    165     } 
    166  
    167     // compute (X, Y) values along grid top and bottom edges 
    168     int numTB = outline ? 2 : (vertGridCount + 2); 
    169     float[] xt = new float[numTB]; 
    170     float[] xb = new float[numTB]; 
    171     float[] yt = new float[numTB]; 
    172     float[] yb = new float[numTB]; 
    173     for (int i=0; i<numTB; i++) { 
    174       float q = (float) i / (numTB - 1); 
    175       xt[i] = q * (xGrid2 - xGrid1) + xGrid1; 
    176       xb[i] = q * (xGrid4 - xGrid3) + xGrid3; 
    177       yt[i] = q * (yGrid2 - yGrid1) + yGrid1; 
    178       yb[i] = q * (yGrid4 - yGrid3) + yGrid3; 
    179     } 
    180  
    181     RealTupleType domain = overlay.getDomainType(); 
    182     TupleType range = overlay.getRangeType(); 
    183  
    184     // compute zig-zagging grid mesh values 
    185     int count = 2 * (numLR + numTB) - 1; 
    186     float[][] setSamples = new float[2][count]; 
    187     for (int i=0; i<numLR; i++) { 
    188       int ndx = 2 * i; 
    189       boolean dir = i % 2 == 0; 
    190       setSamples[0][ndx] = dir ? xl[i] : xr[i]; 
    191       setSamples[1][ndx] = dir ? yl[i] : yr[i]; 
    192       setSamples[0][ndx + 1] = dir ? xr[i] : xl[i]; 
    193       setSamples[1][ndx + 1] = dir ? yr[i] : yl[i]; 
    194     } 
    195     boolean leftToRight = numLR % 2 == 0; 
    196     for (int i=0; i<numTB; i++) { 
    197       int ndx = 2 * (numLR + i) - 1; 
    198       boolean dir = i % 2 == 0; 
    199       int ii = leftToRight ? i : (numTB - i - 1); 
    200       setSamples[0][ndx] = dir ? xb[ii] : xt[ii]; 
    201       setSamples[1][ndx] = dir ? yb[ii] : yt[ii]; 
    202       setSamples[0][ndx + 1] = dir ? xt[ii] : xb[ii]; 
    203       setSamples[1][ndx + 1] = dir ? yt[ii] : yb[ii]; 
    204     } 
    205  
    206     // populate grid color values 
    207     Color c = outline ? Color.cyan : Color.yellow; 
    208     float r = c.getRed() / 255f; 
    209     float g = c.getGreen() / 255f; 
    210     float b = c.getBlue() / 255f; 
    211     float[][] fieldSamples = new float[4][count]; 
    212     for (int i=0; i<count; i++) { 
    213       fieldSamples[0][i] = r; 
    214       fieldSamples[1][i] = g; 
    215       fieldSamples[2][i] = b; 
    216       fieldSamples[3][i] = 1.0f; 
    217     } 
    218  
    219     // construct field 
    220     FlatField field = null; 
    221     try { 
    222       GriddedSet fieldSet = new Gridded2DSet(domain, 
    223         setSamples, setSamples[0].length, null, null, null, false); 
    224       FunctionType fieldType = new FunctionType(domain, range); 
    225       field = new FlatField(fieldType, fieldSet); 
    226       field.setSamples(fieldSamples, false); 
    227     } 
    228     catch (VisADException exc) { exc.printStackTrace(); } 
    229     catch (RemoteException exc) { exc.printStackTrace(); } 
    230     return field; 
    231     */ 
    232   } 
    23359 
    23460} 
  • trunk/loci/visbio/overlays/OverlayText.java

    r2024 r2524  
    2424package loci.visbio.overlays; 
    2525 
     26import java.awt.Color; 
    2627import java.awt.FontMetrics; 
    2728import java.rmi.RemoteException; 
     29import java.util.Arrays; 
    2830import visad.*; 
    2931 
     
    5254    TupleType range = overlay.getTextRangeType(); 
    5355 
    54     float r = color.getRed() / 255f; 
    55     float g = color.getGreen() / 255f; 
    56     float b = color.getBlue() / 255f; 
     56    Color col = selected ? GLOW_COLOR : color; 
     57    float r = col.getRed() / 255f; 
     58    float g = col.getGreen() / 255f; 
     59    float b = col.getBlue() / 255f; 
    5760 
    5861    FieldImpl field = null; 
     
    6669    catch (VisADException exc) { exc.printStackTrace(); } 
    6770    catch (RemoteException exc) { exc.printStackTrace(); } 
     71    return field; 
     72  } 
     73 
     74  /** Gets a layer indicating this object is selected */ 
     75  public DataImpl getSelectionGrid() { return getSelectionGrid(false); } 
     76 
     77  /** Gets a layer indicating this object is selected */ 
     78  public DataImpl getSelectionGrid(boolean outline) {  
     79    if (outline) return super.getSelectionGrid(outline); 
     80 
     81    RealTupleType domain = overlay.getDomainType(); 
     82    TupleType range = overlay.getRangeType(); 
     83 
     84    float[][] setSamples = { 
     85      {xGrid1, xGrid2, xGrid3, xGrid4}, 
     86      {yGrid1, yGrid2, yGrid3, yGrid4} 
     87    }; 
     88 
     89    // construct range samples 
     90    float r = GLOW_COLOR.getRed() / 255f; 
     91    float g = GLOW_COLOR.getGreen() / 255f; 
     92    float b = GLOW_COLOR.getBlue() / 255f; 
     93 
     94    float[][] rangeSamples = new float[4][setSamples[0].length]; 
     95    Arrays.fill(rangeSamples[0], r); 
     96    Arrays.fill(rangeSamples[1], g); 
     97    Arrays.fill(rangeSamples[2], b); 
     98    Arrays.fill(rangeSamples[3], GLOW_ALPHA); 
     99 
     100    FlatField field = null; 
     101    try { 
     102      Gridded2DSet domainSet = new Gridded2DSet(domain, setSamples, 2, 2, 
     103          null, null, null, false); 
     104      FunctionType fieldType = new FunctionType(domain, range); 
     105      field = new FlatField(fieldType, domainSet); 
     106      field.setSamples(rangeSamples); 
     107    } 
     108    catch (VisADException ex) { ex.printStackTrace(); } 
     109    catch (RemoteException ex) { ex.printStackTrace(); } 
    68110    return field; 
    69111  } 
  • trunk/loci/visbio/overlays/PointerTool.java

    r2487 r2524  
    194194      select.setCorner(px, py); 
    195195 
     196      // ******************************************************* 
    196197      // select objects inside the box 
    197198      for (int i=0; i<bounds.length; i++) { 
     
    291292        } 
    292293      } // end for 
     294      // **************************************************** 
    293295 
    294296      if (selectionStateChanged) ((OverlayWidget) 
  • trunk/loci/visbio/overlays/PolylineTool.java

    r2431 r2524  
    102102 
    103103    if (overlay.hasToolChanged()) { 
    104       unselect(); 
     104      releaseLine(); 
    105105      mode = WAIT; 
    106106    } 
     
    192192    else if (mode == EXTEND || mode == BEG_EXTEND) { 
    193193      line.setLastNode(dx, dy); 
    194       line.computeLength(); 
     194      float[] c = line.getNodeCoords(line.getNumNodes()-2); 
     195      double[] cdub = {(double) c[0], (double) c[1]}; 
     196      double oldLen = line.getCurveLength(); 
     197      line.setCurveLength(oldLen + MathUtil.getDistance(cdub, 
     198            new double[]{dx, dy})); 
    195199      mode = PLACE; 
    196200    } 
     
    212216 
    213217    if (overlay.hasToolChanged()) { 
    214       unselect(); 
     218      releaseLine(); 
    215219      mode = WAIT; 
    216220    } 
     
    259263 
    260264    if (overlay.hasToolChanged()) { 
     265      releaseLine(); 
    261266      mode = WAIT; 
    262       unselect(); 
    263267    } 
    264268    if (mode == ADJUST) { 
     269      line.updateBoundingBox(); 
     270      line.computeGridParameters(); 
     271      line.computeLength(); 
    265272      mode = SELECT; 
    266273    } 
    267274    else if (mode == ADJUST_TAIL) { 
     275      line.updateBoundingBox(); 
     276      line.computeGridParameters(); 
     277      line.computeLength(); 
    268278      mode = SELECT; 
    269279    } 
     
    275285      float[] c = line.getNodeCoords(0); 
    276286      line.setLastNode(c[0], c[1]);  
     287      line.updateBoundingBox(); 
     288      line.computeGridParameters(); 
     289      line.computeLength(); 
    277290      selectNode(display, line, line.getNumNodes() - 1); 
    278291      mode = SELECT; 
     
    292305 
    293306    if (overlay.hasToolChanged()) { 
    294       unselect(); 
     307      releaseLine(); 
    295308      mode = WAIT; 
    296309    } 
     
    311324    else if (mode == PLACE) { 
    312325      line.setNextNode(dx, dy); 
     326       
     327      float[] c = line.getNodeCoords(line.getNumNodes()-2); 
     328      double[] cdub = {(double) c[0], (double) c[1]}; 
     329      double oldLen = line.getCurveLength(); 
     330      line.setCurveLength(oldLen + MathUtil.getDistance(cdub, 
     331            new double[]{dx, dy})); 
     332 
    313333      mode = BEG_EXTEND; 
    314334    } 
    315335    else if (mode == EXTEND || mode == EXTEND_ON_TAIL) { 
     336      float[][] lastSeg = {line.getNodeCoords(line.getNumNodes()-1), 
     337        line.getNodeCoords(line.getNumNodes() - 2)}; 
     338      double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
     339        {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
     340      double lastSegLength = MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
     341 
    316342      line.setLastNode(dx, dy); 
     343 
     344      float[][] newLastSeg = {line.getNodeCoords(line.getNumNodes() -1), 
     345        line.getNodeCoords(line.getNumNodes() - 2)}; 
     346      double[][] newLastSegD = {{(double) lastSeg[0][0], (double) 
     347        lastSeg[0][1]}, {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
     348      double newLastSegLength = MathUtil.getDistance(newLastSegD[0],  
     349          newLastSegD[1]); 
     350 
     351      double delta = newLastSegLength - lastSegLength; 
     352      //System.out.println("lastSegLength = " + lastSegLength); // TEMP 
     353      //System.out.println("newLastSegLength = " + newLastSegLength); 
     354      //System.out.println("delta =  " + delta); 
     355 
     356      line.setCurveLength(line.getCurveLength() + delta);      
    317357       
    318358      // determine if near head:  
     
    359399    } 
    360400    else if (mode == BEG_EXTEND) { 
     401      float[][] lastSeg = {line.getNodeCoords(line.getNumNodes() -1), line.getNodeCoords(line.getNumNodes() - 2)}; 
     402      double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
     403        {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
     404      double lastSegLength = MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
     405 
    361406      line.setLastNode(dx, dy); 
     407 
     408      float[][] newLastSeg = {line.getNodeCoords(line.getNumNodes() -1), 
     409        line.getNodeCoords(line.getNumNodes() - 2)}; 
     410      double[][] newLastSegD = {{(double) lastSeg[0][0], (double) 
     411        lastSeg[0][1]}, {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
     412      double newLastSegLength = MathUtil.getDistance(newLastSegD[0],  
     413          newLastSegD[1]); 
     414 
     415      double delta = newLastSegLength - lastSegLength; 
     416 
     417      line.setCurveLength(line.getCurveLength() + delta);  
    362418       
    363419      // determine if near head:  
     
    438494      line.setSelected(true); 
    439495      line = null; 
     496      selectedNode = -1; 
    440497    } 
    441498  } 
Note: See TracChangeset for help on using the changeset viewer.