use of ij.text.TextWindow in project TrakEM2 by trakem2.
the class Utils method createResultsTable.
/**
* Creates a new ResultsTable with the given window title and column titles, and 2 decimals of precision, or if one exists for the given window title, returns it.
*/
public static final ResultsTable createResultsTable(final String title, final String[] columns) {
try {
return new TaskOnEDT<ResultsTable>(new Callable<ResultsTable>() {
@Override
public ResultsTable call() {
final TextWindow tw = (TextWindow) WindowManager.getFrame(title);
if (null != tw) {
// hacking again ... missing a getResultsTable() method in TextWindow
final ResultsTable rt = (ResultsTable) Utils.getField(tw.getTextPanel(), "rt");
// assumes columns will be identical
if (null != rt)
return rt;
}
// else create a new one
final ResultsTable rt = new ResultsTable();
rt.setPrecision(2);
for (int i = 0; i < columns.length; i++) rt.setHeading(i, columns[i]);
//
return rt;
}
}).get();
} catch (final Throwable t) {
IJError.print(t);
return null;
}
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class TraceMolecules method createSummaryTable.
private Consumer<String> createSummaryTable() {
if (java.awt.GraphicsEnvironment.isHeadless()) {
if (logHeader.compareAndSet(true, false)) {
IJ.log(createHeader());
}
return IJ::log;
}
TextWindow window = summaryTable.get();
if (window == null || !window.isVisible()) {
window = new TextWindow(pluginTitle + " Data Summary", createHeader(), "", 800, 300);
window.setVisible(true);
summaryTable.set(window);
}
return window::append;
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class SummariseResults method createSummaryTable.
private static TextWindow createSummaryTable() {
final TextWindow summary = ImageJUtils.refresh(summaryRef, () -> {
final TextWindow window = new TextWindow("Peak Results Summary", createHeader(), "", 800, 300);
window.getTextPanel().addMouseListener(ShowStatisticsListener.INSTANCE);
return window;
});
// This could be optional but at current there is no dialog and it seems unnecessary
clearSummaryTable(summary);
return summary;
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class SummariseResults method showSummary.
private static void showSummary(Collection<MemoryPeakResults> results, int[] removeNullResults) {
final TextWindow summary = createSummaryTable();
final StringBuilder sb = new StringBuilder();
try (BufferedTextWindow tw = new BufferedTextWindow(summary)) {
for (final MemoryPeakResults result : results) {
tw.append(createSummary(sb, result, removeNullResults));
}
tw.append("");
}
summary.toFront();
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method runCompareCoordinates.
@SuppressWarnings("null")
private void runCompareCoordinates(MemoryPeakResults results1, MemoryPeakResults results2) {
final boolean requirePairs = settings.showPairs || settings.isSaveClassifications();
final boolean saveMatched = settings.isSaveMatched();
final boolean saveUnmatched = settings.isSaveUnmatched();
final TextFilePeakResults fileResults = createFilePeakResults(results2);
final List<PointPair> allMatches = new LinkedList<>();
final List<PointPair> pairs = (requirePairs) ? new LinkedList<>() : null;
final double maxDistance = settings.distanceThreshold + settings.increments * settings.delta;
// Divide the results into time points
final TIntObjectHashMap<List<Coordinate>> actualCoordinates = getCoordinates(results1, settings.coordinateMethod1);
final TIntObjectHashMap<List<Coordinate>> predictedCoordinates = getCoordinates(results2, settings.coordinateMethod2);
int n1 = 0;
int n2 = 0;
// Process each time point
for (final int t : getTimepoints(actualCoordinates, predictedCoordinates)) {
final Coordinate[] actual = getCoordinates(actualCoordinates, t);
final Coordinate[] predicted = getCoordinates(predictedCoordinates, t);
final List<Coordinate> tp = null;
List<Coordinate> fp = null;
List<Coordinate> fn = null;
final List<PointPair> matches = new LinkedList<>();
if (requirePairs) {
fp = new LinkedList<>();
fn = new LinkedList<>();
}
MatchCalculator.analyseResults2D(actual, predicted, maxDistance, tp, fp, fn, matches);
// Aggregate
n1 += actual.length;
n2 += predicted.length;
allMatches.addAll(matches);
if (settings.showPairs) {
pairs.addAll(matches);
for (final Coordinate c : fn) {
pairs.add(new PointPair(c, null));
}
for (final Coordinate c : fp) {
pairs.add(new PointPair(null, c));
}
}
if (fileResults != null) {
// Matches are marked in the original value with 1 for true, 0 for false
if (saveMatched) {
for (final PointPair pair : matches) {
PeakResult result = ((PeakResultPoint) pair.getPoint2()).getPeakResult();
result = result.copy();
result.setOrigValue(1);
fileResults.add(result);
}
}
if (saveUnmatched) {
for (final Coordinate c : fp) {
PeakResult result = ((PeakResultPoint) c).getPeakResult();
result = result.copy();
result.setOrigValue(0);
fileResults.add(result);
}
}
}
}
if (fileResults != null) {
fileResults.end();
}
final boolean doIdAnalysis1 = settings.idAnalysis && haveIds(results1);
final boolean doIdAnalysis2 = settings.idAnalysis && haveIds(results2);
// Create output.
// This supports headless mode with just the results table
// or graphical mode with a results table and pairs window.
final boolean headless = java.awt.GraphicsEnvironment.isHeadless();
TextWindow resultsWindow = null;
if (!headless) {
resultsWindow = (settings.showTable) ? createResultsWindow(doIdAnalysis1 || doIdAnalysis2) : null;
showPairs(results1, pairs, resultsWindow);
}
showResults(results1, results2, allMatches, n1, n2, doIdAnalysis1, doIdAnalysis2, resultsWindow);
savePairs(results1, results2, allMatches);
}
Aggregations