Search in sources :

Example 31 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class Fire method createImages.

/**
 * Creates the images to use for the FIRE calculation. This must be called after
 * {@link #initialise(MemoryPeakResults, MemoryPeakResults)}.
 *
 * @param fourierImageScale the fourier image scale (set to zero to auto compute)
 * @param imageSize the image size
 * @param useSignal Use the localisation signal to weight the intensity. The default uses a value
 *        of 1 per localisation.
 * @return the fire images
 */
public FireImages createImages(double fourierImageScale, int imageSize, boolean useSignal) {
    if (results == null) {
        return null;
    }
    final SignalProvider signalProvider = (useSignal && (results.hasIntensity())) ? new PeakSignalProvider() : new FixedSignalProvider();
    // Draw images using the existing IJ routines.
    final Rectangle bounds = new Rectangle((int) Math.ceil(dataBounds.getWidth()), (int) Math.ceil(dataBounds.getHeight()));
    final ResultsImageSettings.Builder builder = ResultsImageSettings.newBuilder().setImageType(ResultsImageType.DRAW_NONE).setWeighted(true).setEqualised(false).setImageMode(ResultsImageMode.IMAGE_ADD);
    if (fourierImageScale > 0) {
        builder.setImageSizeMode(ResultsImageSizeMode.SCALED);
        builder.setScale(fourierImageScale);
    } else {
        builder.setImageSizeMode(ResultsImageSizeMode.IMAGE_SIZE);
        builder.setImageSize(imageSize);
    }
    ImageJImagePeakResults image1 = createPeakResultsImage(bounds, builder, "IP1");
    ImageJImagePeakResults image2 = createPeakResultsImage(bounds, builder, "IP2");
    final float minx = (float) dataBounds.getX();
    final float miny = (float) dataBounds.getY();
    if (this.results2 != null) {
        // Two image comparison
        final ImageJImagePeakResults i1 = image1;
        results.forEach((PeakResultProcedure) result -> {
            final float x = result.getXPosition() - minx;
            final float y = result.getYPosition() - miny;
            i1.add(x, y, signalProvider.getSignal(result));
        });
        final ImageJImagePeakResults i2 = image2;
        results2.forEach((PeakResultProcedure) result -> {
            final float x = result.getXPosition() - minx;
            final float y = result.getYPosition() - miny;
            i2.add(x, y, signalProvider.getSignal(result));
        });
    } else {
        // Block sampling.
        // Ensure we have at least 2 even sized blocks.
        int blockSize = Math.min(results.size() / 2, Math.max(1, settings.blockSize));
        int nblocks = (int) Math.ceil((double) results.size() / blockSize);
        while (nblocks <= 1 && blockSize > 1) {
            blockSize /= 2;
            nblocks = (int) Math.ceil((double) results.size() / blockSize);
        }
        if (nblocks <= 1) {
            // This should not happen since the results should contain at least 2 localisations
            return null;
        }
        if (blockSize != settings.blockSize) {
            IJ.log(pluginTitle + " Warning: Changed block size to " + blockSize);
        }
        final Counter i = new Counter();
        final Counter block = new Counter();
        final int finalBlockSize = blockSize;
        final PeakResult[][] blocks = new PeakResult[nblocks][blockSize];
        results.forEach((PeakResultProcedure) result -> {
            if (i.getCount() == finalBlockSize) {
                block.increment();
                i.reset();
            }
            blocks[block.getCount()][i.getAndIncrement()] = result;
        });
        // Truncate last block
        blocks[block.getCount()] = Arrays.copyOf(blocks[block.getCount()], i.getCount());
        final int[] indices = SimpleArrayUtils.natural(block.getCount() + 1);
        if (settings.randomSplit) {
            MathArrays.shuffle(indices);
        }
        for (final int index : indices) {
            // Split alternating so just rotate
            final ImageJImagePeakResults image = image1;
            image1 = image2;
            image2 = image;
            for (final PeakResult p : blocks[index]) {
                final float x = p.getXPosition() - minx;
                final float y = p.getYPosition() - miny;
                image.add(x, y, signalProvider.getSignal(p));
            }
        }
    }
    image1.end();
    final ImageProcessor ip1 = image1.getImagePlus().getProcessor();
    image2.end();
    final ImageProcessor ip2 = image2.getImagePlus().getProcessor();
    if (settings.maxPerBin > 0 && signalProvider instanceof FixedSignalProvider) {
        // We can eliminate over-sampled pixels
        for (int i = ip1.getPixelCount(); i-- > 0; ) {
            if (ip1.getf(i) > settings.maxPerBin) {
                ip1.setf(i, settings.maxPerBin);
            }
            if (ip2.getf(i) > settings.maxPerBin) {
                ip2.setf(i, settings.maxPerBin);
            }
        }
    }
    return new FireImages(ip1, ip2, nmPerUnit / image1.getScale());
}
Also used : Color(java.awt.Color) RandomUtils(uk.ac.sussex.gdsc.core.utils.rng.RandomUtils) Arrays(java.util.Arrays) Macro(ij.Macro) ImageProcessor(ij.process.ImageProcessor) Rectangle2D(java.awt.geom.Rectangle2D) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) GoalType(org.apache.commons.math3.optim.nonlinear.scalar.GoalType) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) LutHelper(uk.ac.sussex.gdsc.core.ij.process.LutHelper) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ThresholdMethod(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.ThresholdMethod) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) LoessInterpolator(org.apache.commons.math3.analysis.interpolation.LoessInterpolator) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) SimpleCurveFitter(org.apache.commons.math3.fitting.SimpleCurveFitter) PointValuePair(org.apache.commons.math3.optim.PointValuePair) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) Scrollbar(java.awt.Scrollbar) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) FrcCurveResult(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcCurveResult) MaxEval(org.apache.commons.math3.optim.MaxEval) PlugIn(ij.plugin.PlugIn) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) MathArrays(org.apache.commons.math3.util.MathArrays) Prefs(ij.Prefs) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) UnivariateOptimizer(org.apache.commons.math3.optim.univariate.UnivariateOptimizer) GenericDialog(ij.gui.GenericDialog) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) GaussianCurveFitter(org.apache.commons.math3.fitting.GaussianCurveFitter) ResultsImageSizeMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSizeMode) FourierMethod(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FourierMethod) MouseEvent(java.awt.event.MouseEvent) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) Erf(uk.ac.sussex.gdsc.smlm.function.Erf) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair) SamplingMethod(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.SamplingMethod) Frc(uk.ac.sussex.gdsc.smlm.ij.frc.Frc) DoubleMedianWindow(uk.ac.sussex.gdsc.core.utils.DoubleMedianWindow) FrcFireResult(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcFireResult) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) MouseAdapter(java.awt.event.MouseAdapter) DataException(uk.ac.sussex.gdsc.core.data.DataException) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) PlotWindow(ij.gui.PlotWindow) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) Collection(java.util.Collection) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) TrackProgressAdaptor(uk.ac.sussex.gdsc.core.logging.TrackProgressAdaptor) ResultsImageType(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType) ParametricUnivariateFunction(org.apache.commons.math3.analysis.ParametricUnivariateFunction) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) SimplexOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer) BracketFinder(org.apache.commons.math3.optim.univariate.BracketFinder) List(java.util.List) Gaussian(org.apache.commons.math3.analysis.function.Gaussian) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) MultivariateFunction(org.apache.commons.math3.analysis.MultivariateFunction) LUT(ij.process.LUT) FrcCurve(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcCurve) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) Rectangle(java.awt.Rectangle) SearchInterval(org.apache.commons.math3.optim.univariate.SearchInterval) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) AtomicReference(java.util.concurrent.atomic.AtomicReference) TrackProgress(uk.ac.sussex.gdsc.core.logging.TrackProgress) TextField(java.awt.TextField) AWTEvent(java.awt.AWTEvent) ImagePeakResultsFactory(uk.ac.sussex.gdsc.smlm.ij.results.ImagePeakResultsFactory) InitialGuess(org.apache.commons.math3.optim.InitialGuess) UnitHelper(uk.ac.sussex.gdsc.smlm.data.config.UnitHelper) LinkedList(java.util.LinkedList) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) ExecutorService(java.util.concurrent.ExecutorService) DialogListener(ij.gui.DialogListener) ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException) Checkbox(java.awt.Checkbox) StdMath(uk.ac.sussex.gdsc.smlm.utils.StdMath) ResultsImageMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageMode) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) Recorder(ij.plugin.frame.Recorder) WeightedObservedPoints(org.apache.commons.math3.fitting.WeightedObservedPoints) BrentOptimizer(org.apache.commons.math3.optim.univariate.BrentOptimizer) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProviders(uk.ac.sussex.gdsc.core.utils.rng.UniformRandomProviders) Rectangle(java.awt.Rectangle) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) ImageProcessor(ij.process.ImageProcessor) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter)

Example 32 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class FilterMolecules method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "No localisations in memory");
        return;
    }
    if (!showDialog()) {
        return;
    }
    // Load the results
    MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, false, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    // Allow reordering when filtering
    results = results.copy();
    if (settings.removeSingles) {
        results.removeIf(p -> p.getId() <= 0);
        final TIntIntHashMap count = new TIntIntHashMap(results.size());
        results.forEach((PeakResultProcedure) r -> count.adjustOrPutValue(r.getId(), 1, 1));
        results.removeIf(p -> count.get(p.getId()) == 1);
        if (results.isEmpty()) {
            IJ.error(TITLE, "No results after filtering singles");
            return;
        }
    }
    switch(settings.filterMode) {
        case D:
            new FilterDiffusionCoefficient().run(results);
            break;
        default:
            IJ.error(TITLE, "Unknown filter mode: " + settings.filterMode);
    }
}
Also used : PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) Arrays(java.util.Arrays) TIntArrayList(gnu.trove.list.array.TIntArrayList) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) IdFramePeakResultComparator(uk.ac.sussex.gdsc.smlm.results.sort.IdFramePeakResultComparator) StoredData(uk.ac.sussex.gdsc.core.utils.StoredData) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) SortUtils(uk.ac.sussex.gdsc.core.utils.SortUtils) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) SoftLock(uk.ac.sussex.gdsc.core.utils.SoftLock) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) ExecutorService(java.util.concurrent.ExecutorService) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) Label(java.awt.Label) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) NamedObject(uk.ac.sussex.gdsc.smlm.data.NamedObject) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) Executors(java.util.concurrent.Executors) TIntHashSet(gnu.trove.set.hash.TIntHashSet) TimeUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.TimeUnit) Percentile(org.apache.commons.math3.stat.descriptive.rank.Percentile) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) IJ(ij.IJ) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) Line(ij.gui.Line) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) JumpDistanceAnalysis(uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 33 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class Fire method showFrcTimeEvolution.

private void showFrcTimeEvolution(String name, double fireNumber, ThresholdMethod thresholdMethod, double fourierImageScale, int imageSize) {
    IJ.showStatus("Calculating FRC time evolution curve...");
    // Sort by time
    results.sort();
    final int nSteps = 10;
    int maxT = results.getLastFrame();
    if (maxT == 0) {
        maxT = results.size();
    }
    final int step = maxT / nSteps;
    final TDoubleArrayList x = new TDoubleArrayList();
    final TDoubleArrayList y = new TDoubleArrayList();
    double yMin = fireNumber;
    double yMax = fireNumber;
    final MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.copySettings(results);
    int index = 0;
    final PeakResult[] list = results.toArray();
    for (int t = step; t <= maxT - step; t += step) {
        while (index < list.length) {
            final PeakResult r = list[index];
            if (r.getFrame() <= t) {
                newResults.add(r);
                index++;
            } else {
                break;
            }
        }
        x.add(t);
        final Fire f = this.copy();
        final FireResult result = f.calculateFireNumber(fourierMethod, samplingMethod, thresholdMethod, fourierImageScale, imageSize);
        final double fire = (result == null) ? 0 : result.fireNumber;
        y.add(fire);
        yMin = Math.min(yMin, fire);
        yMax = Math.max(yMax, fire);
    }
    // Add the final fire number
    x.add(maxT);
    y.add(fireNumber);
    final double[] xValues = x.toArray();
    final double[] yValues = y.toArray();
    String units = "px";
    if (results.getCalibration() != null) {
        nmPerUnit = results.getNmPerPixel();
        units = "nm";
    }
    final String title = name + " FRC Time Evolution";
    final Plot plot = new Plot(title, "Frames", "Resolution (" + units + ")");
    final double range = Math.max(1, yMax - yMin) * 0.05;
    plot.setLimits(xValues[0], xValues[xValues.length - 1], yMin - range, yMax + range);
    plot.setColor(Color.red);
    plot.addPoints(xValues, yValues, Plot.CONNECTED_CIRCLES);
    ImageJUtils.display(title, plot);
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) FrcFireResult(uk.ac.sussex.gdsc.smlm.ij.frc.Frc.FrcFireResult) Plot(ij.gui.Plot) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Example 34 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method createRankById.

private static float[] createRankById(MemoryPeakResults results) {
    if (results.hasId()) {
        final TFloatArrayList list = new TFloatArrayList(results.size());
        results.forEach((PeakResultProcedure) r -> list.add(r.getId()));
        return list.toArray();
    }
    return null;
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) PickInfo(org.scijava.java3d.PickInfo) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) ItemGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGroup) GUI(ij.gui.GUI) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) TransparentItemShape(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemShape) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Map(java.util.Map) FitProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.FitProtosHelper) ImageWindow3D(ij3d.ImageWindow3D) Triple(org.apache.commons.lang3.tuple.Triple) LutHelper(uk.ac.sussex.gdsc.core.ij.process.LutHelper) KeyStroke(javax.swing.KeyStroke) Appearance(org.scijava.java3d.Appearance) CustomMesh(customnode.CustomMesh) ImageCanvas3D(ij3d.ImageCanvas3D) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) ImageJ3DResultsViewerSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettings) UniverseSettings(ij3d.UniverseSettings) NamedObject(uk.ac.sussex.gdsc.smlm.data.NamedObject) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) ItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGeometryGroup) StopWatch(org.apache.commons.lang3.time.StopWatch) RawResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.RawResultProcedure) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) PlugIn(ij.plugin.PlugIn) WindowConstants(javax.swing.WindowConstants) Color3f(org.scijava.vecmath.Color3f) ListSelectionModel(javax.swing.ListSelectionModel) TransformGroup(org.scijava.java3d.TransformGroup) PeakResultProcedureX(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedureX) XyzResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyzResultProcedure) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) Point3f(org.scijava.vecmath.Point3f) Point3d(org.scijava.vecmath.Point3d) ContentNode(ij3d.ContentNode) SortUtils(uk.ac.sussex.gdsc.core.utils.SortUtils) CustomPointMesh(customnode.CustomPointMesh) RounderUtils(uk.ac.sussex.gdsc.core.data.utils.RounderUtils) PeakResultTableModel(uk.ac.sussex.gdsc.smlm.ij.gui.PeakResultTableModel) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) CustomLineMesh(customnode.CustomLineMesh) ItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh) GeometryArray(org.scijava.java3d.GeometryArray) Field(java.lang.reflect.Field) IntersectionInfo(org.scijava.java3d.PickInfo.IntersectionInfo) Point2d(org.scijava.vecmath.Point2d) MouseEvent(java.awt.event.MouseEvent) ExecutionException(java.util.concurrent.ExecutionException) ReferenceItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ReferenceItemMesh) Canvas3D(org.scijava.java3d.Canvas3D) MouseMotionListener(java.awt.event.MouseMotionListener) LineAttributes(org.scijava.java3d.LineAttributes) ItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh) ResultsTableSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings) ListSelectionListener(javax.swing.event.ListSelectionListener) UniverseListener(ij3d.UniverseListener) TransparentItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh) Builder(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettings.Builder) StandardResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure) TriangleArray(org.scijava.java3d.TriangleArray) Transform3D(org.scijava.java3d.Transform3D) CustomContentHelper(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContentHelper) PointAttributes(org.scijava.java3d.PointAttributes) SplitMix(uk.ac.sussex.gdsc.core.utils.rng.SplitMix) ItemGroupNode(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGroupNode) Content(ij3d.Content) PickCanvas(org.scijava.java3d.utils.pickfast.PickCanvas) ItemShape(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemShape) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh) CoordinatePredicateUtils(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicateUtils) XyResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyResultProcedure) CustomContent(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent) Image3DUniverse(ij3d.Image3DUniverse) Locale(java.util.Locale) ListSelectionModelHelper(uk.ac.sussex.gdsc.smlm.ij.gui.ListSelectionModelHelper) MouseAdapter(java.awt.event.MouseAdapter) DataException(uk.ac.sussex.gdsc.core.data.DataException) ColoringAttributes(org.scijava.java3d.ColoringAttributes) MacroRunner(ij.macro.MacroRunner) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) ListSelectionEvent(javax.swing.event.ListSelectionEvent) UpdateableItemShape(uk.ac.sussex.gdsc.smlm.ij.ij3d.UpdateableItemShape) MouseListener(java.awt.event.MouseListener) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) JMenuBar(javax.swing.JMenuBar) CoordinatePredicate(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JMenu(javax.swing.JMenu) WindowEvent(java.awt.event.WindowEvent) List(java.util.List) PeakResultTableModelFrame(uk.ac.sussex.gdsc.smlm.ij.gui.PeakResultTableModelFrame) OrderedItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.OrderedItemGeometryGroup) Modifier(java.lang.reflect.Modifier) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) Shape3DHelper(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper) TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) LUT(ij.process.LUT) SceneGraphPath(org.scijava.java3d.SceneGraphPath) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) PolygonAttributes(org.scijava.java3d.PolygonAttributes) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) PrecisionMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.PrecisionMethod) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) ItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemMesh) JMenuItem(javax.swing.JMenuItem) ImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress) CustomMeshNode(customnode.CustomMeshNode) View(org.scijava.java3d.View) ExecutorService(java.util.concurrent.ExecutorService) Shape3D(org.scijava.java3d.Shape3D) DefaultUniverse(ij3d.DefaultUniverse) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) Vector3d(org.scijava.vecmath.Vector3d) PeakResultsDigest(uk.ac.sussex.gdsc.smlm.results.PeakResultsDigest) Iterator(java.util.Iterator) BranchGroup(org.scijava.java3d.BranchGroup) AxisAngle4d(org.scijava.vecmath.AxisAngle4d) Image3DMenubar(ij3d.Image3DMenubar) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) ActionEvent(java.awt.event.ActionEvent) ContentInstant(ij3d.ContentInstant) Rounder(uk.ac.sussex.gdsc.core.data.utils.Rounder) TimeUnit(java.util.concurrent.TimeUnit) CustomContentInstant(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContentInstant) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) ImageJ3DResultsViewerSettingsOrBuilder(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettingsOrBuilder) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList)

Example 35 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class OverlayResults method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    names = new String[MemoryPeakResults.getResultNames().size() + 1];
    ids = new int[names.length];
    int count = 0;
    names[count++] = "(None)";
    for (final MemoryPeakResults results : MemoryPeakResults.getAllResults()) {
        if (results.getSource() != null && results.getSource().getOriginal() instanceof IJImageSource) {
            final IJImageSource source = (IJImageSource) (results.getSource().getOriginal());
            final ImagePlus imp = WindowManager.getImage(source.getName());
            if (imp != null) {
                ids[count] = imp.getID();
                names[count++] = results.getName();
            }
        }
    }
    if (count == 1) {
        IJ.error(TITLE, "There are no result images available");
        return;
    }
    names = Arrays.copyOf(names, count);
    Thread thread = null;
    Worker worker = null;
    final NonBlockingGenericDialog gd = new NonBlockingGenericDialog(TITLE);
    settings = Settings.load();
    settings.save();
    gd.addMessage("Overlay results on current image frame");
    gd.addChoice("Results", names, (settings.name == null) ? "" : settings.name);
    gd.addCheckbox("Show_table", settings.showTable);
    gd.addMessage("");
    gd.addHelp(HelpUrls.getUrl("overlay-results"));
    gd.hideCancelButton();
    gd.setOKLabel("Close");
    if (!(IJ.isMacro() || java.awt.GraphicsEnvironment.isHeadless())) {
        worker = new Worker();
        choice = (Choice) gd.getChoices().get(0);
        choice.addItemListener(worker);
        checkbox = (Checkbox) gd.getCheckboxes().get(0);
        checkbox.addItemListener(worker);
        label = (Label) gd.getMessage();
        // Initialise
        worker.refresh();
        // Listen for changes to an image
        ImagePlus.addImageListener(worker);
        thread = new Thread(worker);
        thread.setDaemon(true);
        thread.start();
    }
    gd.showDialog();
    if (worker != null) {
        ImagePlus.removeImageListener(worker);
    }
    if (!gd.wasCanceled()) {
        settings.name = gd.getNextChoice();
        settings.showTable = gd.getNextBoolean();
    }
    if (thread != null && worker != null) {
        worker.running = false;
        inbox.close(true);
        try {
            thread.join(0);
        } catch (final InterruptedException ex) {
            Logger.getLogger(getClass().getName()).log(Level.WARNING, "Unexpected interruption", ex);
            Thread.currentThread().interrupt();
        }
    }
}
Also used : IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) ImagePlus(ij.ImagePlus) Point(java.awt.Point)

Aggregations

MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)138 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)61 List (java.util.List)47 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)46 IJ (ij.IJ)39 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)39 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)38 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)36 PlugIn (ij.plugin.PlugIn)34 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)33 Counter (uk.ac.sussex.gdsc.smlm.results.count.Counter)33 ImagePlus (ij.ImagePlus)31 Rectangle (java.awt.Rectangle)31 SimpleArrayUtils (uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils)31 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)28 TextUtils (uk.ac.sussex.gdsc.core.utils.TextUtils)28 SettingsManager (uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager)28 FrameCounter (uk.ac.sussex.gdsc.smlm.results.count.FrameCounter)28