use of uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.OpticsSettings 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;
}
Aggregations