Changeset 1841


Ignore:
Timestamp:
11/21/06 17:59:18 (14 years ago)
Author:
curtis
Message:

Better startup progress bar; hooks in place for changing 3-D plot coloring.

File:
1 edited

Legend:

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

    r1771 r1841  
    122122    console.getTextArea().setRows(10); 
    123123 
     124    // progress estimate: 
     125    // * Reading data - 70% 
     126    // * Creating types - 1% 
     127    // * Building displays - 7% 
     128    // * Constructing images - 14% 
     129    // * Adjusting peaks - 4% 
     130    // * Creating plots - 4% 
    124131    ProgressMonitor progress = new ProgressMonitor(null, 
    125       "Launching SlimPlotter", "Initializing", 0, 16 + 8); 
     132      "Launching SlimPlotter", "Initializing", 0, 1000); 
    126133    progress.setMillisToPopup(0); 
    127134    progress.setMillisToDecideToPopup(0); 
    128     int p = 0; 
    129135 
    130136    // check for required libraries 
     
    198204    minWave = 400; 
    199205    waveStep = 10; 
    200     progress.setMaximum(adjustPeaks ? 
    201       (channels * height + 2 * channels + 10) : (channels * height + 8)); 
    202     progress.setNote("Creating user interface"); 
    203206 
    204207    // show dialog confirming data parameters 
     
    239242    roiCount = width * height; 
    240243    roiPercent = 100; 
    241     progress.setProgress(++p); 
     244 
     245    // pop up progress monitor 
     246    progress.setProgress(1); // estimate: 0.1% 
     247    if (progress.isCanceled()) System.exit(0); 
     248 
     249    // read pixel data 
    242250    progress.setNote("Reading data"); 
    243  
    244     // read pixel data 
    245251    DataInputStream fin = new DataInputStream(new FileInputStream(file)); 
    246252    fin.skipBytes(offset); // skip to data 
    247253    byte[] data = new byte[2 * channels * height * width * timeBins]; 
    248     fin.readFully(data); 
     254    int blockSize = 65536; 
     255    for (int off=0; off<data.length; off+=blockSize) { 
     256      int len = data.length - off; 
     257      if (len > blockSize) len = blockSize; 
     258      fin.readFully(data, off, len); 
     259      progress.setProgress(700 * 
     260        (off + blockSize) / data.length); // estimate: 0% -> 70% 
     261      if (progress.isCanceled()) System.exit(0); 
     262    } 
    249263    fin.close(); 
    250     progress.setProgress(++p); 
    251     if (progress.isCanceled()) System.exit(0); 
    252264 
    253265    // create types 
     
    260272    bType = RealType.getRealType("bin", ns); 
    261273    cType = RealType.getRealType("channel", nm); 
    262     RealType vType = RealType.getRealType("value"); 
     274    RealType vType = RealType.getRealType("count"); 
    263275    RealTupleType xy = new RealTupleType(xType, yType); 
    264276    FunctionType xyvFunc = new FunctionType(xy, vType); 
     
    268280      minWave, maxWave, channels, null, new Unit[] {nm}, null); 
    269281    bc = new RealTupleType(bType, cType); 
    270     bcvFunc = new FunctionType(bc, vType); 
     282    RealType vType2 = RealType.getRealType("color"); 
     283    RealTupleType vv = new RealTupleType(vType, vType2); 
     284    bcvFunc = new FunctionType(bc, vv); 
    271285    RealType vTypeFit = RealType.getRealType("value_fit"); 
    272286    bcvFuncFit = new FunctionType(bc, vTypeFit); 
    273287    RealType vTypeRes = RealType.getRealType("value_res"); 
    274288    bcvFuncRes = new FunctionType(bc, vTypeRes); 
    275     progress.setProgress(++p); 
     289    progress.setProgress(710); // estimate: 71% 
    276290    if (progress.isCanceled()) System.exit(0); 
    277291 
     
    289303    iPlot.enableEvent(DisplayEvent.MOUSE_DRAGGED); 
    290304    iPlot.addDisplayListener(this); 
     305    progress.setProgress(720); // estimate: 72% 
     306    if (progress.isCanceled()) System.exit(0); 
    291307 
    292308    iPlot.addMap(new ScalarMap(xType, Display.XAxis)); 
     
    296312    DataReferenceImpl intensityRef = new DataReferenceImpl("intensity"); 
    297313    iPlot.addReference(intensityRef); 
     314    progress.setProgress(730); // estimate: 73% 
     315    if (progress.isCanceled()) System.exit(0); 
    298316 
    299317    // set up curve manipulation renderer in 2D display 
     
    329347      new ConstantMap(0.1, Display.Alpha) 
    330348    }); 
     349    progress.setProgress(740); // estimate: 74% 
     350    if (progress.isCanceled()) System.exit(0); 
    331351 
    332352    ac = (AnimationControl) iPlot.getControl(AnimationControl.class); 
    333353    iPlot.getProjectionControl().setMatrix( 
    334354      iPlot.make_matrix(0, 0, 0, 0.85, 0, 0, 0)); 
    335     progress.setProgress(++p); 
     355 
     356    progress.setProgress(750); // estimate: 75% 
    336357    if (progress.isCanceled()) System.exit(0); 
    337358 
     
    354375    //decayPlot.addMap(vMapFit); 
    355376    decayPlot.addMap(vMapRes); 
     377    progress.setProgress(760); // estimate: 76% 
     378    if (progress.isCanceled()) System.exit(0); 
    356379 
    357380    decayRend = new DefaultRendererJ3D(); 
     
    372395      resRend.toggle(false); 
    373396    } 
     397    progress.setProgress(770); // estimate: 77% 
     398    if (progress.isCanceled()) System.exit(0); 
    374399 
    375400    xMap.setRange(0, timeRange); 
     
    398423    pc.setAspectCartesian( 
    399424      new double[] {2, 1, 1}); 
    400     progress.setProgress(++p); 
     425    progress.setProgress(780); // estimate: 78% 
    401426    if (progress.isCanceled()) System.exit(0); 
    402427 
    403428    // convert byte data to unsigned shorts 
    404     progress.setNote("Constructing images "); 
     429    progress.setNote("Constructing images"); 
    405430    values = new int[channels][height][width][timeBins]; 
    406431    float[][][] pix = new float[channels][1][width * height]; 
     
    411436      int oc = timeBins * width * height * c; 
    412437      for (int h=0; h<height; h++) { 
    413         progress.setProgress(++p); 
    414         if (progress.isCanceled()) System.exit(0); 
    415438        int oh = timeBins * width * h; 
    416439        for (int w=0; w<width; w++) { 
     
    429452          pix[c][0][width * h + w] = sum; 
    430453        } 
     454        progress.setProgress(780 + 140 * 
     455          (height * c + h + 1) / (channels * height)); // estimate: 78% -> 92% 
     456        if (progress.isCanceled()) System.exit(0); 
    431457      } 
    432458      FlatField ff = new FlatField(xyvFunc, xySet); 
     
    434460      field.setSample(c, ff); 
    435461    } 
    436     progress.setProgress(++p); 
    437     if (progress.isCanceled()) System.exit(0); 
    438462 
    439463    // adjust peaks 
    440464    if (adjustPeaks) { 
    441       progress.setNote("Adjusting peaks "); 
     465      progress.setNote("Adjusting peaks"); 
    442466      int[] peaks = new int[channels]; 
    443467      for (int c=0; c<channels; c++) { 
    444         progress.setProgress(++p); 
    445         if (progress.isCanceled()) System.exit(0); 
    446468        int[] sum = new int[timeBins]; 
    447469        for (int h=0; h<height; h++) { 
     
    459481        } 
    460482        peaks[c] = ndx; 
    461       } 
    462       progress.setProgress(++p); 
    463       if (progress.isCanceled()) System.exit(0); 
     483        progress.setProgress(920 + 20 * 
     484          (c + 1) / channels); // estimate: 92% -> 94% 
     485        if (progress.isCanceled()) System.exit(0); 
     486      } 
    464487      maxPeak = 0; 
    465488      for (int c=1; c<channels; c++) { 
     
    468491      log("Aligning peaks to tmax = " + maxPeak); 
    469492      for (int c=0; c<channels; c++) { 
    470         progress.setProgress(++p); 
    471         if (progress.isCanceled()) System.exit(0); 
    472493        int shift = maxPeak - peaks[c]; 
    473494        if (shift > 0) { 
     
    483504            " (shifting by " + shift + ")"); 
    484505        } 
    485       } 
    486       progress.setProgress(++p); 
    487       if (progress.isCanceled()) System.exit(0); 
     506        progress.setProgress(940 + 20 * 
     507          (c + 1) / channels); // estimate: 94% -> 96% 
     508        if (progress.isCanceled()) System.exit(0); 
     509      } 
    488510 
    489511      // add yellow line to indicate adjusted peak position 
     
    528550    intensityPane.add(iPlotPane, BorderLayout.CENTER); 
    529551 
     552    progress.setProgress(970); // estimate: 97% 
     553    if (progress.isCanceled()) System.exit(0); 
     554 
    530555    JPanel sliderPane = new JPanel(); 
    531556    sliderPane.setLayout(new BoxLayout(sliderPane, BoxLayout.X_AXIS)); 
     
    547572    cc.setTable(ColorControl.initTableGreyWedge(new float[3][256])); 
    548573 
    549     progress.setProgress(++p); 
     574    progress.setProgress(980); // estimate: 98% 
    550575    if (progress.isCanceled()) System.exit(0); 
    551576 
     
    606631    exportData.addActionListener(this); 
    607632 
     633    progress.setProgress(99); // estimate: 99% 
     634    if (progress.isCanceled()) System.exit(0); 
     635 
    608636    JPanel leftPanel = new JPanel() { 
    609637      public Dimension getMaximumSize() { 
     
    641669    masterPane.add(decayPane, BorderLayout.CENTER); 
    642670 
     671    progress.setProgress(999); // estimate: 99.9% 
     672    if (progress.isCanceled()) System.exit(0); 
     673 
    643674    // show window on screen 
    644675    masterWindow.pack(); 
     
    648679      (screen.height - size.height) / 2); 
    649680    masterWindow.setVisible(true); 
    650     progress.setProgress(++p); 
     681    progress.setProgress(1000); 
    651682    progress.close(); 
    652683    plotData(true, true); 
     
    10031034        timeBins, numChanVis, null, bcUnits, null, false); 
    10041035 
     1036      // compile color values for 3D surface plot 
     1037      float[] colors = new float[numChanVis * timeBins]; 
     1038      for (int c=0, cc=0; c<channels; c++) { 
     1039        if (!cVisible[c]) continue; 
     1040        for (int t=0; t<timeBins; t++) { 
     1041          int ndx = timeBins * c + t; 
     1042          colors[ndx] = samps[ndx]; // CTR TODO: use Tau value for this channel 
     1043        } 
     1044        cc++; 
     1045      } 
     1046 
    10051047      // construct "Data" plot 
    10061048      FlatField ff = new FlatField(bcvFunc, bcSet); 
    1007       ff.setSamples(new float[][] {samps}, false); 
     1049      ff.setSamples(new float[][] {samps, colors}, false); 
    10081050      decayRef.setData(doDataLines ? makeLines(ff) : ff); 
    10091051 
Note: See TracChangeset for help on using the changeset viewer.