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;
}
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());
}
}
}
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);
}
}
}
Aggregations