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);
}
Aggregations