Changeset 4226


Ignore:
Timestamp:
07/22/08 16:13:35 (12 years ago)
Author:
curtis
Message:
  • Split out shared VisAD types into their own class.
  • Add dummy implementation for lifetime view option.
Location:
trunk/loci/slim
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/slim/SlimPlotter.java

    r4224 r4226  
    177177 
    178178  // VisAD objects 
    179   private Unit[] bcUnits; 
    180   private RealType bType, cType; 
    181   private RealTupleType bc, bv, bcv; 
    182   private FunctionType bcvFunc, bcvFuncFit, bcvFuncRes; 
     179  private SlimTypes types; 
    183180  private ScalarMap zMap, zMapFit, zMapRes, vMap, vMapRes; 
    184181  //private ScalarMap vMapFit; 
     
    311308      // create types 
    312309      progress.setNote("Creating types"); 
    313       RealType xType = RealType.getRealType("element"); 
    314       RealType yType = RealType.getRealType("line"); 
    315       ScaledUnit ns = new ScaledUnit(1e-9, SI.second, "ns"); 
    316       ScaledUnit nm = new ScaledUnit(1e-9, SI.meter, "nm"); 
    317       bcUnits = new Unit[] {ns, nm}; 
    318       bType = RealType.getRealType("bin", ns); 
    319       cType = RealType.getRealType("channel", nm); 
    320       RealType vType = RealType.getRealType("count"); 
    321       RealTupleType xy = new RealTupleType(xType, yType); 
    322       FunctionType xyvFunc = new FunctionType(xy, vType); 
    323       Integer2DSet xySet = new Integer2DSet(xy, width, height); 
    324       FunctionType cxyvFunc = new FunctionType(cType, xyvFunc); 
    325       Linear1DSet cSet = new Linear1DSet(cType, 
    326         minWave, maxWave, channels, null, new Unit[] {nm}, null); 
    327       bc = new RealTupleType(bType, cType); 
    328       bv = new RealTupleType(bType, vType); 
    329       bcv = new RealTupleType(bType, cType, vType); 
    330       RealType vType2 = RealType.getRealType("value"); 
    331       RealTupleType vv = new RealTupleType(vType, vType2); 
    332       bcvFunc = new FunctionType(bc, vv); 
    333       RealType vTypeFit = RealType.getRealType("value_fit"); 
    334       bcvFuncFit = new FunctionType(bc, vTypeFit); 
    335       RealType vTypeRes = RealType.getRealType("value_res"); 
    336       bcvFuncRes = new FunctionType(bc, vTypeRes); 
     310      types = new SlimTypes(width, height, channels, minWave, maxWave); 
    337311      setProgress(progress, 710); // estimate: 71% 
    338312 
    339313      // plot intensity data in 2D display 
    340314      progress.setNote("Building displays"); 
    341  
    342       setProgress(progress, 720); // estimate: 72% 
    343       setProgress(progress, 730); // estimate: 73% 
    344       setProgress(progress, 740); // estimate: 74% 
    345       setProgress(progress, 750); // estimate: 75% 
    346315 
    347316      // plot decay curves in 3D display 
    348317      decayPlot = channels > 1 ? new DisplayImplJ3D("decay") : 
    349318        new DisplayImplJ3D("decay", new TwoDDisplayRendererJ3D()); 
    350       ScalarMap xMap = new ScalarMap(bType, Display.XAxis); 
    351       ScalarMap yMap = new ScalarMap(cType, Display.YAxis); 
     319      ScalarMap xMap = new ScalarMap(types.bType, Display.XAxis); 
     320      ScalarMap yMap = new ScalarMap(types.cType, Display.YAxis); 
    352321      DisplayRealType heightAxis = channels > 1 ? Display.ZAxis : Display.YAxis; 
    353       zMap = new ScalarMap(vType, heightAxis); 
    354       zMapFit = new ScalarMap(vTypeFit, heightAxis); 
    355       zMapRes = new ScalarMap(vTypeRes, heightAxis); 
    356       vMap = new ScalarMap(vType2, Display.RGB); 
    357       //vMapFit = new ScalarMap(vTypeFit, Display.RGB); 
    358       vMapRes = new ScalarMap(vTypeRes, Display.RGB); 
     322      zMap = new ScalarMap(types.vType, heightAxis); 
     323      zMapFit = new ScalarMap(types.vTypeFit, heightAxis); 
     324      zMapRes = new ScalarMap(types.vTypeRes, heightAxis); 
     325      vMap = new ScalarMap(types.vType2, Display.RGB); 
     326      //vMapFit = new ScalarMap(types.vTypeFit, Display.RGB); 
     327      vMapRes = new ScalarMap(types.vTypeRes, Display.RGB); 
    359328      decayPlot.addMap(xMap); 
    360329      if (channels > 1) decayPlot.addMap(yMap); 
     
    365334      //decayPlot.addMap(vMapFit); 
    366335      decayPlot.addMap(vMapRes); 
    367       setProgress(progress, 760); // estimate: 76% 
     336      setProgress(progress, 720); // estimate: 72% 
    368337 
    369338      decayRend = new DefaultRendererJ3D(); 
     
    397366        resRend.toggle(false); 
    398367      } 
    399       setProgress(progress, 770); // estimate: 77% 
     368      setProgress(progress, 750); // estimate: 75% 
    400369 
    401370      xMap.setRange(0, timeRange); 
     
    430399      values = new int[channels][height][width][timeBins]; 
    431400      float[][][] pix = new float[channels][1][width * height]; 
    432       FieldImpl field = new FieldImpl(cxyvFunc, cSet); 
     401      FieldImpl field = new FieldImpl(types.cxyvFunc, types.cSet); 
    433402      maxIntensity = new int[channels]; 
    434403      for (int c=0; c<channels; c++) { 
     
    451420            (height * c + h + 1) / (channels * height)); // estimate: 78% -> 92% 
    452421        } 
    453         FlatField ff = new FlatField(xyvFunc, xySet); 
     422        FlatField ff = new FlatField(types.xyvFunc, types.xySet); 
    454423        ff.setSamples(pix[c], false); 
    455424        field.setSample(c, ff); 
     
    516485        DataReferenceImpl peakRef = new DataReferenceImpl("peaks"); 
    517486        float peakTime = (float) (maxPeak * timeRange / (timeBins - 1)); 
    518         peakRef.setData(new Gridded2DSet(bc, 
     487        peakRef.setData(new Gridded2DSet(types.bc, 
    519488          new float[][] {{peakTime, peakTime}, {minWave, maxWave}}, 2)); 
    520489        decayPlot.addReferences(lineRend, peakRef, new ConstantMap[] { 
     
    533502      masterWindow.setContentPane(masterPane); 
    534503 
    535       twoDPane = new TwoDPane(this, field, 
    536         width, height, channels, globalMax, maxChan, cVisible, 
    537         xType, yType, vType, cType); 
     504      twoDPane = new TwoDPane(this, values, cVisible, types); 
    538505 
    539506      MenuBar menubar = new MenuBar(); 
     
    13001267          cc++; 
    13011268        } 
    1302         Gridded2DSet bcSet = new Gridded2DSet(bc, bcGrid, 
    1303           timeBins, numChanVis, null, bcUnits, null, false); 
     1269        Gridded2DSet bcSet = new Gridded2DSet(types.bc, bcGrid, 
     1270          timeBins, numChanVis, null, types.bcUnits, null, false); 
    13041271 
    13051272        // compile color values for 3D surface plot 
     
    13501317          } 
    13511318        } 
    1352         FlatField ff = new FlatField(bcvFunc, bcSet); 
     1319        FlatField ff = new FlatField(types.bcvFunc, bcSet); 
    13531320        ff.setSamples(new float[][] {samps, colors}, false); 
    13541321        decayRef.setData(doDataLines ? makeLines(ff) : ff); 
     
    13681335            } 
    13691336            if (channels > 1) { 
    1370               fwhmSets[c] = new Gridded3DSet(bcv, fwhmLines[c], 2); 
     1337              fwhmSets[c] = new Gridded3DSet(types.bcv, fwhmLines[c], 2); 
    13711338            } 
    13721339            else { 
    1373               fwhmSets[c] = new Gridded2DSet(bv, 
     1340              fwhmSets[c] = new Gridded2DSet(types.bv, 
    13741341                new float[][] {fwhmLines[c][0], fwhmLines[c][2]}, 2); 
    13751342            } 
     
    13871354            } 
    13881355          } 
    1389           FlatField fit = new FlatField(bcvFuncFit, bcSet); 
     1356          FlatField fit = new FlatField(types.bcvFuncFit, bcSet); 
    13901357          fit.setSamples(new float[][] {fitSamps}, false); 
    13911358          fitRef.setData(doFitLines ? makeLines(fit) : fit); 
     
    14011368            } 
    14021369          } 
    1403           FlatField res = new FlatField(bcvFuncRes, bcSet); 
     1370          FlatField res = new FlatField(types.bcvFuncRes, bcSet); 
    14041371          res.setSamples(new float[][] {residuals}, false); 
    14051372          resRef.setData(doResLines ? makeLines(res) : res); 
     
    15631530      // probably could eliminate this by writing cleaner logic to convert 
    15641531      // from 2D surface to 1D lines... 
    1565       Linear1DSet timeSet = new Linear1DSet(bType, 0, 
    1566         timeRange, timeBins, null, new Unit[] {bcUnits[0]}, null); 
     1532      Linear1DSet timeSet = new Linear1DSet(types.bType, 0, 
     1533        timeRange, timeBins, null, new Unit[] {types.bcUnits[0]}, null); 
    15671534      int numChanVis = 0; 
    15681535      for (int c=0; c<channels; c++) { 
     
    15751542          c * (maxWave - minWave) / (channels - 1) + minWave : 0; 
    15761543      } 
    1577       Gridded1DSet waveSet = new Gridded1DSet(cType, 
    1578         cGrid, numChanVis, null, new Unit[] {bcUnits[1]}, null, false); 
     1544      Gridded1DSet waveSet = new Gridded1DSet(types.cType, 
     1545        cGrid, numChanVis, null, new Unit[] {types.bcUnits[1]}, null, false); 
    15791546      ProductSet prodSet = new ProductSet(new SampledSet[] {timeSet, waveSet}); 
    15801547      float[][] samples = surface.getFloats(false); 
     
    15831550      surface.setSamples(samples, false); 
    15841551 
    1585       return (FieldImpl) surface.domainFactor(cType); 
     1552      return (FieldImpl) surface.domainFactor(types.cType); 
    15861553    } 
    15871554    catch (VisADException exc) { exc.printStackTrace(); } 
  • trunk/loci/slim/TwoDPane.java

    r4224 r4226  
    4343 
    4444/** 
    45  * Slim Plotter's 2D intensity pane. 
     45 * Slim Plotter's 2D image pane. 
    4646 * 
    4747 * <dl><dt><b>Source code:</b></dt> 
     
    5959  private SlimPlotter slim; 
    6060  private DisplayImpl iPlot; 
    61   private ScalarMap intensityMap; 
     61  private ScalarMap imageMap; 
     62  private DataReferenceImpl imageRef; 
    6263  private AnimationControl ac; 
    6364 
    6465  // data parameters 
    65   private int width, height; 
     66  private int[][][][] data; 
     67  private int channels, width, height, timeBins; 
    6668  private boolean[] cVisible; 
     69  private SlimTypes types; 
     70 
     71  // intensity parameters 
     72  private FieldImpl intensityField; 
     73  private int intensityMin, intensityMax; 
     74 
     75  // lifetime parameters 
     76  private FieldImpl lifetimeField; 
     77  private int lifetimeMin, lifetimeMax; 
    6778 
    6879  // ROI parameters 
     
    8596  // -- Constructor -- 
    8697 
    87   public TwoDPane(SlimPlotter slim, FieldImpl field, 
    88     int width, int height, int channels, 
    89     int globalMax, int maxChan, boolean[] cVisible, 
    90     RealType xType, RealType yType, RealType vType, RealType cType) 
     98  public TwoDPane(SlimPlotter slim, int[][][][] data, 
     99    boolean[] cVisible, SlimTypes types) 
    91100    throws VisADException, RemoteException 
    92101  { 
    93102    this.slim = slim; 
    94     this.width = width; 
    95     this.height = height; 
     103    this.data = data; 
    96104    this.cVisible = cVisible; 
     105    this.types = types; 
     106 
     107    channels = data.length; 
     108    width = data[0].length; 
     109    height = data[0][0].length; 
     110    timeBins = data[0][0][0].length; 
    97111 
    98112    roiCount = width * height; 
    99113    roiPercent = 100; 
    100114 
    101     // plot intensity data 
    102     iPlot = new DisplayImplJ3D("intensity", new TwoDDisplayRendererJ3D()); 
     115    // create 2D display 
     116    iPlot = new DisplayImplJ3D("image", new TwoDDisplayRendererJ3D()); 
    103117    iPlot.getMouseBehavior().getMouseHelper().setFunctionMap(new int[][][] { 
    104118      {{MouseHelper.DIRECT, MouseHelper.NONE}, // L, shift-L 
     
    112126    iPlot.addDisplayListener(this); 
    113127 
    114     iPlot.addMap(new ScalarMap(xType, Display.XAxis)); 
    115     iPlot.addMap(new ScalarMap(yType, Display.YAxis)); 
    116     intensityMap = new ScalarMap(vType, Display.RGB); 
    117     iPlot.addMap(intensityMap); 
    118     iPlot.addMap(new ScalarMap(cType, Display.Animation)); 
    119     DataReferenceImpl intensityRef = new DataReferenceImpl("intensity"); 
    120     iPlot.addReference(intensityRef); 
     128    iPlot.addMap(new ScalarMap(types.xType, Display.XAxis)); 
     129    iPlot.addMap(new ScalarMap(types.yType, Display.YAxis)); 
     130    imageMap = new ScalarMap(types.vType, Display.RGB); 
     131    iPlot.addMap(imageMap); 
     132    iPlot.addMap(new ScalarMap(types.cType, Display.Animation)); 
     133    imageRef = new DataReferenceImpl("image"); 
     134    iPlot.addReference(imageRef); 
    121135 
    122136    // set up curve manipulation renderer 
     
    132146    } 
    133147    final DataReferenceImpl curveRef = new DataReferenceImpl("curve"); 
    134     RealTupleType xy = new RealTupleType(xType, yType); 
     148    RealTupleType xy = new RealTupleType(types.xType, types.yType); 
    135149    UnionSet dummyCurve = new UnionSet(new Gridded2DSet[] { 
    136       new Gridded2DSet(xy, new float[][] {{0}, {0}}, 1) 
     150      new Gridded2DSet(types.xy, new float[][] {{0}, {0}}, 1) 
    137151    }); 
    138152    curveRef.setData(dummyCurve); 
     
    158172      iPlot.make_matrix(0, 0, 0, 0.85, 0, 0, 0)); 
    159173 
    160     intensityRef.setData(field); 
    161     ColorControl cc = (ColorControl) iPlot.getControl(ColorControl.class); 
    162     cc.setTable(ColorControl.initTableGreyWedge(new float[3][256])); 
    163  
    164174    // lay out components 
    165175    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 
     
    202212    minLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); 
    203213    minPane.add(minLabel); 
    204     minField = new JTextField("0", 4); 
     214    minField = new JTextField(4); 
    205215    minField.setMaximumSize(minField.getPreferredSize()); 
    206216    minField.setToolTipText("<html>" + 
    207       "Adjusts intensity plot's minimum color value.<br>" + 
     217      "Adjusts image plot's minimum color value.<br>" + 
    208218      "Anything less than this value appears black.</html>"); 
    209219    minField.getDocument().addDocumentListener(this); 
     
    217227    minLabel.setPreferredSize(maxLabel.getPreferredSize()); 
    218228    maxPane.add(maxLabel); 
    219     maxField = new JTextField("" + globalMax, 4); 
     229    maxField = new JTextField(4); 
    220230    maxField.setMaximumSize(maxField.getPreferredSize()); 
    221231    maxField.setToolTipText("<html>" + 
    222       "Adjusts intensity plot's maximum color value.<br>" + 
     232      "Adjusts image plot's maximum color value.<br>" + 
    223233      "Anything greater than this value appears white.</html>"); 
    224234    maxField.getDocument().addDocumentListener(this); 
     
    227237    cSlider = new JSlider(1, channels, 1); 
    228238    cSlider.setToolTipText( 
    229       "Selects the channel to display in the 2D intensity plot above"); 
     239      "Selects the channel to display in the 2D image plot above"); 
    230240    cSlider.setSnapToTicks(true); 
    231241    cSlider.setMajorTickSpacing(channels / 4); 
     
    242252    cToggle.setEnabled(channels > 1); 
    243253    sliderPane.add(cToggle); 
    244  
    245     rescaleMinMax(); 
    246254 
    247255    viewModePane.add(new JLabel("View mode:")); 
     
    262270    viewModePane.add(spectraMode); 
    263271 
     272    int maxChan = doIntensity(); 
     273 
    264274    cSlider.setValue(maxChan + 1); 
    265275  } 
     
    284294      slim.plotData(true, true, false); 
    285295    } 
    286     else if (src == intensityMode) { 
    287       // TODO 
    288     } 
    289     else if (src == lifetimeMode) { 
    290       // TODO 
    291     } 
    292     else if (src == spectraMode) { 
    293       // TODO - spectral projection 
    294       // https://skyking.microscopy.wisc.edu/trac/java/ticket/86 
    295     } 
     296    else if (src == intensityMode) doIntensity(); 
     297    else if (src == lifetimeMode) doLifetime(); 
     298    else if (src == spectraMode) doSpectra(); 
    296299  } 
    297300 
     
    393396  } 
    394397 
     398  private void resetMinMax(int min, int max) { 
     399    minField.getDocument().removeDocumentListener(this); 
     400    maxField.getDocument().removeDocumentListener(this); 
     401    minField.setText("" + min); 
     402    maxField.setText("" + max); 
     403    minField.getDocument().addDocumentListener(this); 
     404    maxField.getDocument().addDocumentListener(this); 
     405    rescaleMinMax(); 
     406  } 
     407 
    395408  private void rescaleMinMax() { 
    396409    try { 
    397410      int min = Integer.parseInt(minField.getText()); 
    398411      int max = Integer.parseInt(maxField.getText()); 
    399       intensityMap.setRange(min, max); 
     412      imageMap.setRange(min, max); 
    400413    } 
    401414    catch (NumberFormatException exc) { } 
    402415    catch (VisADException exc) { exc.printStackTrace(); } 
    403416    catch (RemoteException exc) { exc.printStackTrace(); } 
     417  } 
     418 
     419  private int doIntensity() { 
     420    int maxChan = 0; 
     421    try { 
     422      if (intensityField == null) { 
     423        intensityField = new FieldImpl(types.cxyvFunc, types.cSet); 
     424        intensityMin = intensityMax = 0; 
     425        maxChan = 0; 
     426        for (int c=0; c<channels; c++) { 
     427          float[][] samples = new float[1][width * height]; 
     428          for (int h=0; h<height; h++) { 
     429            for (int w=0; w<width; w++) { 
     430              int sum = 0; 
     431              for (int t=0; t<timeBins; t++) sum += data[c][h][w][t]; 
     432              if (sum > intensityMax) { 
     433                intensityMax = sum; 
     434                maxChan = c; 
     435              } 
     436              samples[0][width * h + w] = sum; 
     437            } 
     438          } 
     439          FlatField ff = new FlatField(types.xyvFunc, types.xySet); 
     440          ff.setSamples(samples, false); 
     441          intensityField.setSample(c, ff); 
     442        } 
     443      } 
     444      imageRef.setData(intensityField); 
     445 
     446      // reset to grayscale color map 
     447      ColorControl cc = (ColorControl) iPlot.getControl(ColorControl.class); 
     448      cc.setTable(ColorControl.initTableGreyWedge(new float[3][256])); 
     449 
     450      resetMinMax(intensityMin, intensityMax); 
     451    } 
     452    catch (VisADException exc) { exc.printStackTrace(); } 
     453    catch (RemoteException exc) { exc.printStackTrace(); } 
     454    return maxChan; 
     455  } 
     456 
     457  private void doLifetime() { 
     458    try { 
     459      if (lifetimeField == null) { 
     460        lifetimeField = new FieldImpl(types.cxyvFunc, types.cSet); 
     461        lifetimeMin = lifetimeMax = 0; 
     462        for (int c=0; c<channels; c++) { 
     463          float[][] samples = new float[1][width * height]; 
     464          for (int h=0; h<height; h++) { 
     465            for (int w=0; w<width; w++) { 
     466              // TODO 
     467              float val = 100 * (float) (Math.cos(w/10.0) * Math.sin(h/10.0)); 
     468              samples[0][width * h + w] = val; 
     469              if (val < lifetimeMin) lifetimeMin = (int) Math.floor(val); 
     470              if (val > lifetimeMax) lifetimeMax = (int) Math.ceil(val); 
     471            } 
     472          } 
     473          FlatField ff = new FlatField(types.xyvFunc, types.xySet); 
     474          ff.setSamples(samples, false); 
     475          lifetimeField.setSample(c, ff); 
     476        } 
     477      } 
     478      imageRef.setData(lifetimeField); 
     479 
     480      // reset to HSV color map 
     481      ColorControl cc = (ColorControl) iPlot.getControl(ColorControl.class); 
     482      cc.setTable(ColorControl.initTableHSV(new float[3][256])); 
     483 
     484      resetMinMax(lifetimeMin, lifetimeMax); 
     485    } 
     486    catch (VisADException exc) { exc.printStackTrace(); } 
     487    catch (RemoteException exc) { exc.printStackTrace(); } 
     488  } 
     489 
     490  private void doSpectra() { 
     491    // TODO 
     492    // https://skyking.microscopy.wisc.edu/trac/java/ticket/86 
    404493  } 
    405494 
Note: See TracChangeset for help on using the changeset viewer.