Search in sources :

Example 1 with MultiDialog

use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.

the class PsfCombiner method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    // Build a list of suitable images
    final List<String> titles = createImageList();
    if (titles.size() < 2) {
        IJ.error(TITLE, "No suitable PSF images to combine");
        return;
    }
    final MultiDialog md = new MultiDialog("Select PSFs", titles);
    md.setSelected(lastSelected.get());
    md.setHelpUrl(HelpUrls.getUrl("psf-combiner"));
    md.showDialog();
    if (md.wasCancelled()) {
        return;
    }
    final List<String> selected = md.getSelectedResults();
    if (selected.size() < 2) {
        IJ.error(TITLE, "Require at least 2 PSF images to combine");
        return;
    }
    lastSelected.set(selected);
    for (final String title : selected) {
        input.add(new Psf(title));
    }
    if (input.isEmpty()) {
        return;
    }
    if (input.size() < 2) {
        return;
    }
    // GenericDialog gd = new GenericDialog(TITLE);
    // gd.addMessage("Set the maximum z-depth +/- from the PSF centre");
    // gd.addSlider("Z-depth", 20, 200, zDepth);
    // gd.showDialog();
    // if (gd.wasCanceled())
    // return;
    // zDepth = Math.abs((int) gd.getNextNumber());
    // 
    // for (PSF psf : input)
    // psf.crop(zDepth);
    combineImages();
}
Also used : MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 2 with MultiDialog

use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.

the class ResultsManager method createMultiDialog.

/**
 * Creates a MultiDialog listing all the results held in memory.
 *
 * @param title the dialog title
 * @param filter the filter to select results
 * @return the dialog
 */
public static MultiDialog createMultiDialog(String title, Predicate<MemoryPeakResults> filter) {
    final MemoryResultsList items = new MemoryResultsList(filter);
    final MultiDialog md = new MultiDialog(title, items);
    md.setDisplayConverter(items.getDisplayConverter());
    return md;
}
Also used : MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 3 with MultiDialog

use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.

the class ResultsManager method runClearMemory.

private static void runClearMemory(String arg) {
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        IJ.showStatus("");
        return;
    }
    Collection<MemoryPeakResults> allResults;
    boolean removeAll = false;
    String helpKey = "clear-memory-results";
    if (arg.contains("multi")) {
        helpKey += "-multi";
        final MultiDialog md = createMultiDialog(TITLE);
        md.setSelected(lastSelected.get());
        md.setHelpUrl(HelpUrls.getUrl(helpKey));
        md.showDialog();
        if (md.wasCancelled()) {
            return;
        }
        final List<String> selected = md.getSelectedResults();
        if (selected.isEmpty()) {
            return;
        }
        lastSelected.set(selected);
        allResults = new ArrayList<>(selected.size());
        for (final String name : selected) {
            final MemoryPeakResults r = MemoryPeakResults.getResults(name);
            if (r != null) {
                allResults.add(r);
            }
        }
    } else {
        removeAll = true;
        allResults = MemoryPeakResults.getAllResults();
    }
    if (allResults.isEmpty()) {
        return;
    }
    long memorySize = 0;
    int size = 0;
    for (final MemoryPeakResults results : allResults) {
        memorySize += MemoryPeakResults.estimateMemorySize(results);
        size += results.size();
    }
    final String memory = TextUtils.bytesToString(memorySize);
    final String count = TextUtils.pleural(size, "result");
    final String sets = TextUtils.pleural(allResults.size(), "set");
    final GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage(String.format("Do you want to remove %s from memory (%s, %s)?", count, sets, memory));
    gd.addHelp(HelpUrls.getUrl(helpKey));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    if (removeAll) {
        MemoryPeakResults.clearMemory();
    } else {
        for (final MemoryPeakResults results : allResults) {
            MemoryPeakResults.removeResults(results.getName());
        }
    }
    SummariseResults.clearSummaryTable();
    ImageJUtils.log("Cleared %s (%s, %s)", count, sets, memory);
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) GenericDialog(ij.gui.GenericDialog) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 4 with MultiDialog

use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.

the class TrackPopulationAnalysis method showInputDialog.

private boolean showInputDialog(List<MemoryPeakResults> combinedResults) {
    // Show a list box containing all the clustered results.
    // This should remember the last set of chosen items.
    final MultiDialog md = ResultsManager.createMultiDialog(TITLE, MemoryPeakResults::hasId);
    md.setSelected(settings.input);
    md.setHelpUrl(HelpUrls.getUrl("track-population-analysis"));
    md.showDialog();
    if (md.wasCancelled()) {
        return false;
    }
    final List<String> selected = md.getSelectedResults();
    if (selected.isEmpty()) {
        IJ.error(TITLE, "No results were selected");
        return false;
    }
    settings.input = selected;
    for (final String name : selected) {
        final MemoryPeakResults r = MemoryPeakResults.getResults(name);
        if (r != null) {
            combinedResults.add(r);
        }
    }
    // Check calibration exists for the first set of results
    if (combinedResults.isEmpty() || !checkCalibration(combinedResults.get(0))) {
        return false;
    }
    // Check the calibration is the same for the rest
    final CalibrationReader cal = combinedResults.get(0).getCalibrationReader();
    final double nmPerPixel = cal.getNmPerPixel();
    final double exposureTime = cal.getExposureTime();
    final DistanceUnit distanceUnit = cal.getDistanceUnit();
    for (int i = 1; i < combinedResults.size(); i++) {
        final MemoryPeakResults results = combinedResults.get(i);
        if (!results.hasCalibration() || results.getCalibrationReader().getExposureTime() != exposureTime || results.getNmPerPixel() != nmPerPixel || results.getDistanceUnit() != distanceUnit) {
            IJ.error(TITLE, "The exposure time, pixel pitch and distance unit must match across all the results");
            return false;
        }
    }
    return true;
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 5 with MultiDialog

use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.

the class ConfigurationTemplate method loadSelectedCustomTemplatesFromDirectory.

/**
 * Load templates from directory.
 *
 * @param settings the settings
 */
private static void loadSelectedCustomTemplatesFromDirectory(ConfigurationTemplateSettings.Builder settings) {
    // Allow the user to specify a configuration directory
    final String newDirectory = ImageJUtils.getDirectory("Template_directory", settings.getConfigurationDirectory());
    if (newDirectory == null) {
        // Cancelled dialog
        return;
    }
    settings.setConfigurationDirectory(newDirectory);
    // Search the configuration directory and add everything that is not a tif image
    // (which may be the template source image example).
    final File[] fileList = (new File(newDirectory)).listFiles(file -> file.isFile() && !file.getName().toLowerCase(Locale.US).endsWith("tif"));
    if (fileList == null) {
        IJ.error(TITLE, "No files in template directory: " + newDirectory);
        return;
    }
    // Sort partially numerically
    final List<String> list = Arrays.stream(fileList).map(File::getPath).sorted(AlphaNumericComparator.NULL_IS_MORE_INSTANCE).collect(Collectors.toList());
    // Select
    final MultiDialog md = new MultiDialog("Select templates", list);
    md.setDisplayConverter(path -> ImageJUtils.decodePath(path)[1]);
    md.setSelected(settings.getSelectedCustomTemplatesList());
    md.setHelpUrl(HelpUrls.getUrl("template-manager-load-custom"));
    md.showDialog();
    if (md.wasCancelled()) {
        return;
    }
    final List<String> selected = md.getSelectedResults();
    if (selected.isEmpty()) {
        return;
    }
    // Save
    settings.clearSelectedCustomTemplates();
    settings.addAllSelectedCustomTemplates(selected);
    int count = templates.size();
    final TemplateSettings.Builder builder = TemplateSettings.newBuilder();
    for (final String path : selected) {
        builder.clear();
        final File file = new File(path);
        if (SettingsManager.fromJson(file, builder, 0)) {
            final String name = FileUtils.removeExtension(file.getName());
            // Assume the tif image will be detected automatically
            addTemplate(templates, name, builder.build(), TemplateType.CUSTOM, file, null);
        } else {
            ImageJPluginLoggerHelper.getDefaultLogger().info(() -> "Failed to load template file: " + file);
        }
    }
    count = templates.size() - count;
    if (count > 0) {
        saveLoadedTemplates(templates);
        IJ.showMessage(TITLE, "Loaded " + TextUtils.pleural(count, "new custom template"));
    }
}
Also used : DefaultTemplateSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplateSettings) TemplateSettings(uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings) ConfigurationTemplateSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ConfigurationTemplateSettings) File(java.io.File) Point(java.awt.Point) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Aggregations

MultiDialog (uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)10 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)5 Point (java.awt.Point)2 File (java.io.File)2 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)2 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)2 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)2 GenericDialog (ij.gui.GenericDialog)1 HashSet (java.util.HashSet)1 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)1 ResultsFileSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings)1 TemplateSettings (uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings)1 ConfigurationTemplateSettings (uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ConfigurationTemplateSettings)1 DefaultTemplate (uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplate)1 DefaultTemplateSettings (uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplateSettings)1