use of uk.ac.sussex.gdsc.smlm.results.filter.IDirectFilter in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method readFilterSets.
@Nullable
@SuppressWarnings("unchecked")
private List<FilterSet> readFilterSets() {
if (extraOptions) {
final MultiPathFilter multiFilter = BenchmarkSpotFit.getMultiFilter();
if (multiFilter != null) {
final IDirectFilter f = multiFilter.getFilter();
if (f instanceof DirectFilter) {
final GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Use an identical filter to " + BenchmarkSpotFit.TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.showDialog();
if (gd.wasOKed()) {
final List<FilterSet> filterSets = new ArrayList<>(1);
final List<Filter> filters = new ArrayList<>(1);
filters.add((DirectFilter) f);
final FilterSet filterSet = new FilterSet(filters);
filterSets.add(filterSet);
resetParametersFromFitting();
createResultsPrefix2();
return filterSets;
}
}
}
}
GUIFilterSettings filterSettings = SettingsManager.readGuiFilterSettings(0);
final String filename = ImageJUtils.getFilename("Filter_File", filterSettings.getFilterSetFilename());
if (filename != null) {
IJ.showStatus("Reading filters ...");
filterSettings = filterSettings.toBuilder().setFilterSetFilename(filename).build();
// Allow the filters to be cached
final Triple<String, Long, List<FilterSet>> filterCache = lastFilterList.get();
if (isSameFile(filename, filterCache)) {
final GenericDialog gd = new GenericDialog(TITLE);
gd.hideCancelButton();
gd.addMessage("The same filter file was selected.");
gd.addCheckbox("Re-use_filters", settings.reUseFilters);
gd.showDialog();
if (!gd.wasCanceled()) {
settings.reUseFilters = gd.getNextBoolean();
if (settings.reUseFilters) {
SettingsManager.writeSettings(filterSettings);
return filterCache.getRight();
}
}
}
final File file = new File(filename);
try (BufferedReader input = new BufferedReader(new UnicodeReader(new FileInputStream(file), null))) {
// Use the instance so we can catch the exception
final Object o = FilterXStreamUtils.getXStreamInstance().fromXML(input);
if (!(o instanceof List<?>)) {
IJ.log("No filter sets defined in the specified file: " + filename);
return null;
}
SettingsManager.writeSettings(filterSettings);
List<FilterSet> filterSets = (List<FilterSet>) o;
if (containsStandardFilters(filterSets)) {
IJ.log("Filter sets must contain 'Direct' filters");
return null;
}
// Check they are not empty lists
final List<FilterSet> filterSets2 = new LinkedList<>();
for (final FilterSet filterSet : filterSets) {
if (filterSet.size() != 0) {
filterSets2.add(filterSet);
} else {
IJ.log("Filter set empty: " + filterSet.getName());
}
}
if (filterSets2.isEmpty()) {
IJ.log("All Filter sets are empty");
return null;
}
// Maintain the same list type
filterSets.clear();
filterSets.addAll(filterSets2);
// Option to enumerate filters
filterSets = expandFilters(filterSets);
// Save for re-use
lastFilterList.set(Triple.of(filename, getLastModified(file), filterSets));
return filterSets;
} catch (final Exception ex) {
IJ.log("Unable to load the filter sets from file: " + ex.getMessage());
} finally {
IJ.showStatus("");
}
}
return null;
}
Aggregations