use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method showDialog.
private boolean showDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
settings = Settings.load();
gd.addMessage("Compare the points in two results sets\nand compute the match statistics");
ResultsManager.addInput(gd, "Results1", settings.inputOption1, InputSource.MEMORY);
ResultsManager.addInput(gd, "Results2", settings.inputOption2, InputSource.MEMORY);
gd.addChoice("Coordinate_method1", CoordinateMethodDescriptions.descriptions, settings.coordinateMethod1.getDescription());
gd.addChoice("Coordinate_method2", CoordinateMethodDescriptions.descriptions, settings.coordinateMethod2.getDescription());
gd.addNumericField("Distance", settings.distanceThreshold, 2);
gd.addSlider("Increments", 0, 10, settings.increments);
gd.addNumericField("Delta", settings.delta, 2);
gd.addNumericField("Beta", settings.beta, 2);
gd.addCheckbox("Show_table", settings.showTable);
gd.addCheckbox("Show_pairs", settings.showPairs);
gd.addChoice("Save_classifications", Settings.saveClassificationsOptions, settings.saveClassificationsOption);
gd.addCheckbox("Id_analysis", settings.idAnalysis);
gd.addCheckbox("Save_pairs", settings.savePairs);
gd.addCheckbox("Output_end_frame", settings.outputEndFrame);
gd.addHelp(HelpUrls.getUrl("results-match-calculator"));
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.inputOption1 = gd.getNextChoice();
settings.inputOption2 = gd.getNextChoice();
settings.coordinateMethod1 = CoordinateMethod.fromDescription(gd.getNextChoice(), CoordinateMethod.ALL);
settings.coordinateMethod2 = CoordinateMethod.fromDescription(gd.getNextChoice(), CoordinateMethod.ALL);
settings.distanceThreshold = gd.getNextNumber();
settings.increments = (int) gd.getNextNumber();
settings.delta = gd.getNextNumber();
settings.beta = gd.getNextNumber();
settings.showTable = gd.getNextBoolean();
settings.showPairs = gd.getNextBoolean();
settings.saveClassificationsOption = gd.getNextChoiceIndex();
settings.idAnalysis = gd.getNextBoolean();
settings.savePairs = gd.getNextBoolean();
settings.outputEndFrame = gd.getNextBoolean();
settings.save();
if (!(settings.showTable || settings.showPairs || !settings.isSaveClassifications())) {
IJ.error(TITLE, "No outputs specified");
return false;
}
// Check arguments
try {
ParameterUtils.isPositive("Distance threshold", settings.distanceThreshold);
ParameterUtils.isPositive("Increments", settings.increments);
ParameterUtils.isAboveZero("Delta", settings.delta);
ParameterUtils.isPositive("Beta", settings.beta);
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class UpdateResultsBounds method showInputDialog.
private boolean showInputDialog() {
final int size = MemoryPeakResults.countMemorySize();
if (size == 0) {
IJ.error(TITLE, "There are no fitting results in memory");
return false;
}
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("update-results-bounds"));
gd.addMessage("Select results to update");
settings = Settings.load();
ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.inputOption = ResultsManager.getInputSource(gd);
settings.save();
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class UpdateResultsBounds method showDialog.
private static boolean showDialog(MemoryPeakResults results) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("update-results-bounds"));
// Force computation of bounds
Rectangle currentBounds = results.getBounds();
results.setBounds(null);
Rectangle autoBounds;
try {
autoBounds = results.getBounds(true);
} catch (final DataException ex) {
IJ.error(TITLE, "No calibration found to convert to pixel units");
return false;
} finally {
// Reset after forcing computation
if (currentBounds != null) {
results.setBounds(currentBounds);
}
}
// Re-acquire the bounds (either the existing bounds or the auto-bounds)
currentBounds = results.getBounds();
gd.addMessage(TextUtils.wrap("Set the bounds of the original source image.\n \nAuto-bounds = " + format(autoBounds) + "\n \nThe new bounds will be the union of the auto-bounds and specified bounds " + "to ensure all data is within the bounds.", 80));
gd.addNumericField("Min_x", currentBounds.x, 0, 6, "px");
gd.addNumericField("Min_y", currentBounds.y, 0, 6, "px");
gd.addNumericField("Width", currentBounds.width, 0, 6, "px");
gd.addNumericField("Height", currentBounds.height, 0, 6, "px");
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
final int x = (int) gd.getNextNumber();
final int y = (int) gd.getNextNumber();
final int width = (int) gd.getNextNumber();
final int height = (int) gd.getNextNumber();
// Check the bounds are not smaller than the auto-bounds
final Rectangle newBounds = new Rectangle(x, y, width, height).union(autoBounds);
if (newBounds.isEmpty()) {
IJ.error(TITLE, "New bounds are not valid: " + format(newBounds));
return false;
}
results.setBounds(newBounds);
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class CameraModelFisherInformationAnalysis method createExponents.
@Nullable
private double[] createExponents() {
final int n = 1 + Math.max(0, settings.getSubDivisions());
final double h = 1.0 / n;
final double minExp = settings.getMinExponent();
final double maxExp = settings.getMaxExponent();
final double size = (maxExp - minExp) * n + 1;
if (size > 100) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Number of exponents is " + Math.ceil(size) + ". OK to continue?");
gd.showDialog();
if (gd.wasCanceled()) {
return null;
}
}
final TDoubleArrayList list = new TDoubleArrayList();
for (int i = 0; ; i++) {
final double e = minExp + i * h;
list.add(e);
if (e >= settings.getMaxExponent()) {
break;
}
}
return list.toArray();
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class Configuration method showDialog.
/**
* Show the current properties.
*
* @param fitEngineConfiguration the fit engine configuration
* @param save the save
* @return true, if successful
*/
public boolean showDialog(FitEngineConfiguration fitEngineConfiguration, boolean save) {
this.config = fitEngineConfiguration;
fitConfig = config.getFitConfiguration();
pluginSettings = Settings.load();
pluginSettings.save();
final CalibrationReader calibrationReader = fitConfig.getCalibrationReader();
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("fit-configuration"));
gd.addMessage("Configuration settings for the single-molecule localisation microscopy plugins");
final String[] templates = ConfigurationTemplate.getTemplateNames(true);
gd.addChoice("Template", templates, templates[0]);
PeakFit.addCameraOptions(gd, fitConfig);
gd.addNumericField("Calibration (nm/px)", calibrationReader.getNmPerPixel(), 2);
gd.addNumericField("Exposure_time (ms)", calibrationReader.getExposureTime(), 2);
gd.addMessage("--- Gaussian parameters ---");
PeakFit.addPsfOptions(gd, fitConfig);
gd.addMessage("--- Maxima identification ---");
final FitEngineConfigurationProvider provider = this::getFitEngineConfiguration;
PeakFit.addDataFilterOptions(gd, provider);
PeakFit.addSearchOptions(gd, provider);
PeakFit.addBorderOptions(gd, provider);
PeakFit.addFittingOptions(gd, provider);
gd.addMessage("--- Gaussian fitting ---");
gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), FitProtosHelper.getName(fitConfig.getFitSolver()));
// Parameters specific to each Fit solver are collected in a second dialog
gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
gd.addNumericField("Pass_rate", config.getPassRate(), 2);
gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours());
gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold());
gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold());
PeakFit.addDuplicateDistanceOptions(gd, provider);
gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract");
gd.addCheckbox("Smart_filter", fitConfig.isSmartFilter());
gd.addCheckbox("Disable_simple_filter", fitConfig.isDisableSimpleFilter());
gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor());
gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2);
gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0);
gd.addSlider("Min_width_factor", 0, 0.99, fitConfig.getMinWidthFactor());
gd.addSlider("Width_factor", 1, 4.5, fitConfig.getMaxWidthFactor());
PeakFit.addPrecisionOptions(gd, this::getFitConfiguration);
// Add a mouse listener to the config file field
if (ImageJUtils.isShowGenericDialog()) {
final Vector<TextField> numerics = gd.getNumericFields();
final Vector<Checkbox> checkboxes = gd.getCheckboxes();
final Vector<Choice> choices = gd.getChoices();
final Iterator<TextField> nu = numerics.iterator();
final Iterator<Checkbox> cb = checkboxes.iterator();
final Iterator<Choice> ch = choices.iterator();
final Choice textTemplate = ch.next();
textTemplate.addItemListener(this::itemStateChanged);
textCameraType = ch.next();
textNmPerPixel = nu.next();
textExposure = nu.next();
textPsf = ch.next();
textDataFilterType = ch.next();
textDataFilterMethod = ch.next();
textSmooth = nu.next();
textSearch = nu.next();
textBorder = nu.next();
textFitting = nu.next();
textFitSolver = ch.next();
textFailuresLimit = nu.next();
textPassRate = nu.next();
textIncludeNeighbours = cb.next();
textNeighbourHeightThreshold = nu.next();
textResidualsThreshold = nu.next();
textDuplicateDistance = nu.next();
textSmartFilter = cb.next();
textDisableSimpleFilter = cb.next();
textCoordinateShiftFactor = nu.next();
textSignalStrength = nu.next();
textMinPhotons = nu.next();
textMinWidthFactor = nu.next();
textWidthFactor = nu.next();
textPrecisionThreshold = nu.next();
updateFilterInput();
textSmartFilter.addItemListener(this::itemStateChanged);
textDisableSimpleFilter.addItemListener(this::itemStateChanged);
}
if (save) {
gd.enableYesNoCancel("Save", "Save template");
}
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
// In case a template updated the calibration
final CalibrationWriter calibrationWriter = fitConfig.getCalibrationWriter();
// Ignore the template
gd.getNextChoice();
calibrationWriter.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
calibrationWriter.setNmPerPixel(gd.getNextNumber());
calibrationWriter.setExposureTime(gd.getNextNumber());
fitConfig.setCalibration(calibrationWriter.getCalibration());
fitConfig.setPsfType(PeakFit.getPsfTypeValues()[gd.getNextChoiceIndex()]);
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), false, 0);
config.setSearch(gd.getNextNumber());
config.setBorder(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
// Some enum values are not supported
fitConfig.setFitSolver(SettingsManager.getFitSolverValues()[gd.getNextChoiceIndex()]);
config.setFailuresLimit((int) gd.getNextNumber());
config.setPassRate(gd.getNextNumber());
config.setIncludeNeighbours(gd.getNextBoolean());
config.setNeighbourHeightThreshold(gd.getNextNumber());
config.setResidualsThreshold(gd.getNextNumber());
config.setDuplicateDistance(gd.getNextNumber());
fitConfig.setSmartFilter(gd.getNextBoolean());
fitConfig.setDisableSimpleFilter(gd.getNextBoolean());
fitConfig.setCoordinateShiftFactor(gd.getNextNumber());
fitConfig.setSignalStrength(gd.getNextNumber());
fitConfig.setMinPhotons(gd.getNextNumber());
fitConfig.setMinWidthFactor(gd.getNextNumber());
fitConfig.setMaxWidthFactor(gd.getNextNumber());
fitConfig.setPrecisionThreshold(gd.getNextNumber());
gd.collectOptions();
// Check arguments
try {
ParameterUtils.isAboveZero("nm per pixel", calibrationWriter.getNmPerPixel());
ParameterUtils.isAboveZero("Exposure time", calibrationWriter.getExposureTime());
if (fitConfig.getPsfTypeValue() != PSFType.ASTIGMATIC_GAUSSIAN_2D_VALUE) {
ParameterUtils.isAboveZero("Initial SD0", fitConfig.getInitialXSd());
if (fitConfig.getPsf().getParametersCount() > 1) {
ParameterUtils.isAboveZero("Initial SD1", fitConfig.getInitialYSd());
}
}
ParameterUtils.isAboveZero("Search_width", config.getSearch());
ParameterUtils.isAboveZero("Fitting_width", config.getFitting());
ParameterUtils.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
ParameterUtils.isPositive("Residuals threshold", config.getResidualsThreshold());
ParameterUtils.isPositive("Duplicate distance", config.getDuplicateDistance());
if (!fitConfig.isSmartFilter()) {
ParameterUtils.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
ParameterUtils.isPositive("Signal strength", fitConfig.getSignalStrength());
ParameterUtils.isPositive("Min photons", fitConfig.getMinPhotons());
ParameterUtils.isPositive("Min width factor", fitConfig.getMinWidthFactor());
ParameterUtils.isPositive("Width factor", fitConfig.getMaxWidthFactor());
ParameterUtils.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
}
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
if (gd.invalidNumber()) {
return false;
}
final int flags = PeakFit.FLAG_NO_SAVE;
if (!PeakFit.configurePsfModel(config, flags)) {
return false;
}
if (!PeakFit.configureResultsFilter(config, flags)) {
return false;
}
if (!PeakFit.configureDataFilter(config, flags)) {
return false;
}
PeakFit.configureFitSolver(config, null, null, flags);
if (save) {
final boolean saveToFile = !gd.wasOKed();
if (saveToFile) {
gd = new ExtendedGenericDialog(TITLE);
gd.addFilenameField("Template_filename", pluginSettings.templateFilename);
gd.addMessage("Add notes to the template ...");
gd.addTextAreas(pluginSettings.notes, null, 10, 60);
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
pluginSettings.save();
final String filename = gd.getNextString();
pluginSettings.notes = gd.getNextText();
if (filename != null) {
pluginSettings.templateFilename = FileUtils.replaceExtension(filename, ".txt");
final File file = new File(pluginSettings.templateFilename);
final String name = FileUtils.removeExtension(file.getName());
final TemplateSettings.Builder settings = TemplateSettings.newBuilder();
settings.addNotes(pluginSettings.notes);
settings.setCalibration(fitConfig.getCalibration());
settings.setFitEngineSettings(config.getFitEngineSettings());
// Note: No results settings are currently supported
settings.setPsf(fitConfig.getPsf());
if (!ConfigurationTemplate.saveTemplate(name, settings.build(), file)) {
IJ.error(TITLE, "Failed to save to file: " + pluginSettings.templateFilename);
}
}
} else {
SettingsManager.writeSettings(config, 0);
}
}
return true;
}
Aggregations