Changeset 2024


Ignore:
Timestamp:
01/04/07 17:12:36 (13 years ago)
Author:
sorber
Message:

Added shading to TransientSelectBox (rgb -> rgba for all OverlayObjects' data range)

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

Legend:

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

    r1989 r2024  
    489489   */ 
    490490  private OverlayFreeform getClosestFreeform(float x, float y) { 
     491    // returns only objects at the current dimensional position 
    491492    OverlayObject[] objects = overlay.getObjects(); 
    492493    //Q: Hey, are all of these OverlayFreeforms?  A: No, it returns OverlayObjects of all types 
     494 
    493495    OverlayFreeform closestFreeform = null; 
    494496    if (objects != null) { 
  • trunk/loci/visbio/overlays/OverlayArrow.java

    r1989 r2024  
    9191    float g = color.getGreen() / 255f; 
    9292    float b = color.getBlue() / 255f; 
    93     float[][] rangeSamples = new float[3][setSamples[0].length]; 
     93    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    9494    Arrays.fill(rangeSamples[0], r); 
    9595    Arrays.fill(rangeSamples[1], g); 
    9696    Arrays.fill(rangeSamples[2], b); 
     97    Arrays.fill(rangeSamples[3], 1.0f); 
    9798 
    9899    FlatField field = null; 
  • trunk/loci/visbio/overlays/OverlayBox.java

    r1390 r2024  
    8181    float g = color.getGreen() / 255f; 
    8282    float b = color.getBlue() / 255f; 
    83     float[][] rangeSamples = new float[3][setSamples[0].length]; 
     83    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    8484    Arrays.fill(rangeSamples[0], r); 
    8585    Arrays.fill(rangeSamples[1], g); 
    8686    Arrays.fill(rangeSamples[2], b); 
     87    Arrays.fill(rangeSamples[3], 1.0f); 
    8788 
    8889    FlatField field = null; 
  • trunk/loci/visbio/overlays/OverlayFreeform.java

    r1989 r2024  
    9595 
    9696      int len = fieldSet.getSamples(false)[0].length; 
    97       float[][] rangeSamples = new float[3][len]; 
     97      float[][] rangeSamples = new float[4][len]; 
    9898      Arrays.fill(rangeSamples[0], r); 
    9999      Arrays.fill(rangeSamples[1], g); 
    100100      Arrays.fill(rangeSamples[2], b); 
     101      Arrays.fill(rangeSamples[3], 1.0f); 
    101102 
    102103      FunctionType fieldType = new FunctionType(domain, range); 
  • trunk/loci/visbio/overlays/OverlayLine.java

    r1390 r2024  
    6060    float g = color.getGreen() / 255f; 
    6161    float b = color.getBlue() / 255f; 
    62     float[][] rangeSamples = new float[3][setSamples[0].length]; 
     62    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    6363    Arrays.fill(rangeSamples[0], r); 
    6464    Arrays.fill(rangeSamples[1], g); 
    6565    Arrays.fill(rangeSamples[2], b); 
     66    Arrays.fill(rangeSamples[3], 1.0f); 
    6667 
    6768    FlatField field = null; 
  • trunk/loci/visbio/overlays/OverlayMarker.java

    r1390 r2024  
    5959    float g = color.getGreen() / 255f; 
    6060    float b = color.getBlue() / 255f; 
    61     float[][] rangeSamples = new float[3][setSamples[0].length]; 
     61    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    6262    Arrays.fill(rangeSamples[0], r); 
    6363    Arrays.fill(rangeSamples[1], g); 
    6464    Arrays.fill(rangeSamples[2], b); 
     65    Arrays.fill(rangeSamples[3], 1.0f); 
    6566 
    6667    FlatField field = null; 
  • trunk/loci/visbio/overlays/OverlayObject.java

    r1989 r2024  
    204204    float g = c.getGreen() / 255f; 
    205205    float b = c.getBlue() / 255f; 
    206     float[][] fieldSamples = new float[3][count]; 
     206    float[][] fieldSamples = new float[4][count]; 
    207207    for (int i=0; i<count; i++) { 
    208208      fieldSamples[0][i] = r; 
    209209      fieldSamples[1][i] = g; 
    210210      fieldSamples[2][i] = b; 
     211      fieldSamples[3][i] = 1.0f; 
    211212    } 
    212213 
  • trunk/loci/visbio/overlays/OverlayOval.java

    r1390 r2024  
    127127    float g = color.getGreen() / 255f; 
    128128    float b = color.getBlue() / 255f; 
    129     float[][] rangeSamples = new float[3][setSamples[0].length]; 
     129    float[][] rangeSamples = new float[4][setSamples[0].length]; 
    130130    Arrays.fill(rangeSamples[0], r); 
    131131    Arrays.fill(rangeSamples[1], g); 
    132132    Arrays.fill(rangeSamples[2], b); 
     133    Arrays.fill(rangeSamples[3], 1.0f); 
    133134 
    134135    FlatField field = null; 
  • trunk/loci/visbio/overlays/OverlayText.java

    r1390 r2024  
    6262        new RealTuple(domain, new double[] {x1, y1})); 
    6363      field = new FieldImpl(fieldType, fieldSet); 
    64       field.setSample(0, overlay.getTextRangeValue(text, r, g, b), false); 
     64      field.setSample(0, overlay.getTextRangeValue(text, r, g, b, 1), false); 
    6565    } 
    6666    catch (VisADException exc) { exc.printStackTrace(); } 
  • trunk/loci/visbio/overlays/OverlayTransform.java

    r1995 r2024  
    4545  // -- Constants -- 
    4646 
    47   /** MathType for blue color mappings. */ 
     47  /** MathType for red color mappings. */ 
    4848  protected static final RealType RED_TYPE = 
    4949    RealType.getRealType("overlay_red"); 
    5050 
    51   /** MathType for blue color mappings. */ 
     51  /** MathType for green color mappings. */ 
    5252  protected static final RealType GREEN_TYPE = 
    5353    RealType.getRealType("overlay_green"); 
     
    5656  protected static final RealType BLUE_TYPE = 
    5757    RealType.getRealType("overlay_blue"); 
     58 
     59  /** MathType for alpha color mappings. */ 
     60  protected static final RealType ALPHA_TYPE = 
     61    RealType.getRealType("overlay_alpha"); 
    5862 
    5963  /** Overlay range type. */ 
     
    6569    try { 
    6670      rtt = new RealTupleType(new RealType[] { 
    67         RED_TYPE, GREEN_TYPE, BLUE_TYPE 
     71        RED_TYPE, GREEN_TYPE, BLUE_TYPE, ALPHA_TYPE 
    6872      }); 
    6973    } 
     
    120124    try { 
    121125      textRangeTuple = new TupleType(new ScalarType[] { 
    122         textType, RED_TYPE, GREEN_TYPE, BLUE_TYPE 
     126        textType, RED_TYPE, GREEN_TYPE, BLUE_TYPE, ALPHA_TYPE 
    123127      }); 
    124128    } 
     
    420424  /** Constructs a range value with the given component values. */ 
    421425  public Tuple getTextRangeValue(String text, 
    422     float r, float g, float b) 
     426    float r, float g, float b, float a) 
    423427  { 
    424428    Tuple tuple = null; 
     
    428432        new Real(RED_TYPE, r), 
    429433        new Real(GREEN_TYPE, g), 
    430         new Real(BLUE_TYPE, b) 
     434        new Real(BLUE_TYPE, b), 
     435        new Real(ALPHA_TYPE, a) 
    431436      }); 
    432437    } 
     
    519524    synchronized (overlays) { 
    520525      int size = overlays[q].size(); 
     526      DataImpl selectData = null; 
    521527      FieldImpl rgbField = null, txtField = null; 
    522528      try { 
    523529        if (size > 0) { 
    524           // compute number of selected objects and number of text objects 
    525           int rgbSize = 0, txtSize = 0, sel = 0, outline = 0, tsb = 0; 
    526           if (selectBox != null) tsb = 1;  
     530          // compute number of selected objects, text objects 
     531          int rgbSize = 0, txtSize = 0, sel = 0, outline = 0; 
    527532          for (int i=0; i<size; i++) { 
    528533            OverlayObject obj = (OverlayObject) overlays[q].elementAt(i); 
     
    541546            FunctionType fieldType = new FunctionType(index, 
    542547              new FunctionType(getDomainType(), getRangeType())); 
    543             GriddedSet fieldSet = new Integer1DSet(rgbSize + sel + outline + tsb); 
     548            GriddedSet fieldSet = new Integer1DSet(rgbSize + sel + outline); 
    544549            rgbField = new FieldImpl(fieldType, fieldSet); 
    545550            // compute overlay data for each non-text object 
     
    562567                obj.getSelectionGrid(true), false); 
    563568            } 
    564             // compute visual data for selectBox 
    565             if (selectBox != null) { 
    566               rgbField.setSample(rgbSize + sel + outline, selectBox.getData(), false); 
    567             } 
    568569          } 
    569570 
     
    583584          } 
    584585        } 
    585         if (rgbField == null && txtField == null) return null; 
    586         else if (rgbField == null) return txtField; 
    587         else if (txtField == null) return rgbField; 
    588         else return new Tuple(new Data[] {rgbField, txtField}, false); 
     586 
     587        // retrieve select box data 
     588        if (selectBox != null && selectBox.isVisible()) { 
     589            selectData = selectBox.getData(); 
     590        } 
     591 
     592        Vector v = new Vector(); 
     593        if (selectData != null) v.add(selectData); 
     594        if (rgbField != null) v.add(rgbField); 
     595        if (txtField != null) v.add(txtField); 
     596        if (v.size() == 0) return null; 
     597        else if (v.size() == 1) return (Data) v.elementAt(0); 
     598        Data[] data = (Data[]) v.toArray(new Data[0]); 
     599        return new Tuple(data, false); 
    589600      } 
    590601      catch (VisADException exc) { exc.printStackTrace(); } 
     
    615626      ScalarMap gMap = new ScalarMap(GREEN_TYPE, Display.Green); 
    616627      ScalarMap bMap = new ScalarMap(BLUE_TYPE, Display.Blue); 
     628      ScalarMap aMap = new ScalarMap(ALPHA_TYPE, Display.Alpha); 
    617629      rMap.setRange(0, 1); 
    618630      gMap.setRange(0, 1); 
    619631      bMap.setRange(0, 1); 
    620       maps = new ScalarMap[] {xMap, yMap, tMap, rMap, gMap, bMap}; 
     632      aMap.setRange(0, 1); 
     633      maps = new ScalarMap[] {xMap, yMap, tMap, rMap, gMap, bMap, aMap}; 
    621634    } 
    622635    catch (VisADException exc) { exc.printStackTrace(); } 
  • trunk/loci/visbio/overlays/PointerTool.java

    r1995 r2024  
    4141  protected float downX, downY;  
    4242 
    43   /** Selection box */ 
     43  /** The selection box which may be created by this tool */ 
    4444  protected TransientSelectBox select; 
    4545 
     
    5858    boolean ctrl = (mods & InputEvent.CTRL_MASK) != 0; 
    5959 
    60     // record location of click 
    61     downX = x; 
    62     downY = y; 
    63  
    64     // instantiate selection box 
    65     select = new TransientSelectBox(overlay, downX, downY); 
    66     overlay.addTSB (select); 
    67   
    6860    // pick nearest object 
    6961    OverlayObject[] obj = overlay.getObjects(pos); 
     
    8072    double threshold = 0.02 * overlay.getScalingValue(); 
    8173    boolean selected = dist < threshold && obj[ndx].isSelected(); 
    82  
     74     
    8375    if (!shift && !ctrl) { 
    8476      // deselect all previously selected objects 
     
    9587      // select (or deselect) picked object 
    9688      obj[ndx].setSelected(ctrl ? !selected : true); 
     89    } else { 
     90      // record location of click 
     91      downX = x; 
     92      downY = y; 
     93 
     94      // instantiate selection box 
     95      select = new TransientSelectBox(overlay, downX, downY); 
     96      overlay.addTSB (select); 
    9797    } 
    9898 
     
    112112      overlay.setTextDrawn(true); 
    113113      overlay.notifyListeners(new TransformEvent(overlay)); 
    114     } else { 
     114    } else if (select != null) { 
    115115      select = null; 
    116116      overlay.removeTSB(); 
     
    134134      grabY = y; 
    135135      overlay.notifyListeners(new TransformEvent(overlay)); 
    136     } else if (x != downX && y != downY) { 
     136    } else if (select != null) { 
    137137      // extend selection box 
    138138      select.setCorner (x, y); 
  • trunk/loci/visbio/overlays/TransientSelectBox.java

    r1995 r2024  
     1// 
     2// TransientSelectBox.java 
     3// 
     4 
     5/* 
     6VisBio application for visualization of multidimensional 
     7biological image data. Copyright (C) 2002-@year@ Curtis Rueden. 
     8 
     9This program is free software; you can redistribute it and/or modify 
     10it under the terms of the GNU General Public License as published by 
     11the Free Software Foundation; either version 2 of the License, or 
     12(at your option) any later version. 
     13 
     14This program is distributed in the hope that it will be useful, 
     15but WITHOUT ANY WARRANTY; without even the implied warranty of 
     16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     17GNU General Public License for more details. 
     18 
     19You should have received a copy of the GNU General Public License 
     20along with this program; if not, write to the Free Software 
     21Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     22*/ 
     23 
    124package loci.visbio.overlays; 
    225 
     
    629import java.awt.Color; 
    730 
     31/** TransientSelectBox represents the square that appears in a VisBio display 
     32 *  as a user drags the mouse to select overlays */ 
    833public class TransientSelectBox { 
    934 
     35  // -- Fields -- 
     36   
     37  /** Color of box */ 
    1038  private Color color; 
     39 
     40  /** Boundaries of box */ 
    1141  private float x1, x2, y1, y2; 
     42 
     43  /** Parent Transform */ 
    1244  private OverlayTransform overlay; 
    1345 
     46  /** Whether the box is visible; toggled off if box 
     47   *  boundaries would form an invalid GriddedSet */ 
     48  private boolean visible; 
     49   
     50  // -- Constants --  
     51  /** Sets the transparency of the interior of the select box */ 
     52  private float ALPHA_VALUE = 0.3f; 
     53 
     54  // -- Constructor --  
     55 
     56  /** Constructs a selection box  
     57   *  Initially, the box has zero area and is not visible 
     58   */ 
    1459  public TransientSelectBox(OverlayTransform overlay, float downX, float downY) { 
    1560    this.overlay = overlay; 
     
    1964    y2 = downY; 
    2065    color = Color.green; 
    21     // System.out.println("new transient select box at ("+x1+","+y1+")("+x2+","+y2+")"); // TEMP 
     66    visible = false; 
    2267  } 
    2368 
     69  // -- TransientSelectBox API Methods --  
     70 
     71  /** Sets coordinates of draggable box corner */ 
    2472  public void setCorner (float x, float y) { 
    2573    x2 = x; 
    2674    y2 = y; 
    27     //System.out.println("("+x1+","+y1+")("+x2+","+y2+")"); // TEMP 
     75    // toggle visible.  If x1 == x2 || y1 == y2, GriddedSet invalid. 
     76    if (x1 != x2 && y1 != y2) visible = true; 
     77    else visible = false; 
    2878  } 
    2979 
     80  /** Returns a VisAD data object representing this box  
     81   *  The data object is compound, consisting of 2 parts: 
     82   *  1) a solid GriddedSet of manifold dimension 1, the outline 
     83   *  2) a semi-transparent GriddedSet of manifold dimension 2, the interior 
     84   */ 
    3085  public DataImpl getData() { 
    3186    RealTupleType domain = overlay.getDomainType(); 
    3287    TupleType range = overlay.getRangeType(); 
    3388 
    34     float[][] setSamples = null; 
    35     GriddedSet fieldSet = null; 
     89    float[][] shadeSamples = null; 
     90    float[][] outlineSamples = null; 
     91    GriddedSet shadeSet = null; 
     92    GriddedSet outlineSet = null; 
    3693 
    3794    try { 
    38       setSamples = new float[][] { 
    39         {x1, x2, x2, x1, x1},  
    40         {y1, y1, y2, y2, y1} 
     95      shadeSamples = new float[][] { 
     96        {x1, x2, x1, x2},  
     97        {y1, y1, y2, y2} 
     98      }; 
     99 
     100      outlineSamples = new float[][] { 
     101        {x1, x1, x2, x2, x1},  
     102        {y1, y2, y2, y1, y1} 
    41103      }; 
    42104     
    43       fieldSet = new Gridded2DSet (domain,  
    44           setSamples, setSamples[0].length, null, null, null, false); 
     105      shadeSet = new Gridded2DSet(domain, 
     106          shadeSamples, 2, 2, null, null, null, false); 
     107 
     108      outlineSet = new Gridded2DSet(domain, outlineSamples,  
     109          outlineSamples[0].length, null, null, null, false); 
    45110    } 
     111    catch (SetException set ) { set.printStackTrace(); } 
    46112    catch (VisADException exc) { exc.printStackTrace(); } 
    47113 
     
    49115    float g = color.getGreen() / 255f; 
    50116    float b = color.getBlue() / 255f; 
    51     float[][] rangeSamples = new float[3][setSamples[0].length]; 
    52     Arrays.fill(rangeSamples[0], r); 
    53     Arrays.fill(rangeSamples[1], g); 
    54     Arrays.fill(rangeSamples[2], b); 
     117    float[][] shadeRangeSamples = new float[4][shadeSamples[0].length]; 
     118    Arrays.fill(shadeRangeSamples[0], r); 
     119    Arrays.fill(shadeRangeSamples[1], g); 
     120    Arrays.fill(shadeRangeSamples[2], b); 
     121    Arrays.fill(shadeRangeSamples[3], ALPHA_VALUE); 
    55122 
    56     FlatField field = null; 
     123    float[][] outlineRangeSamples = new float[4][outlineSamples[0].length]; 
     124    Arrays.fill(outlineRangeSamples[0], r); 
     125    Arrays.fill(outlineRangeSamples[1], g); 
     126    Arrays.fill(outlineRangeSamples[2], b); 
     127    Arrays.fill(outlineRangeSamples[3], 1.0f); 
     128 
     129    FlatField inField = null; 
     130    FlatField outField = null; 
     131    DataImpl[] wholeTeam = null; 
     132    Tuple ret = null; 
    57133    try { 
    58134      FunctionType fieldType = new FunctionType(domain, range); 
    59       field = new FlatField(fieldType, fieldSet); 
    60       field.setSamples(rangeSamples); 
     135      // interior field 
     136      inField = new FlatField(fieldType, shadeSet); 
     137      inField.setSamples(shadeRangeSamples); 
     138 
     139      // outline field 
     140      outField = new FlatField(fieldType, outlineSet); 
     141      outField.setSamples(outlineRangeSamples); 
     142   
     143      wholeTeam = new DataImpl[] {inField, outField}; 
     144      ret = new Tuple (wholeTeam); 
    61145    } 
    62146    catch (VisADException exc) { exc.printStackTrace(); } 
    63147    catch (RemoteException exc) { exc.printStackTrace(); } 
    64     return field;   
     148    return ret; 
    65149  } 
     150 
     151  /** Whether this select box is visible */ 
     152  public boolean isVisible() { return visible; } 
    66153} 
Note: See TracChangeset for help on using the changeset viewer.