use of gdsc.smlm.results.filter.IDirectFilter in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method readFilterSets.
@SuppressWarnings("unchecked")
private List<FilterSet> readFilterSets() {
if (extraOptions && BenchmarkSpotFit.multiFilter != null) {
IDirectFilter f = BenchmarkSpotFit.multiFilter.getFilter();
if (f instanceof DirectFilter) {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Use an identical filter to " + BenchmarkSpotFit.TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.showDialog();
if (gd.wasOKed()) {
setLastFile(null);
List<FilterSet> filterSets = new ArrayList<FilterSet>(1);
List<Filter> filters = new ArrayList<Filter>(1);
filters.add((DirectFilter) f);
FilterSet filterSet = new FilterSet(filters);
filterSets.add(filterSet);
resetParametersFromFitting();
createResultsPrefix2();
return filterSets;
}
}
}
GlobalSettings gs = SettingsManager.loadSettings();
FilterSettings filterSettings = gs.getFilterSettings();
String filename = Utils.getFilename("Filter_File", filterSettings.filterSetFilename);
if (filename != null) {
IJ.showStatus("Reading filters ...");
filterSettings.filterSetFilename = filename;
// Allow the filters to be cached
if (isSameFile(filename)) {
GenericDialog gd = new GenericDialog(TITLE);
gd.hideCancelButton();
gd.addMessage("The same filter file was selected.");
gd.addCheckbox("Re-use_filters", reUseFilters);
gd.showDialog();
if (!gd.wasCanceled()) {
if ((reUseFilters = gd.getNextBoolean())) {
SettingsManager.saveSettings(gs);
return filterList;
}
}
}
BufferedReader input = null;
setLastFile(null);
try {
FileInputStream fis = new FileInputStream(filename);
input = new BufferedReader(new UnicodeReader(fis, null));
Object o = XStreamWrapper.getInstance().fromXML(input);
if (o != null && o instanceof List<?>) {
SettingsManager.saveSettings(gs);
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
List<FilterSet> filterSets2 = new LinkedList<FilterSet>();
for (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);
filterList = filterSets;
// Option to enumerate filters
expandFilters();
setLastFile(filename);
return filterList;
}
IJ.log("No filter sets defined in the specified file: " + filename);
} catch (Exception e) {
IJ.log("Unable to load the filter sets from file: " + e.getMessage());
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
// Ignore
}
}
IJ.showStatus("");
}
}
return null;
}
Aggregations