Search in sources :

Example 46 with TextWindow

use of ij.text.TextWindow in project TrakEM2 by trakem2.

the class Utils method createResultsTable.

/**
 * Creates a new ResultsTable with the given window title and column titles, and 2 decimals of precision, or if one exists for the given window title, returns it.
 */
public static final ResultsTable createResultsTable(final String title, final String[] columns) {
    try {
        return new TaskOnEDT<ResultsTable>(new Callable<ResultsTable>() {

            @Override
            public ResultsTable call() {
                final TextWindow tw = (TextWindow) WindowManager.getFrame(title);
                if (null != tw) {
                    // hacking again ... missing a getResultsTable() method in TextWindow
                    final ResultsTable rt = (ResultsTable) Utils.getField(tw.getTextPanel(), "rt");
                    // assumes columns will be identical
                    if (null != rt)
                        return rt;
                }
                // else create a new one
                final ResultsTable rt = new ResultsTable();
                rt.setPrecision(2);
                for (int i = 0; i < columns.length; i++) rt.setHeading(i, columns[i]);
                // 
                return rt;
            }
        }).get();
    } catch (final Throwable t) {
        IJError.print(t);
        return null;
    }
}
Also used : TextWindow(ij.text.TextWindow) ResultsTable(ij.measure.ResultsTable) Callable(java.util.concurrent.Callable)

Example 47 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class TraceMolecules method createSummaryTable.

private Consumer<String> createSummaryTable() {
    if (java.awt.GraphicsEnvironment.isHeadless()) {
        if (logHeader.compareAndSet(true, false)) {
            IJ.log(createHeader());
        }
        return IJ::log;
    }
    TextWindow window = summaryTable.get();
    if (window == null || !window.isVisible()) {
        window = new TextWindow(pluginTitle + " Data Summary", createHeader(), "", 800, 300);
        window.setVisible(true);
        summaryTable.set(window);
    }
    return window::append;
}
Also used : TextWindow(ij.text.TextWindow)

Example 48 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class SummariseResults method createSummaryTable.

private static TextWindow createSummaryTable() {
    final TextWindow summary = ImageJUtils.refresh(summaryRef, () -> {
        final TextWindow window = new TextWindow("Peak Results Summary", createHeader(), "", 800, 300);
        window.getTextPanel().addMouseListener(ShowStatisticsListener.INSTANCE);
        return window;
    });
    // This could be optional but at current there is no dialog and it seems unnecessary
    clearSummaryTable(summary);
    return summary;
}
Also used : TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow)

Example 49 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class SummariseResults method showSummary.

private static void showSummary(Collection<MemoryPeakResults> results, int[] removeNullResults) {
    final TextWindow summary = createSummaryTable();
    final StringBuilder sb = new StringBuilder();
    try (BufferedTextWindow tw = new BufferedTextWindow(summary)) {
        for (final MemoryPeakResults result : results) {
            tw.append(createSummary(sb, result, removeNullResults));
        }
        tw.append("");
    }
    summary.toFront();
}
Also used : TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 50 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class ResultsMatchCalculator method runCompareCoordinates.

@SuppressWarnings("null")
private void runCompareCoordinates(MemoryPeakResults results1, MemoryPeakResults results2) {
    final boolean requirePairs = settings.showPairs || settings.isSaveClassifications();
    final boolean saveMatched = settings.isSaveMatched();
    final boolean saveUnmatched = settings.isSaveUnmatched();
    final TextFilePeakResults fileResults = createFilePeakResults(results2);
    final List<PointPair> allMatches = new LinkedList<>();
    final List<PointPair> pairs = (requirePairs) ? new LinkedList<>() : null;
    final double maxDistance = settings.distanceThreshold + settings.increments * settings.delta;
    // Divide the results into time points
    final TIntObjectHashMap<List<Coordinate>> actualCoordinates = getCoordinates(results1, settings.coordinateMethod1);
    final TIntObjectHashMap<List<Coordinate>> predictedCoordinates = getCoordinates(results2, settings.coordinateMethod2);
    int n1 = 0;
    int n2 = 0;
    // Process each time point
    for (final int t : getTimepoints(actualCoordinates, predictedCoordinates)) {
        final Coordinate[] actual = getCoordinates(actualCoordinates, t);
        final Coordinate[] predicted = getCoordinates(predictedCoordinates, t);
        final List<Coordinate> tp = null;
        List<Coordinate> fp = null;
        List<Coordinate> fn = null;
        final List<PointPair> matches = new LinkedList<>();
        if (requirePairs) {
            fp = new LinkedList<>();
            fn = new LinkedList<>();
        }
        MatchCalculator.analyseResults2D(actual, predicted, maxDistance, tp, fp, fn, matches);
        // Aggregate
        n1 += actual.length;
        n2 += predicted.length;
        allMatches.addAll(matches);
        if (settings.showPairs) {
            pairs.addAll(matches);
            for (final Coordinate c : fn) {
                pairs.add(new PointPair(c, null));
            }
            for (final Coordinate c : fp) {
                pairs.add(new PointPair(null, c));
            }
        }
        if (fileResults != null) {
            // Matches are marked in the original value with 1 for true, 0 for false
            if (saveMatched) {
                for (final PointPair pair : matches) {
                    PeakResult result = ((PeakResultPoint) pair.getPoint2()).getPeakResult();
                    result = result.copy();
                    result.setOrigValue(1);
                    fileResults.add(result);
                }
            }
            if (saveUnmatched) {
                for (final Coordinate c : fp) {
                    PeakResult result = ((PeakResultPoint) c).getPeakResult();
                    result = result.copy();
                    result.setOrigValue(0);
                    fileResults.add(result);
                }
            }
        }
    }
    if (fileResults != null) {
        fileResults.end();
    }
    final boolean doIdAnalysis1 = settings.idAnalysis && haveIds(results1);
    final boolean doIdAnalysis2 = settings.idAnalysis && haveIds(results2);
    // Create output.
    // This supports headless mode with just the results table
    // or graphical mode with a results table and pairs window.
    final boolean headless = java.awt.GraphicsEnvironment.isHeadless();
    TextWindow resultsWindow = null;
    if (!headless) {
        resultsWindow = (settings.showTable) ? createResultsWindow(doIdAnalysis1 || doIdAnalysis2) : null;
        showPairs(results1, pairs, resultsWindow);
    }
    showResults(results1, results2, allMatches, n1, n2, doIdAnalysis1, doIdAnalysis2, resultsWindow);
    savePairs(results1, results2, allMatches);
}
Also used : TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) LinkedList(java.util.LinkedList) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) Point(java.awt.Point) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)

Aggregations

TextWindow (ij.text.TextWindow)61 Point (java.awt.Point)11 BufferedTextWindow (uk.ac.sussex.gdsc.core.ij.BufferedTextWindow)11 BufferedTextWindow (gdsc.core.ij.BufferedTextWindow)7 ArrayList (java.util.ArrayList)6 PointPair (uk.ac.sussex.gdsc.core.match.PointPair)5 IJ (ij.IJ)4 ImagePlus (ij.ImagePlus)4 LinkedList (java.util.LinkedList)4 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)4 ImageROIPainter (gdsc.smlm.ij.utils.ImageROIPainter)3 List (java.util.List)3 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)3 Coordinate (gdsc.core.match.Coordinate)2 MatchResult (gdsc.core.match.MatchResult)2 PointPair (gdsc.core.match.PointPair)2 TIntHashSet (gnu.trove.set.hash.TIntHashSet)2 GenericDialog (ij.gui.GenericDialog)2 ImageWindow (ij.gui.ImageWindow)2 PlotWindow (ij.gui.PlotWindow)2