Search in sources :

Example 36 with ExtendedGenericDialog

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

the class LoadLocalisations method getFields.

private static boolean getFields(LoadLocalisationsSettings.Builder settings) {
    settings.getLocalisationsFilename();
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Load delimited localisations");
    // Show a preview of the file in a text area
    final List<String> preview = loadLines(settings, 100);
    if (!preview.isEmpty()) {
        // Add a TextArea. This cannot add scroll bars after the constructor so we put up
        // with this. But we can use a monospaced font and size the text area nicely.
        gd.addTextAreas(preview.stream().collect(Collectors.joining("\n")), null, Math.min(10, preview.size()), Math.min(80, preview.stream().mapToInt(String::length).max().getAsInt()));
        final TextArea ta = gd.getTextArea1();
        final Font font = new Font(Font.MONOSPACED, Font.PLAIN, (int) (10 * Prefs.getGuiScale()));
        ta.setFont(font);
        ta.setEditable(false);
    }
    if (!settings.getHideFieldDatasetName()) {
        gd.addStringField("Dataset_name", settings.getName(), 30);
    }
    gd.addMessage("Calibration:");
    // Allow the full camera type top be captured
    final Calibration.Builder calibrationBuilder = settings.getCalibrationBuilder();
    final CalibrationWriter cw = new CalibrationWriter(calibrationBuilder);
    PeakFit.addCameraOptions(gd, 0, cw);
    // Only primitive support for other calibration
    gd.addNumericField("Pixel_size", cw.getNmPerPixel(), 3, 8, "nm");
    gd.addNumericField("Exposure_time", cw.getExposureTime(), 3, 8, "");
    // This is the unit for the exposure time (used to convert the exposure time to milliseconds).
    // Use the name as the list is a truncated list of the full enum.
    final TimeUnit t = calibrationBuilder.getTimeCalibration().getTimeUnit();
    gd.addChoice("Time_unit", TimeUnitLoader.getTimeUnits(), SettingsManager.getName(UnitHelper.getName(t), UnitHelper.getShortName(t)));
    gd.addMessage("Records:");
    gd.addNumericField("Header_lines", settings.getHeaderLines(), 0);
    gd.addStringField("Comment", settings.getComment());
    gd.addStringField("Delimiter", settings.getDelimiter());
    gd.addChoice("Distance_unit", SettingsManager.getDistanceUnitNames(), cw.getDistanceUnitValue());
    gd.addChoice("Intensity_unit", SettingsManager.getIntensityUnitNames(), cw.getIntensityUnitValue());
    gd.addMessage("Define the fields:");
    gd.addNumericField("Frame", settings.getFieldT(), 0);
    gd.addNumericField("ID", settings.getFieldId(), 0);
    gd.addNumericField("Category", settings.getFieldCategory(), 0);
    gd.addNumericField("X", settings.getFieldX(), 0);
    gd.addNumericField("Y", settings.getFieldY(), 0);
    gd.addNumericField("Z", settings.getFieldZ(), 0);
    gd.addNumericField("Intensity", settings.getFieldI(), 0);
    gd.addNumericField("Sx", settings.getFieldSx(), 0);
    gd.addNumericField("Sy", settings.getFieldSy(), 0);
    gd.addNumericField("Precision", settings.getFieldPrecision(), 0);
    gd.addChoice("Precision_method", SettingsManager.getPrecisionMethodNames(), cw.getPrecisionMethodValue());
    gd.addHelp(HelpUrls.getUrl("load-localisations"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    if (!settings.getHideFieldDatasetName()) {
        settings.setName(getNextString(gd, settings.getName()));
    }
    cw.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    cw.setNmPerPixel(gd.getNextNumber());
    cw.setExposureTime(gd.getNextNumber());
    // The time units used a truncated list so look-up the value from the index
    calibrationBuilder.getTimeCalibrationBuilder().setTimeUnit(TimeUnitLoader.getTimeUnitValues()[gd.getNextChoiceIndex()]);
    settings.setHeaderLines((int) gd.getNextNumber());
    settings.setComment(gd.getNextString());
    settings.setDelimiter(getNextString(gd, settings.getDelimiter()));
    cw.setDistanceUnit(DistanceUnit.forNumber(gd.getNextChoiceIndex()));
    cw.setIntensityUnit(IntensityUnit.forNumber(gd.getNextChoiceIndex()));
    final int[] columns = new int[10];
    for (int i = 0; i < columns.length; i++) {
        columns[i] = (int) gd.getNextNumber();
    }
    int index = 0;
    settings.setFieldT(columns[index++]);
    settings.setFieldId(columns[index++]);
    settings.setFieldCategory(columns[index++]);
    settings.setFieldX(columns[index++]);
    settings.setFieldY(columns[index++]);
    settings.setFieldZ(columns[index++]);
    settings.setFieldI(columns[index++]);
    settings.setFieldSx(columns[index++]);
    settings.setFieldSy(columns[index++]);
    settings.setFieldPrecision(columns[index]);
    cw.setPrecisionMethod(PrecisionMethod.forNumber(gd.getNextChoiceIndex()));
    // Collect the camera calibration
    gd.collectOptions();
    // Validate after reading the dialog (so we store the last entered values)
    if (gd.invalidNumber()) {
        IJ.error(TITLE, "Invalid number in input fields");
        return false;
    }
    for (int i = 0; i < columns.length; i++) {
        if (columns[i] < 0) {
            continue;
        }
        for (int j = i + 1; j < columns.length; j++) {
            if (columns[j] < 0) {
                continue;
            }
            if (columns[i] == columns[j]) {
                IJ.error(TITLE, "Duplicate indicies: " + columns[i]);
                return false;
            }
        }
    }
    if (cw.getNmPerPixel() <= 0) {
        IJ.error(TITLE, "Require positive pixel pitch");
        return false;
    }
    if (cw.isCcdCamera()) {
        if (!cw.hasCountPerPhoton()) {
            IJ.error(TITLE, "Require positive count/photon for CCD camera type");
            return false;
        }
    } else {
    // Q.Validate other camera types?
    }
    if (settings.getFieldX() < 0 || settings.getFieldY() < 0) {
        IJ.error(TITLE, "Require valid X and Y indices");
        return false;
    }
    return true;
}
Also used : TextArea(java.awt.TextArea) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) TimeUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.TimeUnit) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) Font(java.awt.Font)

Example 37 with ExtendedGenericDialog

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

the class Noise method showDialog.

@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
    // Select a camera model
    calibration = CalibrationWriter.create(SettingsManager.readCalibration(0));
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Preprocess camera image and estimate global noise");
    PeakFit.addCameraOptions(gd, calibration);
    gd.showDialog();
    if (gd.wasCanceled()) {
        return DONE;
    }
    calibration.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    gd.collectOptions();
    SettingsManager.writeSettings(calibration.getCalibration());
    try {
        createCameraModel();
    } catch (final Exception ex) {
        IJ.error(TITLE, ex.getMessage());
        return DONE;
    }
    settings = Settings.load();
    // Do this now to prevent doing it in the preview.
    settings.save();
    // If using a stack, provide a preview graph of the noise for two methods
    if (imp.getStackSize() > 1) {
        this.pfr = pfr;
        drawPlot();
        gd = new ExtendedGenericDialog(TITLE);
        gd.addHelp(HelpUrls.getUrl("noise-estimator"));
        final String[] methodNames = SettingsManager.getNoiseEstimatorMethodNames();
        gd.addChoice("Method1 (blue)", methodNames, methodNames[settings.algorithm]);
        gd.addChoice("Method2 (red)", methodNames, methodNames[settings.algorithm2]);
        gd.addSlider("Lowest_radius", 1, 15, settings.lowestPixelsRange);
        gd.addDialogListener(this);
        gd.addMessage("Click OK to compute noise table using all methods");
        gd.showDialog();
        if (gd.wasCanceled() || !dialogItemChanged(gd, null)) {
            return DONE;
        }
    }
    return IJ.setupDialog(imp, FLAGS);
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 38 with ExtendedGenericDialog

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

the class NeighbourAnalysis method showDialog.

private boolean showDialog() {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("neighbour-analysis"));
    settings = Settings.load();
    ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
    gd.addNumericField("Distance_Threshold (px)", settings.distanceThreshold, 4);
    gd.addNumericField("Time_Threshold (frames)", settings.timeThreshold, 0);
    gd.showDialog();
    if (gd.wasCanceled() || !readDialog(gd)) {
        return false;
    }
    // Load the results
    results = ResultsManager.loadInputResults(settings.inputOption, false, DistanceUnit.PIXEL);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        IJ.showStatus("");
        return false;
    }
    return true;
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 39 with ExtendedGenericDialog

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

the class NucleusMask method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Create a mask stack using spheres");
    settings = SettingsManager.readNucleusMaskSettings(0).toBuilder();
    gd.addChoice("Mode", MODE, settings.getMode());
    gd.addNumericField("Field_width", settings.getFieldWidth(), 2, 6, "px");
    gd.addNumericField("Pixel_width", settings.getNmPerPixel(), 2, 6, "nm");
    gd.addNumericField("Pixel_depth", settings.getNmPerSlice(), 2, 6, "nm");
    gd.addHelp(HelpUrls.getUrl("nucleus-mask"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.setMode(gd.getNextChoiceIndex());
    settings.setFieldWidth((int) gd.getNextNumber());
    settings.setNmPerPixel(gd.getNextNumber());
    settings.setNmPerSlice(gd.getNextNumber());
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Field width", settings.getFieldWidth());
        ParameterUtils.isAboveZero("Pixel width", settings.getNmPerPixel());
        ParameterUtils.isAboveZero("Pixel depth", settings.getNmPerSlice());
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    if (settings.getMode() == 0) {
        gd = new ExtendedGenericDialog(TITLE);
        gd.addHelp(HelpUrls.getUrl("nucleus-mask"));
        gd.addMessage("Create a mask stack using uniform random spheres");
        gd.addNumericField("y_dither", settings.getYDither(), 2, 6, "um");
        gd.addNumericField("z_dither", settings.getZDither(), 2, 6, "um");
        gd.addNumericField("Diameter", settings.getDiameter(), 2, 6, "um");
        gd.addHelp(HelpUrls.getUrl("nucleus-mask"));
        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }
        settings.setYDither(gd.getNextNumber());
        settings.setZDither(gd.getNextNumber());
        settings.setDiameter(gd.getNextNumber());
        try {
            ParameterUtils.isAboveZero("Diameter", settings.getDiameter());
        } catch (final IllegalArgumentException ex) {
            IJ.error(TITLE, ex.getMessage());
            return false;
        }
    }
    SettingsManager.writeSettings(settings);
    return true;
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)

Example 40 with ExtendedGenericDialog

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

the class Optics method showDialog.

private boolean showDialog(boolean isDbscan) {
    logReferences(isDbscan);
    final NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(pluginTitle);
    gd.addHelp(HelpUrls.getUrl(isDbscan ? "dbscan" : "optics"));
    ResultsManager.addInput(gd, inputSettings.getInputOption(), InputSource.MEMORY);
    // globalSettings = SettingsManager.loadSettings();
    // settings = globalSettings.getClusteringSettings();
    gd.addCheckbox("Ignore_z (for 3D data)", inputSettings.getIgnoreZ());
    if (isDbscan) {
        gd.addMessage("--- Nearest-Neighbour Analysis ---");
    } else {
        gd.addMessage("--- " + pluginTitle + " ---");
    }
    gd.addNumericField("Min_points", inputSettings.getMinPoints(), 0);
    if (isDbscan) {
        // Add fields to auto-compute the clustering distance from the K-nearest neighbour distance
        // profile
        gd.addSlider("Noise (%)", 0, 50, inputSettings.getFractionNoise() * 100);
        gd.addNumericField("Samples", inputSettings.getSamples(), 0);
        gd.addSlider("Sample_fraction (%)", 0, 15, inputSettings.getSampleFraction() * 100);
    } else {
        final String[] opticsModes = SettingsManager.getNames((Object[]) OpticsMode.values());
        gd.addChoice("OPTICS_mode", opticsModes, inputSettings.getOpticsMode(), new OptionListener<Integer>() {

            @Override
            public boolean collectOptions(Integer value) {
                inputSettings.setOpticsMode(value);
                final boolean result = collectOptions(false);
                return result;
            }

            @Override
            public boolean collectOptions() {
                return collectOptions(true);
            }

            private boolean collectOptions(boolean silent) {
                final OpticsMode mode = OpticsMode.get(inputSettings.getOpticsMode());
                final ExtendedGenericDialog egd = new ExtendedGenericDialog(mode.toString() + " options");
                final OpticsSettings oldSettings = inputSettings.build();
                if (mode == OpticsMode.FAST_OPTICS) {
                    egd.addMessage(TextUtils.wrap("The number of splits to compute (if below 1 it will be auto-computed " + "using the size of the data)", 80));
                    egd.addNumericField("Number_of_splits", inputSettings.getNumberOfSplitSets(), 0);
                    if (extraOptions) {
                        egd.addCheckbox("Random_vectors", inputSettings.getUseRandomVectors());
                        egd.addCheckbox("Approx_sets", inputSettings.getSaveApproximateSets());
                        final String[] sampleModes = SettingsManager.getNames((Object[]) SampleMode.values());
                        egd.addChoice("Sample_mode", sampleModes, inputSettings.getSampleMode());
                    }
                    egd.setSilent(silent);
                    egd.showDialog(true, gd);
                    if (egd.wasCanceled()) {
                        return false;
                    }
                    inputSettings.setNumberOfSplitSets((int) Math.abs(egd.getNextNumber()));
                    if (extraOptions) {
                        inputSettings.setUseRandomVectors(egd.getNextBoolean());
                        inputSettings.setSaveApproximateSets(egd.getNextBoolean());
                        inputSettings.setSampleMode(egd.getNextChoiceIndex());
                    }
                } else {
                    // OPTICS
                    egd.addNumericField("Generating_distance", inputSettings.getGeneratingDistance(), 2, 6, "nm");
                    egd.showDialog(true, gd);
                    if (egd.wasCanceled()) {
                        return false;
                    }
                    inputSettings.setGeneratingDistance(Math.abs(egd.getNextNumber()));
                }
                // Return true if new settings
                return !inputSettings.build().equals(oldSettings);
            }
        });
    }
    gd.addMessage("--- Clustering ---");
    if (isDbscan) {
        gd.addNumericField("Clustering_distance", inputSettings.getClusteringDistance(), 2, 6, "nm");
        gd.addCheckbox("Core_points", inputSettings.getCore());
    } else {
        final String[] clusteringModes = SettingsManager.getNames((Object[]) ClusteringMode.values());
        gd.addChoice("Clustering_mode", clusteringModes, inputSettings.getClusteringMode(), new OptionListener<Integer>() {

            @Override
            public boolean collectOptions(Integer value) {
                inputSettings.setClusteringMode(value);
                return collectOptions(false);
            }

            @Override
            public boolean collectOptions() {
                return collectOptions(true);
            }

            private boolean collectOptions(boolean silent) {
                final ClusteringMode mode = ClusteringMode.get(inputSettings.getClusteringMode());
                final ExtendedGenericDialog egd = new ExtendedGenericDialog(mode.toString() + " options");
                final OpticsSettings oldSettings = inputSettings.build();
                if (mode == ClusteringMode.XI) {
                    egd.addMessage("Xi controls the change in reachability (profile steepness) to " + "define a cluster");
                    egd.addNumericField("Xi", inputSettings.getXi(), 4);
                    egd.addCheckbox("Top_clusters", inputSettings.getTopLevel());
                    egd.addNumericField("Upper_limit", inputSettings.getUpperLimit(), 4, 10, "nm");
                    egd.addNumericField("Lower_limit", inputSettings.getLowerLimit(), 4, 10, "nm");
                    egd.setSilent(silent);
                    egd.showDialog(true, gd);
                    if (egd.wasCanceled()) {
                        return false;
                    }
                    inputSettings.setXi(Math.abs(egd.getNextNumber()));
                    inputSettings.setTopLevel(egd.getNextBoolean());
                    inputSettings.setUpperLimit(Math.abs(egd.getNextNumber()));
                    inputSettings.setLowerLimit(Math.abs(egd.getNextNumber()));
                } else {
                    // DBSCAN
                    egd.addMessage(ClusteringMode.DBSCAN.toString() + " options:");
                    egd.addNumericField("Clustering_distance", inputSettings.getClusteringDistance(), 4, 10, "nm");
                    egd.addCheckbox("Core_points", inputSettings.getCore());
                    egd.setSilent(silent);
                    egd.showDialog(true, gd);
                    if (egd.wasCanceled()) {
                        return false;
                    }
                    inputSettings.setClusteringDistance(Math.abs(egd.getNextNumber()));
                    inputSettings.setCore(egd.getNextBoolean());
                }
                // Return true if new settings
                return !inputSettings.build().equals(oldSettings);
            }
        });
    }
    gd.addMessage("--- Table ---");
    gd.addCheckbox("Show_table", inputSettings.getShowTable(), new OptionListener<Boolean>() {

        @Override
        public boolean collectOptions(Boolean value) {
            inputSettings.setShowTable(value);
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            if (!inputSettings.getShowTable()) {
                return false;
            }
            final ExtendedGenericDialog egd = new ExtendedGenericDialog("Table options");
            final OpticsSettings oldSettings = inputSettings.build();
            final String[] modes = SettingsManager.getNames((Object[]) TableSortMode.values());
            egd.addChoice("Table_sort_mode", modes, inputSettings.getTableSortMode());
            egd.addCheckbox("Table_reverse_sort", inputSettings.getTableReverseSort());
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            inputSettings.setTableSortMode(egd.getNextChoiceIndex());
            inputSettings.setTableReverseSort(egd.getNextBoolean());
            // Return true if new settings
            return !inputSettings.build().equals(oldSettings);
        }
    });
    gd.addMessage("--- Image ---");
    gd.addSlider("Image_scale", 0, 15, inputSettings.getImageScale());
    final TreeSet<ImageMode> imageModeSet = new TreeSet<>();
    imageModeSet.addAll(Arrays.asList(ImageMode.values()));
    if (isDbscan) {
        imageModeSet.remove(ImageMode.CLUSTER_DEPTH);
        imageModeSet.remove(ImageMode.CLUSTER_ORDER);
    }
    imageModeArray = imageModeSet.toArray();
    final String[] imageModes = SettingsManager.getNames(imageModeArray);
    gd.addChoice("Image_mode", imageModes, ImageMode.get(inputSettings.getImageMode()).toString(), new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            inputSettings.setImageMode(((ImageMode) imageModeArray[value]).ordinal());
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            final ImageMode mode = ImageMode.get(inputSettings.getImageMode());
            final ExtendedGenericDialog egd = new ExtendedGenericDialog(mode.toString() + " options");
            if (mode.canBeWeighted()) {
                egd.addCheckbox("Weighted", inputSettings.getWeighted());
                egd.addCheckbox("Equalised", inputSettings.getEqualised());
            }
            if (mode == ImageMode.LOOP && extraOptions) {
                egd.addNumericField("LoOP_lambda", inputSettings.getLambda(), 4);
            }
            if (!egd.hasFields()) {
                return false;
            }
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            final OpticsSettings oldSettings = inputSettings.build();
            if (mode.canBeWeighted()) {
                inputSettings.setWeighted(egd.getNextBoolean());
                inputSettings.setEqualised(egd.getNextBoolean());
            }
            if (mode == ImageMode.LOOP && extraOptions) {
                inputSettings.setLambda(Math.abs(gd.getNextNumber()));
            }
            // Return true if new settings
            return !inputSettings.build().equals(oldSettings);
        }
    });
    final TreeSet<OutlineMode> outlineModeSet = new TreeSet<>();
    outlineModeSet.addAll(Arrays.asList(OutlineMode.values()));
    if (isDbscan) {
        outlineModeSet.remove(OutlineMode.COLOURED_BY_DEPTH);
    }
    outlineModeArray = outlineModeSet.toArray();
    final String[] outlineModes = SettingsManager.getNames(outlineModeArray);
    gd.addChoice("Outline", outlineModes, OutlineMode.get(inputSettings.getOutlineMode()).toString(), new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            inputSettings.setOutlineMode(((OutlineMode) outlineModeArray[value]).ordinal());
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            final OutlineMode mode = OutlineMode.get(inputSettings.getOutlineMode());
            final ExtendedGenericDialog egd = new ExtendedGenericDialog(mode.toString() + " options");
            final int hullMode = inputSettings.getHullMode();
            final boolean saveOutlines = inputSettings.getSaveOutlines();
            final double diggingThreshold = inputSettings.getDiggingThreshold();
            final String[] hullModes = SettingsManager.getNames((Object[]) HullMode.values());
            egd.addChoice("Hull_algorithm", hullModes, hullMode);
            egd.addCheckbox("Save_to_ROI_manager", saveOutlines);
            egd.addMessage("For the digging concave hull algorithm");
            egd.addNumericField("Digging_threshold", diggingThreshold, 2);
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            inputSettings.setHullMode(egd.getNextChoiceIndex());
            inputSettings.setSaveOutlines(egd.getNextBoolean());
            inputSettings.setDiggingThreshold(ValidationUtils.checkStrictlyPositive(egd.getNextNumber(), "Digging_threshold"));
            // Return true if new settings
            return inputSettings.getHullMode() != hullMode || inputSettings.getSaveOutlines() != saveOutlines || (hullMode == HullMode.DIGGING_CONCAVE_HULL.ordinal() && inputSettings.getDiggingThreshold() != diggingThreshold);
        }
    });
    if (!isDbscan) {
        final String[] spanningTreeModes = SettingsManager.getNames((Object[]) SpanningTreeMode.values());
        gd.addChoice("Spanning_tree", spanningTreeModes, inputSettings.getSpanningTreeMode());
        gd.addMessage("--- Reachability Plot ---");
        final String[] plotModes = SettingsManager.getNames((Object[]) PlotMode.values());
        gd.addChoice("Plot_mode", plotModes, inputSettings.getPlotMode());
    }
    // Everything is done within the dialog listener
    final BaseDialogListener listener = (isDbscan) ? new DbscanDialogListener(gd) : new OpticsDialogListener(gd);
    gd.addDialogListener(listener);
    gd.addOptionCollectedListener(listener);
    // Start disabled so the user can choose settings to update
    if (ImageJUtils.isShowGenericDialog()) {
        gd.addCheckbox("Preview", false, listener);
    } else {
        gd.addCheckbox("Preview", false);
    }
    if (extraOptions) {
        gd.addCheckbox("Debug", false);
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    // The dialog was OK'd so run if work was staged in the workflow.
    if (workflow.isStaged()) {
        workflow.runStaged();
    }
    // Record the options for macros since the NonBlocking dialog does not
    if (Recorder.record) {
        Recorder.recordOption("Min_points", Integer.toString(inputSettings.getMinPoints()));
        if (isDbscan) {
            // Add fields to auto-compute the clustering distance from the K-nearest neighbour distance
            // profile
            Recorder.recordOption("Noise", Double.toString(inputSettings.getFractionNoise() * 100));
            Recorder.recordOption("Samples", Double.toString(inputSettings.getSamples()));
            Recorder.recordOption("Sample_fraction", Double.toString(inputSettings.getSampleFraction() * 100));
            Recorder.recordOption("Clustering_distance", Double.toString(inputSettings.getClusteringDistance()));
        } else {
            Recorder.recordOption("OPTICS_mode", OpticsMode.get(inputSettings.getOpticsMode()).toString());
            Recorder.recordOption("Number_of_splits", Integer.toString(inputSettings.getNumberOfSplitSets()));
            if (extraOptions) {
                if (inputSettings.getUseRandomVectors()) {
                    Recorder.recordOption("Random_vectors");
                }
                if (inputSettings.getSaveApproximateSets()) {
                    Recorder.recordOption("Approx_sets");
                }
                Recorder.recordOption("Sample_mode", SampleMode.forOrdinal(inputSettings.getSampleMode()).toString());
            }
            Recorder.recordOption("Generating_distance", Double.toString(inputSettings.getGeneratingDistance()));
        }
        if (isDbscan) {
            if (inputSettings.getCore()) {
                Recorder.recordOption("Core_points");
            }
        } else {
            Recorder.recordOption("Clustering_mode", ClusteringMode.get(inputSettings.getClusteringMode()).toString());
            Recorder.recordOption("Xi", Double.toString(inputSettings.getXi()));
            if (inputSettings.getTopLevel()) {
                Recorder.recordOption("Top_clusters");
            }
            Recorder.recordOption("Upper_limit", Double.toString(inputSettings.getUpperLimit()));
            Recorder.recordOption("Lower_limit", Double.toString(inputSettings.getLowerLimit()));
            Recorder.recordOption("Clustering_distance", Double.toString(inputSettings.getClusteringDistance()));
            if (inputSettings.getCore()) {
                Recorder.recordOption("Core_points");
            }
        }
        if (inputSettings.getShowTable()) {
            Recorder.recordOption("Show_table");
            Recorder.recordOption("Table_sort_mode", TableSortMode.get(inputSettings.getTableSortMode()).toString());
            if (inputSettings.getTableReverseSort()) {
                Recorder.recordOption("Table_reverse_sort");
            }
        }
        Recorder.recordOption("Image_scale", Double.toString(inputSettings.getImageScale()));
        Recorder.recordOption("Image_mode", ImageMode.get(inputSettings.getImageMode()).toString());
        if (inputSettings.getWeighted()) {
            Recorder.recordOption("Weighted");
        }
        if (inputSettings.getEqualised()) {
            Recorder.recordOption("Equalised");
        }
        if (extraOptions) {
            Recorder.recordOption("LoOP_lambda", Double.toString(inputSettings.getLambda()));
        }
        Recorder.recordOption("Outline", OutlineMode.get(inputSettings.getOutlineMode()).toString());
        Recorder.recordOption("Hull_algorithm", HullMode.get(inputSettings.getHullMode()).toString());
        if (inputSettings.getSaveOutlines()) {
            Recorder.recordOption("Save_to_ROI_manager");
        }
        Recorder.recordOption("Digging_threshold", Double.toString(inputSettings.getDiggingThreshold()));
        if (!isDbscan) {
            Recorder.recordOption("Spanning_tree", SpanningTreeMode.get(inputSettings.getSpanningTreeMode()).toString());
            Recorder.recordOption("Plot_mode", PlotMode.get(inputSettings.getPlotMode()).toString());
        }
        if (debug) {
            Recorder.recordOption("Debug");
        }
    }
    return true;
}
Also used : NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TreeSet(java.util.TreeSet) OpticsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.OpticsSettings)

Aggregations

ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)151 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)38 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)21 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)14 Checkbox (java.awt.Checkbox)13 ImagePlus (ij.ImagePlus)12 File (java.io.File)11 Rectangle (java.awt.Rectangle)10 TextField (java.awt.TextField)10 ResultsImageSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings)10 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)10 Choice (java.awt.Choice)9 ArrayList (java.util.ArrayList)9 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)9 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)8 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)7 ResultsSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings)7 ResultsTableSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings)7 IJ (ij.IJ)6 GenericDialog (ij.gui.GenericDialog)5