Search in sources :

Example 1 with IDirectFilter

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;
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) ArrayList(java.util.ArrayList) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) UnicodeReader(gdsc.core.utils.UnicodeReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) IOException(java.io.IOException) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) Filter(gdsc.smlm.results.filter.Filter) MultiPathFilter(gdsc.smlm.results.filter.MultiPathFilter) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) GenericDialog(ij.gui.GenericDialog) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) FilterSettings(gdsc.smlm.ij.settings.FilterSettings)

Aggregations

UnicodeReader (gdsc.core.utils.UnicodeReader)1 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)1 FilterSettings (gdsc.smlm.ij.settings.FilterSettings)1 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)1 DirectFilter (gdsc.smlm.results.filter.DirectFilter)1 Filter (gdsc.smlm.results.filter.Filter)1 FilterSet (gdsc.smlm.results.filter.FilterSet)1 IDirectFilter (gdsc.smlm.results.filter.IDirectFilter)1 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)1 GenericDialog (ij.gui.GenericDialog)1 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1