Changeset 2261


Ignore:
Timestamp:
02/13/07 16:58:18 (13 years ago)
Author:
curtis
Message:

Rearrange GUI to accommodate interactive color table;
add ability to exclude last 1.5 ns from curve fitting;
fix initial dialog closure/cancelation.

File:
1 edited

Legend:

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

    r2178 r2261  
    44 
    55/* 
    6 Coded in 2006-@year@ by Curtis Rueden, for Long Yan and others. 
     6Coded in 2006-@year@ by Curtis Rueden, with suggestions from 
     7Long Yan, Steve Trier, Kraig Kumfer and Paolo Provenzano. 
    78Permission is granted to use this code for anything. 
    89*/ 
     
    3233import visad.bom.CurveManipulationRendererJ3D; 
    3334import visad.java3d.*; 
     35import visad.util.ColorMapWidget; 
    3436 
    3537/** A tool for visualization of spectral lifetime data. */ 
     
    7173  private float timeRange; 
    7274  private int minWave, waveStep, maxWave; 
    73   private boolean adjustPeaks; 
     75  private boolean adjustPeaks, cutEnd; 
    7476  private boolean[] cVisible; 
    7577  private int maxPeak; 
     78  private int[] maxIntensity; 
    7679 
    7780  // ROI parameters 
     
    9295  private JDialog paramDialog; 
    9396  private JTextField wField, hField, tField, cField, trField, wlField, sField; 
    94   private JCheckBox peaksBox; 
     97  private JCheckBox peaksBox, cutBox; 
    9598 
    9699  // GUI components for intensity pane 
     
    227230    paramPane.setBorder(new EmptyBorder(10, 10, 10, 10)); 
    228231    paramDialog.setContentPane(paramPane); 
    229     paramPane.setLayout(new GridLayout(10, 3)); 
     232    paramPane.setLayout(new GridLayout(11, 3)); 
    230233    wField = addRow(paramPane, "Image width", width, "pixels"); 
    231234    hField = addRow(paramPane, "Image height", height, "pixels"); 
     
    240243    // row 8 
    241244    peaksBox = new JCheckBox("Align peaks", true); 
     245    peaksBox.setToolTipText("<html>Computes the peak of each spectral " + 
     246      "channel, and aligns those peaks <br>to match by adjusting the " + 
     247      "lifetime histograms. This option corrects<br>for skew across channels " + 
     248      "caused by the multispectral detector's<br>variable system response " + 
     249      "time between channels. This option must<br>be enabled to perform " + 
     250      "exponential curve fitting.</html>"); 
    242251    paramPane.add(peaksBox); 
    243252    paramPane.add(new JLabel()); 
    244253    paramPane.add(new JLabel()); 
    245     // row 9 
     254    // row 8 
     255    cutBox = new JCheckBox("Cut 1.5ns from fit", true); 
     256    cutBox.setToolTipText("<html>When performing exponential curve fitting, " + 
     257      "excludes the last 1.5 ns<br>from the computation. This option is " + 
     258      "useful because the end of the <br>the lifetime histogram sometimes " + 
     259      "drops off unexpectedly, skewing<br>the fit results.</html>"); 
     260    paramPane.add(cutBox); 
     261    paramPane.add(new JLabel()); 
     262    paramPane.add(new JLabel()); 
     263    // row 10 
    246264    paramPane.add(new JLabel()); 
    247265    paramPane.add(new JLabel()); 
    248266    paramPane.add(new JLabel()); 
    249     // row 10 
     267    // row 11 
    250268    paramPane.add(new JLabel()); 
    251269    paramPane.add(ok); 
     
    256274      (screenSize.height - ps.height) / 2); 
    257275    paramDialog.setVisible(true); 
     276    if (cVisible == null) System.exit(0); // dialog canceled (closed with X) 
    258277    maxWave = minWave + (channels - 1) * waveStep; 
    259278    roiCount = width * height; 
     
    297316      minWave, maxWave, channels, null, new Unit[] {nm}, null); 
    298317    bc = new RealTupleType(bType, cType); 
    299     RealType vType2 = RealType.getRealType("color"); 
     318    RealType vType2 = RealType.getRealType("tau"); 
    300319    RealTupleType vv = new RealTupleType(vType, vType2); 
    301320    bcvFunc = new FunctionType(bc, vv); 
     
    451470    float[][][] pix = new float[channels][1][width * height]; 
    452471    FieldImpl field = new FieldImpl(cxyvFunc, cSet); 
    453     int max = 0; 
    454     int maxChan = 0; 
     472    maxIntensity = new int[channels]; 
    455473    for (int c=0; c<channels; c++) { 
    456474      int oc = timeBins * width * height * c; 
     
    463481            int ndx = 2 * (oc + oh + ow + t); 
    464482            int val = DataTools.bytesToInt(data, ndx, 2, true); 
    465             if (val > max) { 
    466               max = val; 
    467               maxChan = c; 
    468             } 
     483            if (val > maxIntensity[c]) maxIntensity[c] = val; 
    469484            values[c][h][w][t] = val; 
    470485            sum += val; 
     
    479494      ff.setSamples(pix[c], false); 
    480495      field.setSample(c, ff); 
     496    } 
     497 
     498    // compute channel with brightest intensity 
     499    int maxChan = 0; 
     500    int max = 0; 
     501    for (int c=0; c<channels; c++) { 
     502      if (maxIntensity[c] > max) { 
     503        max = maxIntensity[c]; 
     504        maxChan = c; 
     505      } 
    481506    } 
    482507 
     
    538563        new ConstantMap(-1, Display.ZAxis), 
    539564        new ConstantMap(0, Display.Blue), 
    540 //        new ConstantMap(2, Display.LineWidth) 
     565        //new ConstantMap(2, Display.LineWidth) 
    541566      }); 
    542567    } 
     
    651676    decayPane.add(decayLabel, BorderLayout.NORTH); 
    652677 
    653     JPanel options = new JPanel(); 
    654     options.setBorder(new EmptyBorder(8, 5, 8, 5)); 
    655     options.setLayout(new BoxLayout(options, BoxLayout.Y_AXIS)); 
     678    ColorMapWidget colorWidget = new ColorMapWidget(vMap); 
     679    Dimension prefSize = colorWidget.getPreferredSize(); 
     680    colorWidget.setPreferredSize(new Dimension(prefSize.width, 0)); 
     681 
     682    showData = new JCheckBox("Data", true); 
     683    showData.setToolTipText("Toggles visibility of raw data"); 
     684    showData.addActionListener(this); 
     685    showScale = new JCheckBox("Scale", true); 
     686    showScale.setToolTipText("Toggles visibility of scale bars"); 
     687    showScale.addActionListener(this); 
     688    showBox = new JCheckBox("Box", true); 
     689    showBox.setToolTipText("Toggles visibility of bounding box"); 
     690    showBox.addActionListener(this); 
     691    showLine = new JCheckBox("Line", adjustPeaks); 
     692    showLine.setToolTipText( 
     693      "Toggles visibility of aligned peaks indicator line"); 
     694    showLine.setEnabled(adjustPeaks); 
     695    showLine.addActionListener(this); 
     696    showFit = new JCheckBox("Fit", false); 
     697    showFit.setToolTipText("Toggles visibility of fitted curves"); 
     698    showFit.setEnabled(adjustPeaks); 
     699    showFit.addActionListener(this); 
     700    showResiduals = new JCheckBox("Residuals", false); 
     701    showResiduals.setToolTipText( 
     702      "Toggles visibility of fitted curve residuals"); 
     703    showResiduals.setEnabled(adjustPeaks); 
     704    showResiduals.addActionListener(this); 
    656705 
    657706    linear = new JRadioButton("Linear", true); 
     
    696745    colorTau.setEnabled(adjustPeaks && channels > 1); 
    697746 
     747    zOverride = new JCheckBox("", false); 
     748    zOverride.setToolTipText("Toggles manual override of Z axis scale (Count)"); 
     749    zOverride.addActionListener(this); 
     750    zScaleValue = new JTextField(9); 
     751    zScaleValue.setToolTipText("Overridden Z axis scale value"); 
     752    zScaleValue.setEnabled(false); 
     753    zScaleValue.getDocument().addDocumentListener(this); 
     754 
     755    exportData = new JButton("Export"); 
     756    exportData.setToolTipText( 
     757      "Exports the selected ROI's raw data to a text file"); 
     758    exportData.addActionListener(this); 
     759 
    698760    numCurves = new JSpinner(new SpinnerNumberModel(1, 1, 9, 1)); 
    699761    numCurves.setToolTipText("Number of components in exponential fit"); 
     
    701763    numCurves.addChangeListener(this); 
    702764 
     765    setProgress(progress, 990); // estimate: 99% 
     766    if (progress.isCanceled()) System.exit(0); 
     767 
    703768    JPanel showPanel = new JPanel(); 
    704769    showPanel.setBorder(new TitledBorder("Show")); 
    705     showPanel.setLayout(new BoxLayout(showPanel, BoxLayout.X_AXIS)); 
    706  
    707     showData = new JCheckBox("Data", true); 
    708     showData.setToolTipText("Toggles visibility of raw data"); 
    709     showData.addActionListener(this); 
     770    showPanel.setLayout(new BoxLayout(showPanel, BoxLayout.Y_AXIS)); 
    710771    showPanel.add(showData); 
    711     showScale = new JCheckBox("Scale", true); 
    712     showScale.setToolTipText("Toggles visibility of scale bars"); 
    713     showScale.addActionListener(this); 
    714772    showPanel.add(showScale); 
    715     showBox = new JCheckBox("Box", true); 
    716     showBox.setToolTipText("Toggles visibility of bounding box"); 
    717     showBox.addActionListener(this); 
    718773    showPanel.add(showBox); 
    719     showLine = new JCheckBox("Line", adjustPeaks); 
    720     showLine.setToolTipText( 
    721       "Toggles visibility of aligned peaks indicator line"); 
    722     showLine.setEnabled(adjustPeaks); 
    723     showLine.addActionListener(this); 
    724774    showPanel.add(showLine); 
    725     showFit = new JCheckBox("Fit", false); 
    726     showFit.setToolTipText("Toggles visibility of fitted curves"); 
    727     showFit.setEnabled(adjustPeaks); 
    728     showFit.addActionListener(this); 
    729775    showPanel.add(showFit); 
    730     showResiduals = new JCheckBox("Residuals", false); 
    731     showResiduals.setToolTipText( 
    732       "Toggles visibility of fitted curve residuals"); 
    733     showResiduals.setEnabled(adjustPeaks); 
    734     showResiduals.addActionListener(this); 
    735776    showPanel.add(showResiduals); 
    736777 
     
    738779    scalePanel.setBorder(new TitledBorder("Z Scale Override")); 
    739780    scalePanel.setLayout(new BoxLayout(scalePanel, BoxLayout.X_AXIS)); 
    740  
    741     zOverride = new JCheckBox("", false); 
    742     zOverride.setToolTipText("Toggles manual override of Z axis scale (Count)"); 
    743     zOverride.addActionListener(this); 
    744781    scalePanel.add(zOverride); 
    745     zScaleValue = new JTextField(9); 
    746     zScaleValue.setToolTipText("Overridden Z axis scale value"); 
    747     zScaleValue.setEnabled(false); 
    748     zScaleValue.getDocument().addDocumentListener(this); 
    749782    scalePanel.add(zScaleValue); 
    750783 
    751     exportData = new JButton("Export"); 
    752     exportData.setToolTipText( 
    753       "Exports the selected ROI's raw data to a text file"); 
    754     exportData.addActionListener(this); 
    755  
    756     setProgress(progress, 990); // estimate: 99% 
    757     if (progress.isCanceled()) System.exit(0); 
    758  
    759     JPanel leftPanel = new JPanel() { 
     784    JPanel colorPanel = new JPanel(); 
     785    colorPanel.setBorder(new TitledBorder("Color Mapping")); 
     786    colorPanel.setLayout(new BorderLayout()); 
     787    colorPanel.add(colorWidget); 
     788 
     789    JPanel miscRow1 = new JPanel(); 
     790    miscRow1.setLayout(new BoxLayout(miscRow1, BoxLayout.X_AXIS)); 
     791    miscRow1.add(makeRadioPanel("Scale", linear, log)); 
     792    miscRow1.add(makeRadioPanel("Projection", perspective, parallel)); 
     793    miscRow1.add(makeRadioPanel("Data", dataSurface, dataLines)); 
     794 
     795    JPanel miscRow2 = new JPanel(); 
     796    miscRow2.setLayout(new BoxLayout(miscRow2, BoxLayout.X_AXIS)); 
     797    miscRow2.add(makeRadioPanel("Fit", fitSurface, fitLines)); 
     798    miscRow2.add(makeRadioPanel("Residuals", resSurface, resLines)); 
     799    miscRow2.add(makeRadioPanel("Colors", colorHeight, colorTau)); 
     800 
     801    JPanel miscRow3 = new JPanel(); 
     802    miscRow3.setLayout(new BoxLayout(miscRow3, BoxLayout.X_AXIS)); 
     803    miscRow3.add(scalePanel); 
     804    miscRow3.add(Box.createHorizontalStrut(5)); 
     805    miscRow3.add(exportData); 
     806    //miscRow3.add(numCurves); 
     807 
     808    JPanel miscPanel = new JPanel(); 
     809    miscPanel.setLayout(new BoxLayout(miscPanel, BoxLayout.Y_AXIS)); 
     810    miscPanel.add(miscRow1); 
     811    miscPanel.add(miscRow2); 
     812    miscPanel.add(miscRow3); 
     813 
     814    JPanel options = new JPanel(); 
     815    options.setBorder(new EmptyBorder(8, 5, 8, 5)); 
     816    options.setLayout(new BoxLayout(options, BoxLayout.X_AXIS)); 
     817    options.add(colorPanel); 
     818    options.add(showPanel); 
     819    options.add(miscPanel); 
     820    decayPane.add(options, BorderLayout.SOUTH); 
     821    masterPane.add(decayPane, BorderLayout.CENTER); 
     822 
     823    JPanel rightPanel = new JPanel() { 
    760824      public Dimension getMaximumSize() { 
    761825        Dimension pref = getPreferredSize(); 
     
    764828      } 
    765829    }; 
    766     leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS)); 
    767     leftPanel.add(intensityPane); 
    768     leftPanel.add(console.getWindow().getContentPane()); 
     830    rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS)); 
     831    rightPanel.add(intensityPane); 
     832    rightPanel.add(console.getWindow().getContentPane()); 
    769833    BreakawayPanel breakawayPanel = new BreakawayPanel(masterPane, 
    770834      "Intensity Data - " + file.getName(), false); 
    771     breakawayPanel.setEdge(BorderLayout.WEST); 
     835    breakawayPanel.setEdge(BorderLayout.EAST); 
    772836    breakawayPanel.setUpEnabled(false); 
    773837    breakawayPanel.setDownEnabled(false); 
    774     breakawayPanel.setContentPane(leftPanel); 
    775  
    776     JPanel options1 = new JPanel(); 
    777     options1.setLayout(new BoxLayout(options1, BoxLayout.X_AXIS)); 
    778     options1.add(makeRadioPanel("Scale", linear, log)); 
    779     options1.add(makeRadioPanel("Projection", perspective, parallel)); 
    780     options1.add(makeRadioPanel("Data", dataSurface, dataLines)); 
    781     options1.add(makeRadioPanel("Fit", fitSurface, fitLines)); 
    782     options1.add(makeRadioPanel("Residuals", resSurface, resLines)); 
    783     options1.add(makeRadioPanel("Colors", colorHeight, colorTau)); 
    784 //    options1.add(numCurves); 
    785     JPanel options2 = new JPanel(); 
    786     options2.setLayout(new BoxLayout(options2, BoxLayout.X_AXIS)); 
    787     options2.add(showPanel); 
    788     options2.add(scalePanel); 
    789     options2.add(Box.createHorizontalStrut(5)); 
    790     options2.add(exportData); 
    791     options.add(options1); 
    792     options.add(options2); 
    793     decayPane.add(options, BorderLayout.SOUTH); 
    794     masterPane.add(decayPane, BorderLayout.CENTER); 
     838    breakawayPanel.setContentPane(rightPanel); 
    795839 
    796840    setProgress(progress, 999); // estimate: 99.9% 
     
    9611005      waveStep = parse(sField.getText(), waveStep); 
    9621006      adjustPeaks = peaksBox.isSelected(); 
     1007      cutEnd = cutBox.isSelected(); 
    9631008      cVisible = new boolean[channels]; 
    9641009      Arrays.fill(cVisible, true); 
     
    11421187          params[2] = 0; 
    11431188        } 
    1144   //      for (int i=0; i<numExp; i++) { 
    1145   //        // initial guess for (a, b, c) 
    1146   //        int e = 3 * i; 
    1147   //        params[e] = (numExp - i) * maxVal / (numExp + 1); 
    1148   //        params[e + 1] = 1; 
    1149   //        params[e + 2] = 0; 
    1150   //      } 
     1189        //for (int i=0; i<numExp; i++) { 
     1190        //  // initial guess for (a, b, c) 
     1191        //  int e = 3 * i; 
     1192        //  params[e] = (numExp - i) * maxVal / (numExp + 1); 
     1193        //  params[e + 1] = 1; 
     1194        //  params[e + 2] = 0; 
     1195        //} 
    11511196        int num = timeBins - maxPeak; 
     1197 
     1198        // HACK - cut off last 1.5 ns from lifetime histogram, 
     1199        // to improve accuracy of fit. 
     1200        if (cutEnd) { 
     1201          int cutBins = (int) (1.5f * timeBins / timeRange); 
     1202          if (num > cutBins + 5) num -= cutBins; 
     1203        } 
     1204 
    11521205        float[] xVals = new float[num]; 
    11531206        for (int i=0; i<num; i++) xVals[i] = i; 
Note: See TracChangeset for help on using the changeset viewer.