use of uk.ac.sussex.gdsc.smlm.results.PeakResultPoint in project GDSC-SMLM by aherbert.
the class BenchmarkSmartSpotRanking method runAnalysis.
private void runAnalysis() {
// Extract all the results in memory into a list per frame. This can be cached
boolean refresh = false;
final Pair<Integer, TIntObjectHashMap<List<Coordinate>>> coords = coordinateCache.get();
TIntObjectHashMap<List<Coordinate>> actualCoordinates;
if (coords.getKey() != simulationParameters.id) {
// Do not get integer coordinates
// The Coordinate objects will be PeakResultPoint objects that store the original PeakResult
// from the MemoryPeakResults
actualCoordinates = ResultsMatchCalculator.getCoordinates(results, false);
coordinateCache.set(Pair.of(simulationParameters.id, actualCoordinates));
refresh = true;
} else {
actualCoordinates = coords.getValue();
}
// Extract all the candidates into a list per frame. This can be cached if the settings have not
// changed.
CandidateData candidateData = candidateDataCache.get();
if (refresh || candidateData == null || candidateData.differentSettings(filterResult.id, settings)) {
candidateData = subsetFilterResults(filterResult.filterResults);
candidateDataCache.set(candidateData);
}
final TIntObjectHashMap<FilterCandidates> filterCandidates = candidateData.filterCandidates;
final ImageStack stack = imp.getImageStack();
// Create a pool of workers
final int nThreads = Prefs.getThreads();
final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<>(nThreads * 2);
final List<Worker> workers = new LinkedList<>();
final List<Thread> threads = new LinkedList<>();
final Ticker ticker = ImageJUtils.createTicker(filterCandidates.size(), nThreads);
for (int i = 0; i < nThreads; i++) {
final Worker worker = new Worker(jobs, stack, actualCoordinates, filterCandidates, ticker);
final Thread t = new Thread(worker);
workers.add(worker);
threads.add(t);
t.start();
}
// Process the frames
filterCandidates.forEachKey(value -> {
put(jobs, value);
return true;
});
// Finish all the worker threads by passing in a null job
for (int i = 0; i < threads.size(); i++) {
put(jobs, -1);
}
// Wait for all to finish
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).join();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new ConcurrentRuntimeException("Unexpected interrupt", ex);
}
}
threads.clear();
IJ.showProgress(1);
if (ImageJUtils.isInterrupted()) {
IJ.showStatus("Aborted");
return;
}
IJ.showStatus("Collecting results ...");
final TIntObjectHashMap<RankResults> rankResults = new TIntObjectHashMap<>();
for (final Worker w : workers) {
rankResults.putAll(w.results);
}
summariseResults(rankResults, candidateData);
IJ.showStatus("");
}
Aggregations