Search in sources :

Example 1 with YesNoCancelDialog

use of ij.gui.YesNoCancelDialog in project GDSC-SMLM by aherbert.

the class PeakFit method setup.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.filter.PlugInFilter#setup(java.lang.String, ij.ImagePlus)
	 */
public int setup(String arg, ImagePlus imp) {
    SMLMUsageTracker.recordPlugin(this.getClass(), arg);
    plugin_flags = FLAGS;
    extraOptions = Utils.isExtraOptions();
    maximaIdentification = (arg != null && arg.contains("spot"));
    fitMaxima = (arg != null && arg.contains("maxima"));
    simpleFit = (arg != null && arg.contains("simple"));
    boolean runSeries = (arg != null && arg.contains("series"));
    ImageSource imageSource = null;
    if (fitMaxima) {
        imp = null;
        // The image source will be found from the peak results.
        if (!showMaximaDialog())
            return DONE;
        MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
        if (results == null || results.size() == 0) {
            IJ.error(TITLE, "No results could be loaded");
            return DONE;
        }
        // Check for single frame
        singleFrame = results.getHead().getFrame();
        for (PeakResult result : results.getResults()) {
            if (singleFrame != result.getFrame()) {
                singleFrame = 0;
                break;
            }
        }
        imageSource = results.getSource();
        plugin_flags |= NO_IMAGE_REQUIRED;
    } else if (runSeries) {
        imp = null;
        // Select input folder
        String inputDirectory;
        inputDirectory = IJ.getDirectory("Select image series ...");
        //inputDirectory = getInputDirectory("Select image series ...");
        if (inputDirectory == null)
            return DONE;
        // Load input series ...
        SeriesOpener series;
        if (extraOptions)
            series = new SeriesOpener(inputDirectory, true, numberOfThreads);
        else
            series = new SeriesOpener(inputDirectory);
        if (series.getNumberOfImages() == 0) {
            IJ.error(TITLE, "No images in the selected directory:\n" + inputDirectory);
            return DONE;
        }
        SeriesImageSource seriesImageSource = new SeriesImageSource(getName(series.getImageList()), series);
        seriesImageSource.setLogProgress(true);
        if (extraOptions) {
            numberOfThreads = Math.max(1, series.getNumberOfThreads());
            seriesImageSource.setNumberOfThreads(numberOfThreads);
        }
        imageSource = seriesImageSource;
        plugin_flags |= NO_IMAGE_REQUIRED;
    } else {
        if (imp == null) {
            IJ.noImage();
            return DONE;
        }
        // Check it is not a previous result
        if (imp.getTitle().endsWith(IJImagePeakResults.IMAGE_SUFFIX)) {
            IJImageSource tmpImageSource = null;
            // Check the image to see if it has an image source XML structure in the info property
            Object o = imp.getProperty("Info");
            Pattern pattern = Pattern.compile("Source: (<.*IJImageSource>.*<.*IJImageSource>)", Pattern.DOTALL);
            Matcher match = pattern.matcher((o == null) ? "" : o.toString());
            if (match.find()) {
                ImageSource source = ImageSource.fromXML(match.group(1));
                if (source instanceof IJImageSource) {
                    tmpImageSource = (IJImageSource) source;
                    if (!tmpImageSource.open()) {
                        tmpImageSource = null;
                    } else {
                        imp = WindowManager.getImage(tmpImageSource.getName());
                    }
                }
            }
            if (tmpImageSource == null) {
                // Look for a parent using the title
                String parentTitle = imp.getTitle().substring(0, imp.getTitle().length() - IJImagePeakResults.IMAGE_SUFFIX.length() - 1);
                ImagePlus parentImp = WindowManager.getImage(parentTitle);
                if (parentImp != null) {
                    tmpImageSource = new IJImageSource(parentImp);
                    imp = parentImp;
                }
            }
            String message = "The selected image may be a previous fit result";
            if (tmpImageSource != null) {
                // are missing
                if (!Utils.isNullOrEmpty(tmpImageSource.getName()))
                    message += " of: \n \n" + tmpImageSource.getName();
                message += " \n \nFit the parent?";
            } else
                message += " \n \nDo you want to continue?";
            YesNoCancelDialog d = new YesNoCancelDialog(null, TITLE, message);
            if (tmpImageSource == null) {
                if (!d.yesPressed())
                    return DONE;
            } else {
                if (d.yesPressed())
                    imageSource = tmpImageSource;
                if (d.cancelPressed())
                    return DONE;
            }
        }
        if (imageSource == null)
            imageSource = new IJImageSource(imp);
    }
    time = -1;
    if (!initialiseImage(imageSource, getBounds(imp), false)) {
        IJ.error(TITLE, "Failed to initialise the source image: " + imageSource.getName());
        return DONE;
    }
    int flags = showDialog(imp);
    if ((flags & DONE) == 0) {
        // Repeat so that we pass in the selected option for ignoring the bounds.
        // This should not be necessary since it is set within the readDialog method.
        //if (ignoreBoundsForNoise)
        //	initialiseImage(imageSource, bounds, ignoreBoundsForNoise);
        initialiseFitting();
    }
    return flags;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) SeriesImageSource(gdsc.smlm.ij.SeriesImageSource) SeriesOpener(gdsc.smlm.ij.utils.SeriesOpener) ImagePlus(ij.ImagePlus) PeakResult(gdsc.smlm.results.PeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult) IJImageSource(gdsc.smlm.ij.IJImageSource) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) YesNoCancelDialog(ij.gui.YesNoCancelDialog) AggregatedImageSource(gdsc.smlm.results.AggregatedImageSource) IJImageSource(gdsc.smlm.ij.IJImageSource) SeriesImageSource(gdsc.smlm.ij.SeriesImageSource) InterlacedImageSource(gdsc.smlm.results.InterlacedImageSource) ImageSource(gdsc.smlm.results.ImageSource)

Example 2 with YesNoCancelDialog

use of ij.gui.YesNoCancelDialog in project GDSC-SMLM by aherbert.

the class Configuration method refreshSettings.

private void refreshSettings(String newFilename) {
    if (newFilename != null && new File(newFilename).exists()) {
        YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), TITLE, "Reload settings from file");
        d.setVisible(true);
        if (d.yesPressed()) {
            // Reload the settings and update the GUI
            // XXX : This does not deal with loading settings into fields that are not displayed,
            // e.g. for configuring the Fit Solvers. This could be done by writing into
            // a class scope settings instance (loaded in showDialog()). However the user would not 
            // see all the changes that have been written, since the later dialogs are shown depending 
            // on what options are initially configured. 
            GlobalSettings settings = SettingsManager.unsafeLoadSettings(newFilename, false);
            if (settings == null)
                return;
            FitEngineConfiguration config = settings.getFitEngineConfiguration();
            FitConfiguration fitConfig = config.getFitConfiguration();
            Calibration calibration = settings.getCalibration();
            textNmPerPixel.setText("" + calibration.getNmPerPixel());
            textGain.setText("" + calibration.getGain());
            textEMCCD.setState(calibration.isEmCCD());
            textExposure.setText("" + calibration.getExposureTime());
            textInitialPeakStdDev0.setText("" + fitConfig.getInitialPeakStdDev0());
            textInitialPeakStdDev1.setText("" + fitConfig.getInitialPeakStdDev1());
            textInitialAngleD.setText("" + fitConfig.getInitialAngle());
            textDataFilterType.select(config.getDataFilterType().ordinal());
            textDataFilter.select(config.getDataFilter(0).ordinal());
            textSmooth.setText("" + config.getSmooth(0));
            textSearch.setText("" + config.getSearch());
            textBorder.setText("" + config.getBorder());
            textFitting.setText("" + config.getFitting());
            textFitSolver.select(fitConfig.getFitSolver().ordinal());
            textFitFunction.select(fitConfig.getFitFunction().ordinal());
            textFailuresLimit.setText("" + config.getFailuresLimit());
            textIncludeNeighbours.setState(config.isIncludeNeighbours());
            textNeighbourHeightThreshold.setText("" + config.getNeighbourHeightThreshold());
            textResidualsThreshold.setText("" + config.getResidualsThreshold());
            textDuplicateDistance.setText("" + fitConfig.getDuplicateDistance());
            textCoordinateShiftFactor.setText("" + fitConfig.getCoordinateShiftFactor());
            textSignalStrength.setText("" + fitConfig.getSignalStrength());
            textMinPhotons.setText("" + fitConfig.getMinPhotons());
            textMinWidthFactor.setText("" + fitConfig.getMinWidthFactor());
            textWidthFactor.setText("" + fitConfig.getWidthFactor());
            textPrecisionThreshold.setText("" + fitConfig.getPrecisionThreshold());
        }
    }
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) YesNoCancelDialog(ij.gui.YesNoCancelDialog) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) Calibration(gdsc.smlm.results.Calibration) File(java.io.File)

Example 3 with YesNoCancelDialog

use of ij.gui.YesNoCancelDialog in project GDSC-SMLM by aherbert.

the class ResultsManager method addFileResults.

private void addFileResults(PeakResultsList resultsList, boolean showDeviations, boolean showEndFrame, boolean showId) {
    if (resultsSettings.resultsFilename != null && resultsSettings.resultsFilename.length() > 0) {
        // Remove extension
        resultsSettings.resultsFilename = Utils.replaceExtension(resultsSettings.resultsFilename, resultsSettings.getResultsFileFormat().getExtension());
        if (fileInput && inputFilename.equals(resultsSettings.resultsFilename)) {
            IJ.log(TITLE + ": Input and output files are the same, skipping output ...");
            return;
        }
        // Check if file exists
        File file = new File(resultsSettings.resultsFilename);
        if (file.exists()) {
            YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), TITLE, "Overwrite existing file?\n" + resultsSettings.resultsFilename);
            if (!d.yesPressed())
                return;
        }
        File parent = file.getParentFile();
        if (parent != null && parent.exists()) {
            PeakResults r;
            switch(resultsSettings.getResultsFileFormat()) {
                case GDSC_BINARY:
                    r = new BinaryFilePeakResults(resultsSettings.resultsFilename, showDeviations, showEndFrame, showId);
                    break;
                case GDSC_TEXT:
                    r = new FilePeakResults(resultsSettings.resultsFilename, showDeviations, showEndFrame, showId);
                    break;
                case MALK:
                    r = new MALKFilePeakResults(resultsSettings.resultsFilename);
                    break;
                case TSF:
                    r = new TSFPeakResultsWriter(resultsSettings.resultsFilename);
                    break;
                default:
                    throw new RuntimeException("Unsupported file format: " + resultsSettings.getResultsFileFormat());
            }
            if (r instanceof FilePeakResults) {
                FilePeakResults fr = (FilePeakResults) r;
                fr.setPeakIdColumnName("Frame");
            }
            resultsList.addOutput(r);
        }
    }
}
Also used : MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) TSFPeakResultsWriter(gdsc.smlm.results.TSFPeakResultsWriter) PeakResults(gdsc.smlm.results.PeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) YesNoCancelDialog(ij.gui.YesNoCancelDialog) File(java.io.File) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults)

Aggregations

YesNoCancelDialog (ij.gui.YesNoCancelDialog)3 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)2 File (java.io.File)2 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)1 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)1 IJImageSource (gdsc.smlm.ij.IJImageSource)1 SeriesImageSource (gdsc.smlm.ij.SeriesImageSource)1 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)1 IJTablePeakResults (gdsc.smlm.ij.results.IJTablePeakResults)1 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)1 SeriesOpener (gdsc.smlm.ij.utils.SeriesOpener)1 AggregatedImageSource (gdsc.smlm.results.AggregatedImageSource)1 BinaryFilePeakResults (gdsc.smlm.results.BinaryFilePeakResults)1 Calibration (gdsc.smlm.results.Calibration)1 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)1 FilePeakResults (gdsc.smlm.results.FilePeakResults)1 ImageSource (gdsc.smlm.results.ImageSource)1 InterlacedImageSource (gdsc.smlm.results.InterlacedImageSource)1 MALKFilePeakResults (gdsc.smlm.results.MALKFilePeakResults)1 PeakResult (gdsc.smlm.results.PeakResult)1