use of uk.ac.sussex.gdsc.smlm.results.procedures.XyResultProcedure in project GDSC-SMLM by aherbert.
the class PeakFit method addSingleFrameOverlay.
private void addSingleFrameOverlay() {
// If a single frame was processed add the peaks as an overlay if they are in memory
ImagePlus localImp = this.imp;
if (fitMaxima && singleFrame > 0 && source instanceof IJImageSource) {
final String title = source.getName();
localImp = WindowManager.getImage(title);
}
if (singleFrame > 0 && localImp != null) {
MemoryPeakResults memoryResults = null;
for (final PeakResults r : this.results.toArray()) {
if (r instanceof MemoryPeakResults) {
memoryResults = (MemoryPeakResults) r;
break;
}
}
if (memoryResults == null || memoryResults.size() == 0) {
return;
}
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("Add the fitted localisations as an overlay?");
gd.showDialog();
if (!gd.wasOKed()) {
return;
}
final LUT lut = LutHelper.createLut(LutColour.ICE);
final Overlay o = new Overlay();
final int size = memoryResults.size();
final Counter j = new Counter(size);
final ImagePlus finalImp = localImp;
memoryResults.forEach(DistanceUnit.PIXEL, (XyResultProcedure) (x, y) -> {
final PointRoi roi = new OffsetPointRoi(x, y);
final Color c = LutHelper.getColour(lut, j.decrementAndGet(), size);
roi.setStrokeColor(c);
roi.setFillColor(c);
if (finalImp.getStackSize() > 1) {
roi.setPosition(singleFrame);
}
o.add(roi);
});
localImp.setOverlay(o);
localImp.getWindow().toFront();
}
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyResultProcedure in project GDSC-SMLM by aherbert.
the class SpotInspector method mouseClicked.
private void mouseClicked(MouseEvent event) {
if (id != currentId.get()) {
return;
}
// Show the result that was double clicked in the result table
if (event.getClickCount() > 1) {
final int rank = textPanel.getSelectionStart() + 1;
// Show the spot that was double clicked
final ImagePlus imp = WindowManager.getImage(TITLE);
if (imp != null && rank > 0 && rank <= imp.getStackSize()) {
imp.setSlice(rank);
if (imp.getWindow() != null) {
imp.getWindow().toFront();
}
final PeakResult r = rankedResults.get(rank - 1).peakResult;
final TypeConverter<DistanceUnit> dc = results.getDistanceConverter(DistanceUnit.PIXEL);
final float rx = dc.convert(r.getXPosition());
final float ry = dc.convert(r.getYPosition());
final int x = (int) rx;
final int y = (int) ry;
// Find bounds
final int minX = x - settings.radius;
final int minY = y - settings.radius;
// Require the Shift key to add all spots
if (!event.isShiftDown()) {
// Add the single clicked spot
imp.setRoi(new OffsetPointRoi(rx - minX, ry - minY));
return;
}
// Add all the spots
final int maxX = x + settings.radius + 1;
final int maxY = y + settings.radius + 1;
// Create ROIs
final HashSet<Point2D.Float> spots = new HashSet<>();
results.forEach(DistanceUnit.PIXEL, (XyResultProcedure) (xp, yp) -> {
if (xp > minX && xp < maxX && yp > minY && yp < maxY) {
// Use only unique points
spots.add(new Point2D.Float(xp - minX, yp - minY));
}
});
final int points = spots.size();
final float[] ox = new float[points];
final float[] oy = new float[points];
final Counter c = new Counter();
spots.forEach(p -> {
ox[c.getCount()] = p.x;
oy[c.getAndIncrement()] = p.y;
});
imp.setRoi(new OffsetPointRoi(ox, oy, points));
}
}
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyResultProcedure in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method getPoints.
/**
* Gets the points.
*
* @param results the results
* @param settings the settings
* @return the points
*/
static LocalList<Point3f> getPoints(MemoryPeakResults results, ImageJ3DResultsViewerSettingsOrBuilder settings) {
final LocalList<Point3f> points = new LocalList<>(results.size());
if (results.is3D()) {
results.forEach(DistanceUnit.NM, (XyzResultProcedure) (x, y, z) -> {
points.push(new Point3f(x, y, z));
});
} else {
results.forEach(DistanceUnit.NM, (XyResultProcedure) (x, y) -> {
points.push(new Point3f(x, y, 0));
});
final double range = settings.getDepthRange();
if (range > 0 && results.size() > 1) {
final DepthMode mode = DepthMode.forNumber(settings.getDepthMode());
final double min = -settings.getDepthRange() / 2;
switch(mode) {
case DITHER:
final SplitMix r = SplitMix.new64(settings.getDitherSeed());
for (int i = points.size(); i-- > 0; ) {
points.unsafeGet(i).z += (min + r.nextDouble() * range);
}
break;
case INTENSITY:
// Rank by intensity, highest first
final StandardResultProcedure p = new StandardResultProcedure(results);
p.getI();
final int[] indices = SimpleArrayUtils.natural(results.size());
SortUtils.sortIndices(indices, p.intensity, true);
final double inc = range / indices.length;
for (int i = 0; i < indices.length; i++) {
// The standard rendering has +z going away so put the highest rank at min
points.unsafeGet(indices[i]).z += (min + i * inc);
}
break;
case NONE:
break;
default:
throw new IllegalStateException("Unknown depth mode: " + mode);
}
}
}
return points;
}
Aggregations