Search in sources :

Example 1 with NonBlockingGenericDialog

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

the class SpotFinderPreview method showDialog.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.filter.ExtendedPlugInFilter#showDialog(ij.ImagePlus, java.lang.String,
	 * ij.plugin.filter.PlugInFilterRunner)
	 */
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
    this.o = imp.getOverlay();
    this.imp = imp;
    String filename = SettingsManager.getSettingsFilename();
    GlobalSettings settings = SettingsManager.loadSettings(filename);
    config = settings.getFitEngineConfiguration();
    fitConfig = config.getFitConfiguration();
    NonBlockingGenericDialog gd = new NonBlockingGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Preview candidate maxima");
    String[] templates = ConfigurationTemplate.getTemplateNames(true);
    gd.addChoice("Template", templates, templates[0]);
    gd.addStringField("Config_file", filename, 40);
    gd.addNumericField("Initial_StdDev0", fitConfig.getInitialPeakStdDev0(), 3);
    String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values());
    gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]);
    String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values());
    gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]);
    gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0));
    gd.addSlider("Search_width", 0.5, 2.5, config.getSearch());
    gd.addSlider("Border", 0.5, 2.5, config.getBorder());
    // Find if this image was created with ground truth data
    if (imp.getID() == CreateData.getImageId()) {
        MemoryPeakResults results = CreateData.getResults();
        if (results != null) {
            gd.addSlider("Match_distance", 0, 2.5, distance);
            gd.addCheckbox("Show TP", showTP);
            gd.addCheckbox("Show FP", showFP);
            gd.addMessage("");
            label = (Label) gd.getMessage();
            // Integer coords
            actualCoordinates = ResultsMatchCalculator.getCoordinates(results.getResults(), true);
        }
    }
    if (!(IJ.isMacro() || java.awt.GraphicsEnvironment.isHeadless())) {
        // Listen for changes to an image
        ImagePlus.addImageListener(this);
    }
    gd.addPreviewCheckbox(pfr);
    gd.addDialogListener(this);
    gd.hideCancelButton();
    gd.setOKLabel("Close");
    gd.showDialog();
    if (!(IJ.isMacro() || java.awt.GraphicsEnvironment.isHeadless()))
        ImagePlus.removeImageListener(this);
    if (!gd.wasCanceled()) {
        filename = gd.getNextString();
        if (SettingsManager.saveSettings(settings, filename, true))
            SettingsManager.saveSettingsFilename(filename);
        else
            IJ.error(TITLE, "Failed to save settings to file " + filename);
    }
    // Reset
    imp.setOverlay(o);
    return DONE;
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog)

Example 2 with NonBlockingGenericDialog

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

the class ConfigurationTemplate method showTemplateImages.

private void showTemplateImages() {
    TITLE = "Template Example Images";
    String[] names = getTemplateNamesWithImage();
    if (names.length == 0) {
        IJ.error(TITLE, "No templates with example images");
        return;
    }
    // Follow when the image slice is changed
    ImagePlus.addImageListener(this);
    NonBlockingGenericDialog gd = new NonBlockingGenericDialog(TITLE);
    gd.addMessage("View the example source image");
    gd.addChoice("Template", names, template);
    gd.addCheckbox("Close_on_exit", close);
    gd.hideCancelButton();
    gd.addDialogListener(this);
    // Show the first template
    template = ((Choice) (gd.getChoices().get(0))).getSelectedItem();
    showTemplateImage(template);
    gd.showDialog();
    template = gd.getNextChoice();
    close = gd.getNextBoolean();
    ImagePlus.removeImageListener(this);
    if (close) {
        if (imp != null)
            imp.close();
        closeResults();
        closeInfo();
    }
}
Also used : NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog)

Example 3 with NonBlockingGenericDialog

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

the class OverlayResults method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    names = new String[MemoryPeakResults.getResultNames().size() + 1];
    ids = new int[names.length];
    int count = 0;
    names[count++] = "(None)";
    for (final MemoryPeakResults results : MemoryPeakResults.getAllResults()) {
        if (results.getSource() != null && results.getSource().getOriginal() instanceof IJImageSource) {
            final IJImageSource source = (IJImageSource) (results.getSource().getOriginal());
            final ImagePlus imp = WindowManager.getImage(source.getName());
            if (imp != null) {
                ids[count] = imp.getID();
                names[count++] = results.getName();
            }
        }
    }
    if (count == 1) {
        IJ.error(TITLE, "There are no result images available");
        return;
    }
    names = Arrays.copyOf(names, count);
    Thread thread = null;
    Worker worker = null;
    final NonBlockingGenericDialog gd = new NonBlockingGenericDialog(TITLE);
    settings = Settings.load();
    settings.save();
    gd.addMessage("Overlay results on current image frame");
    gd.addChoice("Results", names, (settings.name == null) ? "" : settings.name);
    gd.addCheckbox("Show_table", settings.showTable);
    gd.addMessage("");
    gd.addHelp(HelpUrls.getUrl("overlay-results"));
    gd.hideCancelButton();
    gd.setOKLabel("Close");
    if (!(IJ.isMacro() || java.awt.GraphicsEnvironment.isHeadless())) {
        worker = new Worker();
        choice = (Choice) gd.getChoices().get(0);
        choice.addItemListener(worker);
        checkbox = (Checkbox) gd.getCheckboxes().get(0);
        checkbox.addItemListener(worker);
        label = (Label) gd.getMessage();
        // Initialise
        worker.refresh();
        // Listen for changes to an image
        ImagePlus.addImageListener(worker);
        thread = new Thread(worker);
        thread.setDaemon(true);
        thread.start();
    }
    gd.showDialog();
    if (worker != null) {
        ImagePlus.removeImageListener(worker);
    }
    if (!gd.wasCanceled()) {
        settings.name = gd.getNextChoice();
        settings.showTable = gd.getNextBoolean();
    }
    if (thread != null && worker != null) {
        worker.running = false;
        inbox.close(true);
        try {
            thread.join(0);
        } catch (final InterruptedException ex) {
            Logger.getLogger(getClass().getName()).log(Level.WARNING, "Unexpected interruption", ex);
            Thread.currentThread().interrupt();
        }
    }
}
Also used : IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) ImagePlus(ij.ImagePlus) Point(java.awt.Point)

Example 4 with NonBlockingGenericDialog

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

the class ConfigurationTemplate method showTemplateImages.

/**
 * Show template images.
 *
 * @param settings the settings
 */
private void showTemplateImages(ConfigurationTemplateSettings.Builder settings) {
    title = "Template Example Images";
    final String[] names = getTemplateNamesWithImage();
    if (names.length == 0) {
        IJ.error(title, "No templates with example images");
        return;
    }
    // Follow when the image slice is changed
    ImageListener listener;
    if (imp != null) {
        listener = new ImageAdapter() {

            @Override
            public void imageUpdated(ImagePlus imp) {
                if (imp == ConfigurationTemplate.this.imp) {
                    updateResults(imp.getCurrentSlice());
                }
            }
        };
        ImagePlus.addImageListener(listener);
    } else {
        listener = null;
    }
    final NonBlockingGenericDialog gd = new NonBlockingGenericDialog(title);
    gd.addMessage("View the example source image");
    gd.addChoice("Template", names, settings.getTemplate());
    gd.addCheckbox("Close_on_exit", settings.getClose());
    gd.hideCancelButton();
    templateImage = true;
    gd.addDialogListener(this::dialogItemChanged);
    // Show the first template
    final String template = ((Choice) (gd.getChoices().get(0))).getSelectedItem();
    showTemplateImage(template);
    gd.addHelp(HelpUrls.getUrl("template-manager-show-images"));
    gd.showDialog();
    // There is no cancel so read the settings.
    settings.setTemplate(gd.getNextChoice());
    settings.setClose(gd.getNextBoolean());
    // This is null safe so always do this
    ImagePlus.removeImageListener(listener);
    if (settings.getClose()) {
        if (imp != null) {
            imp.close();
        }
        closeResults();
        closeInfo();
    }
}
Also used : Choice(java.awt.Choice) ImageListener(ij.ImageListener) ImageAdapter(uk.ac.sussex.gdsc.core.ij.ImageAdapter) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) ImagePlus(ij.ImagePlus)

Example 5 with NonBlockingGenericDialog

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

the class ConfigurationTemplate method showTemplate.

/**
 * Show template.
 *
 * @param settings the settings
 */
private void showTemplate(ConfigurationTemplateSettings.Builder settings) {
    if (templates.isEmpty()) {
        IJ.error(title, "No templates are currently loaded");
        return;
    }
    final String[] names = getTemplateNames();
    final NonBlockingGenericDialog gd = new NonBlockingGenericDialog(title);
    gd.addMessage("View the template");
    gd.addChoice("Template", names, settings.getTemplate());
    gd.addCheckbox("Close_on_exit", settings.getClose());
    gd.hideCancelButton();
    gd.addDialogListener(this::dialogItemChanged);
    // Show the first template
    final String template = ((Choice) (gd.getChoices().get(0))).getSelectedItem();
    showTemplate(template);
    gd.addHelp(HelpUrls.getUrl("template-manager-show-template"));
    gd.showDialog();
    // There is no cancel so read the settings.
    settings.setTemplate(gd.getNextChoice());
    settings.setClose(gd.getNextBoolean());
    if (settings.getClose()) {
        closeInfo();
    }
}
Also used : Choice(java.awt.Choice) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog)

Aggregations

NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)10 ImagePlus (ij.ImagePlus)5 ImageListener (ij.ImageListener)3 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)2 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)2 ImageWindow (ij.gui.ImageWindow)2 Choice (java.awt.Choice)2 Point (java.awt.Point)2 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)1 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)1 IJImageSource (gdsc.smlm.ij.IJImageSource)1 ResultsImageSampler (gdsc.smlm.ij.results.ResultsImageSampler)1 ImageStack (ij.ImageStack)1 DialogListener (ij.gui.DialogListener)1 GenericDialog (ij.gui.GenericDialog)1 AWTEvent (java.awt.AWTEvent)1 ImageAdapter (uk.ac.sussex.gdsc.core.ij.ImageAdapter)1 WindowOrganiser (uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser)1 TemplateSettings (uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings)1 FitEngineConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration)1