use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class TraceMolecules method createSummaryTable.
private void createSummaryTable() {
if (java.awt.GraphicsEnvironment.isHeadless()) {
if (header == null) {
header = createHeader();
IJ.log(header);
}
} else {
if (summaryTable == null || !summaryTable.isVisible()) {
summaryTable = new TextWindow(TITLE + " Data Summary", createHeader(), "", 800, 300);
summaryTable.setVisible(true);
}
}
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class ImageJTablePeakResults method createResultsWindow.
/**
* Create the result window (if it is not available).
*/
private void createResultsWindow() {
final String header = createResultsHeader();
roiPainter = null;
for (final Frame f : WindowManager.getNonImageWindows()) {
if (f != null && tableTitle.equals(f.getTitle()) && f instanceof TextWindow) {
resultsWindow = (TextWindow) f;
// Check if the existing table matches the desired header
final String currentHeader = resultsWindow.getTextPanel().getColumnHeadings();
if (!currentHeader.startsWith(header)) {
resultsWindow = null;
continue;
}
roiPainter = map.get(resultsWindow.getTextPanel());
break;
}
}
newWindow = false;
if (!ImageJUtils.isShowing(resultsWindow)) {
newWindow = true;
resultsWindow = new TextWindow(tableTitle, header, "", 800, 300);
roiPainter = new ImageRoiPainter(resultsWindow.getTextPanel(), "", this);
// The ROI painter adds itself to the TextPanel as a mouse listener. However
// the TextPanel addMouseListener() adds to the private TextCanvas object so it
// cannot be retrieved. Store the painter in a global lookup table.
map.put(resultsWindow.getTextPanel(), roiPainter);
}
tp = resultsWindow.getTextPanel();
if (roiPainter != null && getSource() != null) {
roiPainter.setTitle(getSource().getOriginal().getName());
// Update the coordinate provider (avoids memory leaks with old objects lying around)
roiPainter.setCoordProvider(this);
// Get the headings for extracting the coordinates
final String[] headings = tp.getColumnHeadings().split("\t");
indexT = indexX = indexY = -1;
for (int i = 0; i < headings.length; i++) {
if (headings[i].equals(frameColumnName)) {
indexT = i;
continue;
}
// Allow for units
if (headings[i].equals("X") || headings[i].startsWith("X (")) {
indexX = i;
continue;
}
if (headings[i].equals("Y") || headings[i].startsWith("Y (")) {
indexY = i;
continue;
}
}
}
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method compareCoordinates.
@SuppressWarnings("null")
private void compareCoordinates(MemoryPeakResults results1, MemoryPeakResults results2, MemoryPeakResults results3, double distanceThreshold) {
final Pulse[] p1 = extractPulses(results1);
final Pulse[] p2 = extractPulses(results2);
final Pulse[] p3 = extractPulses(results3);
final List<Pulse> tp = null;
List<Pulse> fp = null;
List<Pulse> fn = null;
List<PointPair> pairs = null;
final List<Pulse> tp2 = null;
List<Pulse> fp2 = null;
List<Pulse> fn2 = null;
List<PointPair> pairs2 = null;
if (settings.showPairs) {
pairs = new LinkedList<>();
fp = new LinkedList<>();
fn = new LinkedList<>();
pairs2 = new LinkedList<>();
fp2 = new LinkedList<>();
fn2 = new LinkedList<>();
}
final MatchResult result = MatchCalculator.analyseResults2D(p1, p2, distanceThreshold, tp, fp, fn, pairs);
final MatchResult result2 = MatchCalculator.analyseResults2D(p1, p3, distanceThreshold, tp2, fp2, fn2, pairs2);
// Create output
Consumer<String> resultsOutput;
if (!java.awt.GraphicsEnvironment.isHeadless()) {
final TextWindow resultsWindow = ImageJUtils.refresh(resultsWindowRef, () -> new TextWindow(TITLE + " Results", createResultsHeader(), "", 900, 300));
resultsOutput = resultsWindow::append;
if (settings.showPairs) {
if (p3 == null) {
// Produce a pairs output
final WindowAndPainter wap = refresh(pairsWindowRef, true, resultsWindow, results1);
// Add the unmatched points
WindowManager.getIDList();
for (final Coordinate c : fn) {
pairs.add(new PointPair(c, null));
}
for (final Coordinate c : fp) {
pairs.add(new PointPair(null, c));
}
final List<? extends PointPair> sortedPairs = sort(pairs);
for (final PointPair pair : sortedPairs) {
addPairResult(wap.textWindow, pair);
}
} else {
// Produce a triple output
final WindowAndPainter wap = refresh(triplesWindowRef, false, resultsWindow, results1);
final HashMap<Pulse, Triple> map = new HashMap<>();
final ArrayList<Triple> triples = new ArrayList<>(pairs.size());
for (final PointPair pair : pairs) {
final Pulse p = (Pulse) pair.getPoint1();
final Triple t = new Triple(p, (Pulse) pair.getPoint2(), null);
triples.add(t);
map.put(p, t);
}
// Complete the reference set of points
for (final Coordinate c : fn) {
final Pulse p = (Pulse) c;
final Triple t = new Triple(p, null, null);
triples.add(t);
map.put(p, t);
}
// Add the unmatched points
for (final Coordinate c : fp) {
triples.add(new Triple(null, (Pulse) c, null));
}
for (final Coordinate c : fp2) {
triples.add(new Triple(null, null, (Pulse) c));
}
// Add the results from the second match
for (final PointPair pair : pairs2) {
final Pulse p = (Pulse) pair.getPoint1();
final Pulse pp = (Pulse) pair.getPoint2();
final Triple triple = map.get(p);
if (triple != null) {
triple.p3 = pp;
} else {
triples.add(new Triple(null, null, pp));
}
}
final List<? extends Triple> sortedTriples = sort(triples);
for (final Triple t : sortedTriples) {
addTripleResult(wap.textWindow, t);
}
}
}
} else {
if (writeHeader.compareAndSet(true, false)) {
IJ.log(createResultsHeader());
}
resultsOutput = IJ::log;
}
final StringBuilder sb = new StringBuilder();
addResult(resultsOutput, sb, settings.inputOption1, settings.inputOption2, distanceThreshold, result);
if (p3 != null) {
addResult(resultsOutput, sb, settings.inputOption1, settings.inputOption3, distanceThreshold, result2);
}
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method refresh.
private static WindowAndPainter refresh(AtomicReference<WindowAndPainter> ref, boolean pairs, TextWindow resultsWindow, MemoryPeakResults results1) {
// Produce a pairs output
final WindowAndPainter wap = ConcurrencyUtils.refresh(ref, // Test the window is showing
w -> ImageJUtils.isShowing(w.textWindow), // Create
() -> {
final String title = TITLE + ((pairs) ? " Pairs" : " Triples");
final String header = pairs ? createPairsHeader() : createTriplesHeader();
final TextWindow window = new TextWindow(title, header, "", 900, 300);
// Position relative to results window
final Point p = resultsWindow.getLocation();
p.y += resultsWindow.getHeight();
window.setLocation(p);
final CoordinateProvider coordinateProvider = line -> {
// Extract the startT and x,y coordinates from the first pulse in the line
final int[] index = { 0, 5, 12 };
final String[] fields = line.split("\t");
for (final int i : index) {
if (i < fields.length) {
if (fields[i].equals("-")) {
continue;
}
final int startT = Integer.parseInt(fields[i]);
final double x = Double.parseDouble(fields[i + 2]);
final double y = Double.parseDouble(fields[i + 3]);
return new double[] { startT, x, y };
}
}
return null;
};
final ImageRoiPainter painter = new ImageRoiPainter(window.getTextPanel(), results1.getSource().getOriginal().getName(), coordinateProvider);
final WindowAndPainter result = new WindowAndPainter(window, painter);
// Free memory on close
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent event) {
ref.compareAndSet(result, null);
super.windowClosed(event);
}
});
return result;
});
wap.textWindow.getTextPanel().clear();
wap.painter.setTitle(results1.getSource().getOriginal().getName());
return wap;
}
use of ij.text.TextWindow in project GDSC-SMLM by aherbert.
the class TrackPopulationAnalysis method createModelTable.
/**
* Creates a table to show the final model. This uses the assignments to create a mixture model
* from the original data.
*
* @param data the data
* @param weights the weights for each component
* @param component the component
*/
private static void createModelTable(double[][] data, double[] weights, int[] component) {
final MixtureMultivariateGaussianDistribution model = MultivariateGaussianMixtureExpectationMaximization.createMixed(data, component);
final MultivariateGaussianDistribution[] distributions = model.getDistributions();
// Get the fraction of each component
final int[] count = new int[MathUtils.max(component) + 1];
Arrays.stream(component).forEach(c -> count[c]++);
try (BufferedTextWindow tw = new BufferedTextWindow(ImageJUtils.refresh(modelTableRef, () -> new TextWindow("Track Population Model", createHeader(), "", 800, 300)))) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < weights.length; i++) {
sb.setLength(0);
sb.append(i).append('\t');
sb.append(MathUtils.rounded((double) count[i] / component.length)).append('\t');
sb.append(MathUtils.rounded(weights[i]));
final double[] means = distributions[i].getMeans();
final double[] sd = distributions[i].getStandardDeviations();
for (int j = 0; j < means.length; j++) {
sb.append('\t').append(MathUtils.rounded(means[j])).append('\t').append(MathUtils.rounded(sd[j]));
}
tw.append(sb.toString());
}
}
}
Aggregations