Ignore:
Timestamp:
01/06/12 19:54:37 (8 years ago)
Author:
aivar
Message:

Refactoring.

Location:
trunk/projects/slim-plugin/src/main/java/loci/slim
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/slim-plugin/src/main/java/loci/slim/SLIMProcessor.java

    r7862 r7864  
    7070import loci.slim.ui.IStartStopListener; 
    7171import loci.slim.ui.IUserInterfacePanel; 
    72 import loci.slim.ui.IUserInterfacePanel.FitAlgorithm; 
    73 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    74 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
    7572import loci.slim.ui.IUserInterfacePanelListener; 
    7673import loci.slim.ui.UserInterfacePanel; 
     
    9390import imagej.slim.fitting.params.IFitResults; 
    9491import imagej.slim.fitting.config.Configuration; 
     92import imagej.slim.fitting.FitInfo; 
    9593import imagej.slim.fitting.FLIMImageFitter; 
    9694import imagej.slim.fitting.FLIMImageFitter.OutputImage; 
    97  
     95import imagej.slim.fitting.FitInfo.FitAlgorithm; 
     96import imagej.slim.fitting.FitInfo.FitFunction; 
     97import imagej.slim.fitting.FitInfo.FitRegion; 
     98import imagej.slim.fitting.FitInfo.NoiseModel; 
    9899 
    99100 
     
    113114    private static boolean OLD_STYLE = false; 
    114115     
    115     private imagej.slim.fitting.engine.IFittingEngine _fittingEngine; 
     116    private IFittingEngine _fittingEngine; 
    116117     
    117118    private static final String X = "X"; 
     
    153154    private Image<T> m_image; 
    154155    private LocalizableByDimCursor<T> m_cursor; 
    155  
    156     private ImageProcessor m_grayscaleImageProcessor; 
    157     private Canvas m_grayscaleCanvas; 
    158156 
    159157    private Image<DoubleType> m_fittedImage = null; 
     
    647645        // only one fit at a time 
    648646        synchronized (m_synchFit) { 
     647             
    649648            switch (m_region) { 
    650649                case SUMMED: 
     
    672671        } 
    673672    } 
     673     
     674    private FitInfo getFitInfo(IGrayScaleImage grayScalePanel, IUserInterfacePanel uiPanel) { 
     675        FitInfo fitInfo = new FitInfo(); 
     676        fitInfo.setChannel(grayScalePanel.getChannel()); 
     677        fitInfo.setRegion(uiPanel.getRegion()); 
     678        fitInfo.setAlgorithm(uiPanel.getAlgorithm()); 
     679        fitInfo.setFunction(uiPanel.getFunction()); 
     680        fitInfo.setNoiseModel(uiPanel.getNoiseModel()); 
     681        fitInfo.setFittedImages(uiPanel.getFittedImages()); 
     682        fitInfo.setAnalysisList(uiPanel.getAnalysisList()); 
     683        fitInfo.setFitAllChannels(uiPanel.getFitAllChannels()); 
     684        fitInfo.setStart(uiPanel.getStart()); 
     685        fitInfo.setStop(uiPanel.getStop()); 
     686        fitInfo.setThreshold(uiPanel.getThreshold()); 
     687        fitInfo.setChiSquareTarget(uiPanel.getChiSquareTarget()); 
     688        fitInfo.setBinning(uiPanel.getBinning()); 
     689         
     690        fitInfo.setX(uiPanel.getX()); 
     691        fitInfo.setY(uiPanel.getY()); 
     692        fitInfo.setParameterCount(uiPanel.getParameterCount()); 
     693         
     694         
     695        fitInfo.setParameters(uiPanel.getParameters()); 
     696        fitInfo.setFree(uiPanel.getFree()); 
     697        fitInfo.setRefineFit(uiPanel.getRefineFit()); 
     698        return fitInfo; 
     699    } 
     700     
     701    private void newFitData(IGrayScaleImage grayScalePanel, IUserInterfacePanel uiPanel) { 
     702        Image<DoubleType> fittedImage = null; 
     703        FitInfo fitInfo = new FitInfo(); 
     704   
     705        // only one fit at a time 
     706        synchronized (m_synchFit) { 
     707             
     708        } 
     709        m_channel        = grayScalePanel.getChannel(); 
     710 
     711        m_region         = uiPanel.getRegion(); // this is either SUMMED/ROI/POINT/EACH -- which type of fit 
     712        m_algorithm      = uiPanel.getAlgorithm(); 
     713        m_function       = uiPanel.getFunction(); 
     714        m_fitAllChannels = uiPanel.getFitAllChannels(); 
     715 
     716        m_x              = uiPanel.getX(); 
     717        m_y              = uiPanel.getY(); 
     718        m_startBin       = uiPanel.getStart(); 
     719        m_stopBin        = uiPanel.getStop(); 
     720        m_threshold      = uiPanel.getThreshold(); 
     721 
     722        m_param          = uiPanel.getParameters(); 
     723        m_free           = uiPanel.getFree(); 
     724    } 
    674725 
    675726    /* 
     
    9981049        LocalizableByDimCursor<T> pixelCursor = workImage.createLocalizableByDimCursor(); 
    9991050 
    1000         ICurveFitter curveFitter = getCurveFitter(uiPanel); //TODO where is this used? 
     1051        ICurveFitter curveFitterX = getCurveFitter(uiPanel); //TODO where is this used? 
    10011052        double params[] = uiPanel.getParameters(); 
    10021053 
     
    10111062        else { 
    10121063            // ask UI whether to use previous results 
    1013             useFittedParams = uiPanel.refineFit(); 
     1064            useFittedParams = uiPanel.getRefineFit(); 
    10141065        } 
    10151066        resultsCursor = m_fittedImage.createLocalizableByDimCursor(); 
     
    11861237    //TODO need to be a selfcontained function call 
    11871238    //  = gives you fitted images and a histogram tool 
     1239     
     1240    private Image<DoubleType> fitEachPixelLatest(IUserInterfacePanel uiPanel) { 
     1241         
     1242        // we need to generate the following for fitEachPixel nowadays: 
     1243         
     1244        // note that every fit type needs these, not just images 
     1245         
     1246        IFittingEngine fittingEngine = Configuration.getInstance().getFittingEngine(); // still have a _fittingEngine global also 
     1247            fittingEngine.setThreads(Configuration.getInstance().getThreads()); 
     1248            fittingEngine.setCurveFitter(Configuration.getInstance().getCurveFitter()); 
     1249        ChunkyPixel[] pixels;  
     1250        IGlobalFitParams globalFitParams; 
     1251        List<ILocalFitParams> localFitParams = new ArrayList<ILocalFitParams>(); 
     1252        FLIMImageFitter imageFitter; //it's confusing to have both an imageFitter and a fittingEngine 
     1253       
     1254        return null; 
     1255    } 
    11881256 
    11891257    private Image<DoubleType> fitEachPixelXYZ(IUserInterfacePanel uiPanel) { 
     
    12121280        else { 
    12131281            // ask UI whether to use previous results 
    1214             useFittedParams = uiPanel.refineFit(); 
     1282            useFittedParams = uiPanel.getRefineFit(); 
    12151283        } 
    12161284        resultsCursor = m_fittedImage.createLocalizableByDimCursor(); 
     
    13061374        return null; 
    13071375    } 
    1308  
    13091376    /* 
    13101377     * Helper function that processes an array of pixels.  Histogram and images 
    13111378     * are updated at the end of this function. 
    13121379     */ 
    1313     private void processPixelsXYZ(ICurveFitData[] data, ChunkyPixel[] pixels, FLIMImageFitter imageFitter) { 
     1380     
     1381     
     1382    /** 
     1383     * Helper function that processes an array of pixels.  Histogram and imagess 
     1384     * are updated at the end of this function. 
     1385     *  
     1386     * @param fittingEngine 
     1387     * @param pixels 
     1388     * @param globalFitParams 
     1389     * @param localFitParams 
     1390     * @param imageFitter  
     1391     */ 
     1392    private void processPixels(IFittingEngine fittingEngine, ChunkyPixel[] pixels, IGlobalFitParams globalFitParams, List<ILocalFitParams> localFitParams, FLIMImageFitter imageFitter) { 
     1393        List<IFitResults> results = fittingEngine.fit(globalFitParams, localFitParams); 
     1394 
     1395        for (int i = 0; i < results.size(); ++i) { 
     1396            IFitResults result = results.get(i); 
     1397            ChunkyPixel p = pixels[i]; 
     1398            int[] location = { p.getX(), p.getY() }; 
     1399            imageFitter.updatePixel(location, result.getParams()); 
     1400        } 
     1401 
     1402        imageFitter.recalcHistogram(); 
     1403    } 
     1404   
     1405    // copied 1/12 to modify into "processPixels" above: 
     1406    private void processPixelsXYZhuhuh(ICurveFitData[] data, ChunkyPixel[] pixels, FLIMImageFitter imageFitter) { 
    13141407        if (null == _fittingEngine) { 
    13151408            _fittingEngine = Configuration.getInstance().getFittingEngine(); 
     
    13601453  
    13611454    /* 
     1455     * Helper function that processes an array of pixels.  Histogram and images 
     1456     * are updated at the end of this function. 
     1457     */ 
     1458    private void processPixelsXYZ(ICurveFitData[] data, ChunkyPixel[] pixels, FLIMImageFitter imageFitter) { 
     1459        if (null == _fittingEngine) { 
     1460            _fittingEngine = Configuration.getInstance().getFittingEngine(); 
     1461            _fittingEngine.setThreads(Configuration.getInstance().getThreads()); 
     1462            _fittingEngine.setCurveFitter(Configuration.getInstance().getCurveFitter()); 
     1463        } 
     1464 
     1465        IGlobalFitParams globalFitParams = new GlobalFitParams(); 
     1466        globalFitParams.setFitAlgorithm(loci.curvefitter.ICurveFitter.FitAlgorithm.RLD_LMA); 
     1467        globalFitParams.setFitFunction(loci.curvefitter.ICurveFitter.FitFunction.SINGLE_EXPONENTIAL); 
     1468        globalFitParams.setNoiseModel(loci.curvefitter.ICurveFitter.NoiseModel.MAXIMUM_LIKELIHOOD); 
     1469        globalFitParams.setXInc(m_timeRange); 
     1470        globalFitParams.setPrompt(null); 
     1471        if (null != m_excitationPanel) { 
     1472            globalFitParams.setPrompt(m_excitationPanel.getValues(1)); 
     1473        } 
     1474        globalFitParams.setChiSquareTarget(data[0].getChiSquareTarget()); 
     1475 
     1476 
     1477        boolean[] free = { true, true, true }; 
     1478        globalFitParams.setFree(free); //TODO BAD! s/n/b hardcoded here 
     1479      //TODO KLUDGE  globalFitParams.setFree(translateFree(uiPanel.getFunction(), uiPanel.getFree())); 
     1480 
     1481        List<ILocalFitParams> dataList = new ArrayList<ILocalFitParams>(); 
     1482 
     1483        for (ICurveFitData datum : data) { 
     1484            ILocalFitParams localFitParams = new LocalFitParams(); 
     1485            localFitParams.setY(datum.getYCount()); 
     1486            localFitParams.setSig(datum.getSig()); 
     1487            localFitParams.setParams(datum.getParams()); 
     1488            localFitParams.setFitStart(m_startBin); 
     1489            localFitParams.setFitStop(m_stopBin); 
     1490            localFitParams.setYFitted(datum.getYFitted()); 
     1491            dataList.add(localFitParams); 
     1492        } 
     1493 
     1494        List<IFitResults> results = _fittingEngine.fit(globalFitParams, dataList); 
     1495 
     1496        for (int i = 0; i < results.size(); ++i) { 
     1497            IFitResults result = results.get(i); 
     1498            ChunkyPixel p = pixels[i]; 
     1499            int[] location = { p.getX(), p.getY() }; 
     1500            imageFitter.updatePixel(location, result.getParams()); 
     1501        } 
     1502 
     1503        imageFitter.recalcHistogram(); 
     1504    } 
     1505  
     1506    /* 
    13621507     * Fits each and every pixel.  This is the most complicated fit. 
    13631508     * 
     
    13921537        else { 
    13931538            // ask UI whether to use previous results 
    1394             useFittedParams = uiPanel.refineFit(); 
     1539            useFittedParams = uiPanel.getRefineFit(); 
    13951540        } 
    13961541        resultsCursor = m_fittedImage.createLocalizableByDimCursor(); 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/analysis/ISLIMAnalyzer.java

    r7668 r7864  
    3535package loci.slim.analysis; 
    3636 
    37 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    38 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
     37import imagej.slim.fitting.FitInfo.FitFunction; 
     38import imagej.slim.fitting.FitInfo.FitRegion; 
    3939 
    4040import mpicbg.imglib.image.Image; 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/analysis/SLIMAnalysis.java

    r7668 r7864  
    4141import java.util.List; 
    4242 
    43 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    44 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
     43import imagej.slim.fitting.FitInfo.FitFunction; 
     44import imagej.slim.fitting.FitInfo.FitRegion; 
    4545 
    4646import mpicbg.imglib.image.Image; 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/analysis/plugins/Display.java

    r7668 r7864  
    5252import loci.slim.colorizer.FiveColorColorize; 
    5353import loci.slim.colorizer.IColorize; 
    54 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    55 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
     54import imagej.slim.fitting.FitInfo.FitFunction; 
     55import imagej.slim.fitting.FitInfo.FitRegion; 
    5656 
    5757import mpicbg.imglib.cursor.LocalizableByDimCursor; 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/analysis/plugins/ExportToText.java

    r7668 r7864  
    4949import loci.slim.analysis.ISLIMAnalyzer; 
    5050import loci.slim.analysis.SLIMAnalyzer; 
    51 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    52 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
     51import imagej.slim.fitting.FitInfo.FitFunction; 
     52import imagej.slim.fitting.FitInfo.FitRegion; 
    5353 
    5454import mpicbg.imglib.cursor.LocalizableByDimCursor; 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/analysis/plugins/VisADAnalysisPlugin.java

    r7676 r7864  
    3838import ij.ImagePlus; 
    3939 
    40 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    41 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
     40import imagej.slim.fitting.FitInfo.FitFunction; 
     41import imagej.slim.fitting.FitInfo.FitRegion; 
    4242import loci.slim.analysis.ISLIMAnalyzer; 
    4343import loci.slim.analysis.SLIMAnalyzer; 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/ui/IUserInterfacePanel.java

    r7842 r7864  
    3737import javax.swing.JFrame; 
    3838 
     39import imagej.slim.fitting.FitInfo.FitAlgorithm; 
     40import imagej.slim.fitting.FitInfo.FitFunction; 
     41import imagej.slim.fitting.FitInfo.FitRegion; 
     42import imagej.slim.fitting.FitInfo.NoiseModel; 
     43 
    3944/** 
    4045 * Interface to the User Interface Panel 
     
    4752 */ 
    4853public interface IUserInterfacePanel { 
    49     public static enum FitRegion { 
    50         SUMMED, ROI, POINT, EACH 
    51     } 
    52  
    53     public static enum FitAlgorithm { 
    54        JAOLHO, SLIMCURVE_RLD, SLIMCURVE_LMA, SLIMCURVE_RLD_LMA 
    55     } 
    56  
    57     public static enum FitFunction { 
    58         SINGLE_EXPONENTIAL, DOUBLE_EXPONENTIAL, TRIPLE_EXPONENTIAL, STRETCHED_EXPONENTIAL 
    59     } 
    60  
    61     public static enum NoiseModel { 
    62         GAUSSIAN_FIT, POISSON_FIT, POISSON_DATA, MAXIMUM_LIKELIHOOD 
    63     } 
    64  
    6554 
    6655    /** 
     
    272261     * @return 
    273262     */ 
    274     public boolean refineFit(); 
     263    public boolean getRefineFit(); 
    275264} 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/ui/UserInterfacePanel.java

    r7842 r7864  
    6464import ij.gui.GenericDialog; 
    6565 
    66 import loci.slim.ui.IUserInterfacePanel.FitAlgorithm; 
    67 import loci.slim.ui.IUserInterfacePanel.FitFunction; 
    68 import loci.slim.ui.IUserInterfacePanel.FitRegion; 
     66import imagej.slim.fitting.FitInfo.FitAlgorithm; 
     67import imagej.slim.fitting.FitInfo.FitFunction; 
     68import imagej.slim.fitting.FitInfo.FitRegion; 
     69import imagej.slim.fitting.FitInfo.NoiseModel; 
    6970 
    7071/** 
     
    13261327    } 
    13271328 
    1328     public boolean refineFit() { 
     1329    public boolean getRefineFit() { 
    13291330        JCheckBox checkBox = null; 
    13301331        String function = (String) m_functionComboBox.getSelectedItem(); 
Note: See TracChangeset for help on using the changeset viewer.