Changeset 2032


Ignore:
Timestamp:
01/05/07 15:43:58 (13 years ago)
Author:
sorber
Message:

Dynamic selection of multiple objects with TransientSelectBox

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

Legend:

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

    r2024 r2032  
    4444  protected TransientSelectBox select; 
    4545 
     46  /** Array of OverlayObjects at current dimensional position */ 
     47  protected OverlayObject[] objs; 
     48 
     49  /** Array of the bounds of the OverlayObjects at the current dimensional position */ 
     50  protected float[][] bounds; 
     51 
    4652  // -- Constructor -- 
    4753 
     
    4955  public PointerTool(OverlayTransform overlay) { 
    5056    super(overlay, "Pointer", "Pointer", "pointer.png"); 
     57    bounds = null; 
    5158  } 
    5259 
     
    5966 
    6067    // pick nearest object 
    61     OverlayObject[] obj = overlay.getObjects(pos); 
     68    objs = overlay.getObjects(pos); 
     69    bounds = new float[objs.length][4]; 
     70 
    6271    double dist = Double.POSITIVE_INFINITY; 
    6372    int ndx = -1; 
    64     for (int i=0; i<obj.length; i++) { 
    65       double d = obj[i].getDistance(x, y); 
     73    for (int i=0; i<objs.length; i++) { 
     74      double d = objs[i].getDistance(x, y); 
    6675      if (d < dist) { 
    6776        dist = d; 
    6877        ndx = i; 
    6978      } 
     79 
     80      // assemble array of distances 
     81      float[] bound = new float[4]; 
     82      bound[0] = objs[i].getX(); 
     83      bound[1] = objs[i].getY(); 
     84      if (objs[i].hasEndpoint2()) { 
     85        bound[2] = objs[i].getX2(); 
     86        bound[3] = objs[i].getY2(); 
     87      } else { 
     88        bound[2] = bound[0]; 
     89        bound[3] = bound[1]; 
     90      } 
     91      bounds[i] = bound;  
    7092    } 
    7193 
    7294    double threshold = 0.02 * overlay.getScalingValue(); 
    73     boolean selected = dist < threshold && obj[ndx].isSelected(); 
     95    boolean selected = dist < threshold && objs[ndx].isSelected(); 
    7496     
    7597    if (!shift && !ctrl) { 
    7698      // deselect all previously selected objects 
    77       for (int i=0; i<obj.length; i++) obj[i].setSelected(false); 
     99      for (int i=0; i<objs.length; i++) objs[i].setSelected(false); 
    78100    } 
    79101 
     
    86108      } 
    87109      // select (or deselect) picked object 
    88       obj[ndx].setSelected(ctrl ? !selected : true); 
     110      objs[ndx].setSelected(ctrl ? !selected : true); 
    89111    } else { 
    90112      // record location of click 
     
    137159      // extend selection box 
    138160      select.setCorner (x, y); 
     161 
     162      // select objects inside the box 
     163      for (int i=0; i<bounds.length; i++) { 
     164        float bx1, bx2, by1, by2; 
     165        float tx1, tx2, ty1, ty2; 
     166        float ox1, ox2, oy1, oy2; 
     167         
     168        ox1 = bounds[i][0]; 
     169        oy1 = bounds[i][1]; 
     170        ox2 = bounds[i][2]; 
     171        oy2 = bounds[i][3]; 
     172 
     173        // un-oriented (disoriented?) box coordinates 
     174        tx1 = select.getX1(); 
     175        tx2 = select.getX2(); 
     176        ty1 = select.getY1(); 
     177        ty2 = select.getY2(); 
     178 
     179        // assign oriented coordinates of seletion box 
     180        if (tx1 < tx2) { bx1 = tx1; bx2 = tx2; } 
     181        else { bx1 = tx2; bx2 = tx1; } 
     182        if (ty1 < ty2) { by1 = ty1; by2 = ty2; } 
     183        else { by1 = ty2; by2 = ty1; } 
     184 
     185        System.out.println ("TSB coords: ("+tx1+","+ty1+"),("+tx2+","+ty2+")"); 
     186        System.out.println ("TSB adjust: ("+bx1+","+by1+"),("+bx2+","+by2+")"); 
     187        System.out.println ("Object coords: ("+ox1+","+oy1+"),("+ox2+","+oy2+")"); 
     188 
     189        // determine whether object i is inside or outside of selection box  
     190        if (bx1 < ox1 && ox1 < bx2 &&  
     191            bx1 < ox2 && ox2 < bx2 && 
     192            by1 < oy1 && oy1 < by2 && 
     193            by1 < oy2 && oy2 < by2 ) objs[i].setSelected(true); 
     194        else objs[i].setSelected (false); 
     195      } 
    139196      overlay.notifyListeners(new TransformEvent(overlay)); 
    140197    } 
  • trunk/loci/visbio/overlays/TransientSelectBox.java

    r2024 r2032  
    142142   
    143143      wholeTeam = new DataImpl[] {inField, outField}; 
    144       ret = new Tuple (wholeTeam); 
     144      ret = new Tuple (wholeTeam, false); 
    145145    } 
    146146    catch (VisADException exc) { exc.printStackTrace(); } 
     
    151151  /** Whether this select box is visible */ 
    152152  public boolean isVisible() { return visible; } 
     153 
     154  /** Gets X coordinate of the overlay's first endpoint. */ 
     155  public float getX1() { return x1; }  
     156 
     157  /** Gets X coordinate of the overlay's second endpoint. */ 
     158  public float getX2() { return x2; }  
     159   
     160  /** Gets Y coordinate of the overlay's second endpoint. */ 
     161  public float getY1() { return y1; }  
     162   
     163  /** Gets Y coordinate of the overlay's first endpoint. */ 
     164  public float getY2() { return y2; }  
    153165} 
Note: See TracChangeset for help on using the changeset viewer.