Search in sources :

Example 11 with Overlay

use of ij.gui.Overlay in project GDSC-SMLM by aherbert.

the class ImageROIPainter method mousePressed.

public void mousePressed(MouseEvent e) {
    // If a multiple-line selection is made then show all the points
    int index = textPanel.getSelectionStart();
    if (index == -1)
        return;
    int index2 = textPanel.getSelectionEnd();
    if (index == index2)
        return;
    ImagePlus imp = WindowManager.getImage(title);
    if (imp == null)
        return;
    // Show all
    int points = 0;
    float[] x = new float[index2 - index + 1];
    float[] y = new float[x.length];
    int[] slice = new int[x.length];
    while (index <= index2) {
        double[] position = coordProvider.getCoordinates(textPanel.getLine(index));
        if (position == null || position.length < 3)
            continue;
        slice[points] = (int) position[0];
        x[points] = (float) position[1];
        y[points] = (float) position[2];
        points++;
        index++;
    }
    if (points == 0)
        return;
    // Simple code to add the ROI onto a single slice: addRoi(imp, slice[0], new PointRoi(x, y, points));
    // Add the ROI to each relevant slice
    // Sort the slices
    int[] indices = new int[points];
    for (int i = 0; i < points; i++) indices[i] = i;
    Sort.sort(indices, slice);
    Overlay o = new Overlay();
    // Create an ROI for each slice
    int start = 0;
    for (int i = 0; i < points; i++) {
        if (slice[indices[i]] != slice[indices[start]]) {
            appendRoi(x, y, slice, indices, o, start, i);
            start = i;
        }
    }
    appendRoi(x, y, slice, indices, o, start, points);
    // Choose the first slice and add the final overlay
    imp.setSlice(slice[indices[start]]);
    if (imp.getWindow() != null)
        imp.getWindow().toFront();
    o.setStrokeColor(Color.green);
    imp.setOverlay(o);
}
Also used : Overlay(ij.gui.Overlay) ImagePlus(ij.ImagePlus)

Aggregations

Overlay (ij.gui.Overlay)11 ImagePlus (ij.ImagePlus)6 Rectangle (java.awt.Rectangle)5 PointRoi (ij.gui.PointRoi)4 ArrayList (java.util.ArrayList)4 PeakResult (gdsc.smlm.results.PeakResult)3 ImageStack (ij.ImageStack)3 Color (java.awt.Color)3 BasePoint (gdsc.core.match.BasePoint)2 Coordinate (gdsc.core.match.Coordinate)2 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)2 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)2 ImageRoi (ij.gui.ImageRoi)2 Roi (ij.gui.Roi)2 LUT (ij.process.LUT)2 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)1 FractionalAssignment (gdsc.core.match.FractionalAssignment)1 MatchResult (gdsc.core.match.MatchResult)1 PointPair (gdsc.core.match.PointPair)1 Statistics (gdsc.core.utils.Statistics)1