Search in sources :

Example 1 with RoiListener

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

the class TcPalmAnalysis method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "No localisations in memory");
        return;
    }
    // Only allow 1 instance to run
    if (!instanceLock.acquire()) {
        final Window w = WindowManager.getWindow(TITLE);
        if (w != null) {
            w.toFront();
            return;
        }
    // Fall through to allow the plugin to run. This may still have concurrency issues if
    // another version is running but the window is not currently showing/registered with
    // the window manager. Perhaps show a dialog asking to continue.
    }
    if (!showDialog()) {
        instanceLock.release();
        return;
    }
    // Load the results
    results = ResultsManager.loadInputResults(settings.getInputOption(), false, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        instanceLock.release();
        return;
    }
    // Allocate singles an id for analysis.
    results = results.copyAndAssignZeroIds();
    dataCalibration = new DataCalibration(results.getCalibration());
    // Show a super-resolution image where clusters can be selected.
    final Rectangle bounds = results.getBounds(true);
    final PeakResultsList resultsList = new PeakResultsList();
    resultsList.copySettings(results);
    ResultsManager.addImageResults(resultsList, settings.getResultsImageSettings(), bounds, 0);
    resultsList.begin();
    resultsList.addAll(results.toArray());
    resultsList.end();
    image = (ImageJImagePeakResults) resultsList.getOutput(0);
    // Note: Setting the lut name in the image only has an effect if the image is not showing
    // thus the lut is applied afterwards.
    final ImagePlus imp = image.getImagePlus();
    if (TextUtils.isNotEmpty(image.getLutName())) {
        imp.setLut(LutHelper.createLut(LutColour.forName(image.getLutName()), true));
    }
    // Set-up analysis processing:
    // Store latest image ROI bounds and analysis settings.
    // ConcurrentMonoStack to store next image ROI bounds and analysis settings.
    // When image is clicked submit for analysis.
    // When settings are changed submit for analysis.
    // Submit for analysis checks if ROI is area ROI. if so it:
    // - adds current settings to the next analysis monostack
    // - acquires a softlock and if available submits a runnable to do the analysis until
    // the monostack is empty
    lock = new SoftLock();
    workQueue = new ConcurrentMonoStack<>();
    // Use the current ROI (which may remain from previous plugin execution)
    previous = new Work(0, imp.getRoi(), settings.build());
    executor = Executors.newSingleThreadExecutor();
    // Create the bounds and activation times for each cluster
    clusterData = createClusterData(results);
    // Add interactive monitor to the image where clusters can be selected.
    // For all selected clusters show on an Activations-vs-Time plot.
    final RoiListener roiListener = new RoiListener() {

        @Override
        public void roiModified(ImagePlus imp2, int id) {
            if (imp2 != null && imp.getID() == imp2.getID()) {
                addWork(imp.getRoi());
            }
        }
    };
    Roi.addRoiListener(roiListener);
    // Add monitor for the selection of clusters in the current clusters table
    clusterSelectedListener = new ClusterSelectedListener();
    // Initialise the loop view
    loopImage = new LoopImage().setSettings(previous.settings).setColourMap(colourMap);
    // steepness parameter: local window size (sec) and activation rate (per sec)
    try {
        showAnalysisDialog();
    } finally {
        Roi.removeRoiListener(roiListener);
        // Remove the action from the single instance of the current clusters table
        removeListener(currentGroupsTable.get());
        removeListener(currentClustersTable.get());
        removeListener(allClustersTable.get());
        executor.shutdown();
        instanceLock.release();
        SettingsManager.writeSettings(settings);
    }
}
Also used : Window(java.awt.Window) PlotWindow(ij.gui.PlotWindow) PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) RoiListener(ij.gui.RoiListener) Rectangle(java.awt.Rectangle) ImagePlus(ij.ImagePlus) SoftLock(uk.ac.sussex.gdsc.core.utils.SoftLock)

Aggregations

ImagePlus (ij.ImagePlus)1 PlotWindow (ij.gui.PlotWindow)1 RoiListener (ij.gui.RoiListener)1 Rectangle (java.awt.Rectangle)1 Window (java.awt.Window)1 SoftLock (uk.ac.sussex.gdsc.core.utils.SoftLock)1 PeakResultsList (uk.ac.sussex.gdsc.smlm.results.PeakResultsList)1