use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener in project GDSC-SMLM by aherbert.
the class TraceDiffusion method showTraceDialog.
private boolean showTraceDialog(ArrayList<MemoryPeakResults> allResults) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("trace-diffusion"));
if (!multiMode) {
ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
}
clusteringSettings = SettingsManager.readClusteringSettings(0).toBuilder();
gd.addChoice("Mode", TRACE_MODE, clusteringSettings.getTraceDiffusionMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
clusteringSettings.setTraceDiffusionMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Trace diffusion options", null);
// Only 2 modes
if (clusteringSettings.getTraceDiffusionMode() == 1) {
// Dynamic Multiple Target Tracing
final TextField tfD = egd.addAndGetNumericField("Diffusion_coefficient", clusteringSettings.getDiffusionCoefficentMaximum(), 3, 6, "um^2/s");
final TextField tfW = egd.addAndGetNumericField("Temporal_window", clusteringSettings.getTemporalWindow(), 0, 6, "frames");
final TextField tfLdw = egd.addAndGetNumericField("Local_diffusion_weight", clusteringSettings.getLocalDiffusionWeight(), 2);
final TextField tfOiw = egd.addAndGetNumericField("On_intensity_weight", clusteringSettings.getOnIntensityWeight(), 2);
final TextField tfDdf = egd.addAndGetNumericField("Disappearance_decay_factor", clusteringSettings.getDisappearanceDecayFactor(), 0, 6, "frames");
final TextField tfDt = egd.addAndGetNumericField("Disappearance_threshold", clusteringSettings.getDisappearanceThreshold(), 0, 6, "frames");
final Checkbox cbDld = egd.addAndGetCheckbox("Disable_local_diffusion_model", clusteringSettings.getDisableLocalDiffusionModel());
final Checkbox cbDim = egd.addAndGetCheckbox("Disable_intensity_model", clusteringSettings.getDisableIntensityModel());
// Allow reset to defaults
egd.addAndGetButton("Defaults", e -> {
final DmttConfiguration config = DmttConfiguration.newBuilder(1).build();
tfD.setText(String.valueOf(clusteringSettings.getDiffusionCoefficentMaximum()));
tfW.setText(String.valueOf(config.getTemporalWindow()));
tfLdw.setText(String.valueOf(config.getLocalDiffusionWeight()));
tfOiw.setText(String.valueOf(config.getOnIntensityWeight()));
tfDdf.setText(String.valueOf(config.getDisappearanceDecayFactor()));
tfDt.setText(String.valueOf(config.getDisappearanceThreshold()));
cbDld.setState(config.isDisableLocalDiffusionModel());
cbDim.setState(config.isDisableIntensityModel());
});
} else {
// Nearest Neighbour
egd.addNumericField("Distance_Threshold (nm)", clusteringSettings.getDistanceThreshold(), 0);
egd.addNumericField("Distance_Exclusion (nm)", clusteringSettings.getDistanceExclusion(), 0);
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
if (clusteringSettings.getTraceDiffusionMode() == 1) {
// Dynamic Multiple Target Tracing
clusteringSettings.setDiffusionCoefficentMaximum(egd.getNextNumber());
clusteringSettings.setTemporalWindow((int) egd.getNextNumber());
clusteringSettings.setLocalDiffusionWeight(egd.getNextNumber());
clusteringSettings.setOnIntensityWeight(egd.getNextNumber());
clusteringSettings.setDisappearanceDecayFactor(egd.getNextNumber());
clusteringSettings.setDisappearanceThreshold((int) egd.getNextNumber());
clusteringSettings.setDisableLocalDiffusionModel(egd.getNextBoolean());
clusteringSettings.setDisableIntensityModel(egd.getNextBoolean());
} else {
// Nearest Neighbour
clusteringSettings.setDistanceThreshold(egd.getNextNumber());
clusteringSettings.setDistanceExclusion(Math.abs(egd.getNextNumber()));
}
return true;
}
});
gd.addSlider("Min_trace_length", 2, 20, clusteringSettings.getMinimumTraceLength());
gd.addCheckbox("Ignore_ends", clusteringSettings.getIgnoreEnds());
gd.addCheckbox("Save_traces", clusteringSettings.getSaveTraces());
gd.showDialog();
if (gd.wasCanceled() || !readTraceDialog(gd)) {
return false;
}
// Update the settings
SettingsManager.writeSettings(clusteringSettings.build());
// Load the results
if (!multiMode) {
final MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, true, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return false;
}
if (!checkCalibration(results)) {
return false;
}
allResults.add(results);
}
return true;
}
Aggregations