Search in sources :

Example 1 with Pulse

use of uk.ac.sussex.gdsc.core.match.Pulse in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method extractPulses.

@Nullable
private static Pulse[] extractPulses(MemoryPeakResults results) {
    if (results == null) {
        return null;
    }
    final Pulse[] pulses = new Pulse[results.size()];
    final Counter i = new Counter();
    results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> pulses[i.getAndIncrement()] = new Pulse(x, y, result.getFrame(), result.getEndFrame()));
    return pulses;
}
Also used : CoordinateProvider(uk.ac.sussex.gdsc.smlm.utils.CoordinateProvider) TextWindow(ij.text.TextWindow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WindowManager(ij.WindowManager) Point(java.awt.Point) HashMap(java.util.HashMap) ImageRoiPainter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageRoiPainter) AtomicReference(java.util.concurrent.atomic.AtomicReference) MatchResult(uk.ac.sussex.gdsc.core.match.MatchResult) ArrayList(java.util.ArrayList) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) LinkedList(java.util.LinkedList) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) Pulse(uk.ac.sussex.gdsc.core.match.Pulse) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) WindowAdapter(java.awt.event.WindowAdapter) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) WindowEvent(java.awt.event.WindowEvent) Consumer(java.util.function.Consumer) List(java.util.List) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) MatchCalculator(uk.ac.sussex.gdsc.core.match.MatchCalculator) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) PlugIn(ij.plugin.PlugIn) Collections(java.util.Collections) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) Pulse(uk.ac.sussex.gdsc.core.match.Pulse) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable)

Example 2 with Pulse

use of uk.ac.sussex.gdsc.core.match.Pulse in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method compareCoordinates.

@SuppressWarnings("null")
private void compareCoordinates(MemoryPeakResults results1, MemoryPeakResults results2, MemoryPeakResults results3, double distanceThreshold) {
    final Pulse[] p1 = extractPulses(results1);
    final Pulse[] p2 = extractPulses(results2);
    final Pulse[] p3 = extractPulses(results3);
    final List<Pulse> tp = null;
    List<Pulse> fp = null;
    List<Pulse> fn = null;
    List<PointPair> pairs = null;
    final List<Pulse> tp2 = null;
    List<Pulse> fp2 = null;
    List<Pulse> fn2 = null;
    List<PointPair> pairs2 = null;
    if (settings.showPairs) {
        pairs = new LinkedList<>();
        fp = new LinkedList<>();
        fn = new LinkedList<>();
        pairs2 = new LinkedList<>();
        fp2 = new LinkedList<>();
        fn2 = new LinkedList<>();
    }
    final MatchResult result = MatchCalculator.analyseResults2D(p1, p2, distanceThreshold, tp, fp, fn, pairs);
    final MatchResult result2 = MatchCalculator.analyseResults2D(p1, p3, distanceThreshold, tp2, fp2, fn2, pairs2);
    // Create output
    Consumer<String> resultsOutput;
    if (!java.awt.GraphicsEnvironment.isHeadless()) {
        final TextWindow resultsWindow = ImageJUtils.refresh(resultsWindowRef, () -> new TextWindow(TITLE + " Results", createResultsHeader(), "", 900, 300));
        resultsOutput = resultsWindow::append;
        if (settings.showPairs) {
            if (p3 == null) {
                // Produce a pairs output
                final WindowAndPainter wap = refresh(pairsWindowRef, true, resultsWindow, results1);
                // Add the unmatched points
                WindowManager.getIDList();
                for (final Coordinate c : fn) {
                    pairs.add(new PointPair(c, null));
                }
                for (final Coordinate c : fp) {
                    pairs.add(new PointPair(null, c));
                }
                final List<? extends PointPair> sortedPairs = sort(pairs);
                for (final PointPair pair : sortedPairs) {
                    addPairResult(wap.textWindow, pair);
                }
            } else {
                // Produce a triple output
                final WindowAndPainter wap = refresh(triplesWindowRef, false, resultsWindow, results1);
                final HashMap<Pulse, Triple> map = new HashMap<>();
                final ArrayList<Triple> triples = new ArrayList<>(pairs.size());
                for (final PointPair pair : pairs) {
                    final Pulse p = (Pulse) pair.getPoint1();
                    final Triple t = new Triple(p, (Pulse) pair.getPoint2(), null);
                    triples.add(t);
                    map.put(p, t);
                }
                // Complete the reference set of points
                for (final Coordinate c : fn) {
                    final Pulse p = (Pulse) c;
                    final Triple t = new Triple(p, null, null);
                    triples.add(t);
                    map.put(p, t);
                }
                // Add the unmatched points
                for (final Coordinate c : fp) {
                    triples.add(new Triple(null, (Pulse) c, null));
                }
                for (final Coordinate c : fp2) {
                    triples.add(new Triple(null, null, (Pulse) c));
                }
                // Add the results from the second match
                for (final PointPair pair : pairs2) {
                    final Pulse p = (Pulse) pair.getPoint1();
                    final Pulse pp = (Pulse) pair.getPoint2();
                    final Triple triple = map.get(p);
                    if (triple != null) {
                        triple.p3 = pp;
                    } else {
                        triples.add(new Triple(null, null, pp));
                    }
                }
                final List<? extends Triple> sortedTriples = sort(triples);
                for (final Triple t : sortedTriples) {
                    addTripleResult(wap.textWindow, t);
                }
            }
        }
    } else {
        if (writeHeader.compareAndSet(true, false)) {
            IJ.log(createResultsHeader());
        }
        resultsOutput = IJ::log;
    }
    final StringBuilder sb = new StringBuilder();
    addResult(resultsOutput, sb, settings.inputOption1, settings.inputOption2, distanceThreshold, result);
    if (p3 != null) {
        addResult(resultsOutput, sb, settings.inputOption1, settings.inputOption3, distanceThreshold, result2);
    }
}
Also used : IJ(ij.IJ) HashMap(java.util.HashMap) Pulse(uk.ac.sussex.gdsc.core.match.Pulse) ArrayList(java.util.ArrayList) MatchResult(uk.ac.sussex.gdsc.core.match.MatchResult) TextWindow(ij.text.TextWindow) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) PointPair(uk.ac.sussex.gdsc.core.match.PointPair)

Example 3 with Pulse

use of uk.ac.sussex.gdsc.core.match.Pulse in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method refresh.

private static WindowAndPainter refresh(AtomicReference<WindowAndPainter> ref, boolean pairs, TextWindow resultsWindow, MemoryPeakResults results1) {
    // Produce a pairs output
    final WindowAndPainter wap = ConcurrencyUtils.refresh(ref, // Test the window is showing
    w -> ImageJUtils.isShowing(w.textWindow), // Create
    () -> {
        final String title = TITLE + ((pairs) ? " Pairs" : " Triples");
        final String header = pairs ? createPairsHeader() : createTriplesHeader();
        final TextWindow window = new TextWindow(title, header, "", 900, 300);
        // Position relative to results window
        final Point p = resultsWindow.getLocation();
        p.y += resultsWindow.getHeight();
        window.setLocation(p);
        final CoordinateProvider coordinateProvider = line -> {
            // Extract the startT and x,y coordinates from the first pulse in the line
            final int[] index = { 0, 5, 12 };
            final String[] fields = line.split("\t");
            for (final int i : index) {
                if (i < fields.length) {
                    if (fields[i].equals("-")) {
                        continue;
                    }
                    final int startT = Integer.parseInt(fields[i]);
                    final double x = Double.parseDouble(fields[i + 2]);
                    final double y = Double.parseDouble(fields[i + 3]);
                    return new double[] { startT, x, y };
                }
            }
            return null;
        };
        final ImageRoiPainter painter = new ImageRoiPainter(window.getTextPanel(), results1.getSource().getOriginal().getName(), coordinateProvider);
        final WindowAndPainter result = new WindowAndPainter(window, painter);
        // Free memory on close
        window.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosed(WindowEvent event) {
                ref.compareAndSet(result, null);
                super.windowClosed(event);
            }
        });
        return result;
    });
    wap.textWindow.getTextPanel().clear();
    wap.painter.setTitle(results1.getSource().getOriginal().getName());
    return wap;
}
Also used : CoordinateProvider(uk.ac.sussex.gdsc.smlm.utils.CoordinateProvider) TextWindow(ij.text.TextWindow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WindowManager(ij.WindowManager) Point(java.awt.Point) HashMap(java.util.HashMap) ImageRoiPainter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageRoiPainter) AtomicReference(java.util.concurrent.atomic.AtomicReference) MatchResult(uk.ac.sussex.gdsc.core.match.MatchResult) ArrayList(java.util.ArrayList) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) LinkedList(java.util.LinkedList) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) Pulse(uk.ac.sussex.gdsc.core.match.Pulse) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) WindowAdapter(java.awt.event.WindowAdapter) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) WindowEvent(java.awt.event.WindowEvent) Consumer(java.util.function.Consumer) List(java.util.List) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) MatchCalculator(uk.ac.sussex.gdsc.core.match.MatchCalculator) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) PlugIn(ij.plugin.PlugIn) Collections(java.util.Collections) ImageRoiPainter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageRoiPainter) TextWindow(ij.text.TextWindow) CoordinateProvider(uk.ac.sussex.gdsc.smlm.utils.CoordinateProvider) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point)

Example 4 with Pulse

use of uk.ac.sussex.gdsc.core.match.Pulse in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method addTripleResult.

private void addTripleResult(TextWindow triplesWindow, Triple triple) {
    final StringBuilder sb = new StringBuilder();
    final Pulse p1 = triple.p1;
    final Pulse p2 = triple.p2;
    final Pulse p3 = triple.p3;
    addPoint(sb, p1);
    addPointPairResult(sb, p1, p2);
    addPointPairResult(sb, p1, p3);
    triplesWindow.append(sb.toString());
}
Also used : Pulse(uk.ac.sussex.gdsc.core.match.Pulse)

Example 5 with Pulse

use of uk.ac.sussex.gdsc.core.match.Pulse in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method addPairResult.

private void addPairResult(TextWindow pairsWindow, PointPair pair) {
    final StringBuilder sb = new StringBuilder();
    final Pulse p1 = (Pulse) pair.getPoint1();
    final Pulse p2 = (Pulse) pair.getPoint2();
    addPoint(sb, p1);
    addPointPairResult(sb, p1, p2);
    pairsWindow.append(sb.toString());
}
Also used : Pulse(uk.ac.sussex.gdsc.core.match.Pulse)

Aggregations

Pulse (uk.ac.sussex.gdsc.core.match.Pulse)5 IJ (ij.IJ)3 TextWindow (ij.text.TextWindow)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)3 MatchResult (uk.ac.sussex.gdsc.core.match.MatchResult)3 PointPair (uk.ac.sussex.gdsc.core.match.PointPair)3 WindowManager (ij.WindowManager)2 PlugIn (ij.plugin.PlugIn)2 Point (java.awt.Point)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Consumer (java.util.function.Consumer)2 Nullable (uk.ac.sussex.gdsc.core.annotation.Nullable)2