Skip to content

Commit 814a8e5

Browse files
committed
Improvements to TimeProfiler and misc fixes:
- Plots and tables remaining open after quitting SNT - Contextual menus being injected twice in SNTTables with non-unique titles - Spurious warning on missing temporary path - Improve organization of menus and searches in Command Palette
1 parent 2b5cf40 commit 814a8e5

9 files changed

Lines changed: 132 additions & 89 deletions

File tree

‎src/main/java/sc/fiji/snt/PathManagerUI.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public PathManagerUI(final SNT plugin) {
365365
jmi.setToolTipText("Creates a 'linear image' from the pixels associated with single paths");
366366
jmi.addActionListener(singlePathListener);
367367
process.add(jmi);
368-
process.addSeparator();
368+
GuiUtils.addSeparator(process, "Semantic Segmentation:");
369369
jmi = new JMenuItem(MultiPathActionListener.SEND_TO_LABKIT_CMD, IconFactory.menuIcon(IconFactory.GLYPH.KIWI_BIRD));
370370
jmi.setToolTipText("Starts a Labkit session loaded with labels from selected paths");
371371
jmi.addActionListener(multiPathListener);
@@ -508,7 +508,7 @@ public void windowClosing(final WindowEvent ignored) {
508508
}
509509

510510
private JMenu getSpineUtilsMenu(final MultiPathActionListener multiPathListener) {
511-
final JMenu menu = new JMenu("Spine/Varicosities/Labels");
511+
final JMenu menu = new JMenu("Spines/Varicosities/Labels");
512512
final String tooltip = "Assumes spine/varicosity markers have already been assigned to selected path(s)";
513513
menu.setIcon(IconFactory.menuIcon('\ue29c', true));
514514

@@ -568,25 +568,25 @@ private JMenu getTimeSequenceMenu(final MultiPathActionListener multiPathListene
568568
menu.setIcon(IconFactory.menuIcon(IconFactory.GLYPH.VIDEO));
569569

570570
// 'Generic' commands that do not require matching paths across time
571-
GuiUtils.addSeparator(menu, "Generic:");
572571
JMenuItem jmi = new JMenuItem(MultiPathActionListener.TIME_COLOR_CODING_CMD, IconFactory.menuIcon(IconFactory.GLYPH.COLOR2));
573572
jmi.setToolTipText(tooltip);
574573
jmi.addActionListener(multiPathListener);
575574
ScriptRecorder.setRecordingCall(jmi, "snt.getUI().getPathManager().runCommand(\"" + MultiPathActionListener.TIME_COLOR_CODING_CMD + "\")");
576575
menu.add(jmi);
577576
jmi = new JMenuItem(MultiPathActionListener.TIME_PROFILER_CMD, IconFactory.menuIcon(IconFactory.GLYPH.CHART_LINE));
578-
jmi.setToolTipText("Timelapse version of " + MultiPathActionListener.PLOT_PROFILE_CMD);
577+
jmi.setToolTipText("Timelapse version of " + MultiPathActionListener.PLOT_PROFILE_CMD
578+
+".\nMonitor intensities profiles across time, e.g., calcium dynamics along neurites.");
579579
jmi.addActionListener(multiPathListener);
580580
ScriptRecorder.setRecordingCall(jmi, "snt.getUI().getPathManager().runCommand(\"" + MultiPathActionListener.TIME_PROFILER_CMD + "\")");
581581
menu.add(jmi);
582582
jmi = new JMenuItem(MultiPathActionListener.TIME_PROFILE_UNMATCHED_CMD, IconFactory.menuIcon(IconFactory.GLYPH.CHART_AREA));
583-
jmi.setToolTipText(tooltip);
583+
jmi.setToolTipText("Plots a measurement across time");
584584
jmi.addActionListener(multiPathListener);
585585
ScriptRecorder.setRecordingCall(jmi, "snt.getUI().getPathManager().runCommand(\"" + MultiPathActionListener.TIME_PROFILE_UNMATCHED_CMD + "\")");
586586
menu.add(jmi);
587587

588588
// Commands that require paths to be matched across time
589-
GuiUtils.addSeparator(menu, "Neurite-based:");
589+
GuiUtils.addSeparator(menu, "Neurite-based Analysis:");
590590
jmi = new JMenuItem(MultiPathActionListener.MATCH_PATHS_ACROSS_TIME_CMD, IconFactory.menuIcon('\ue4af', true));
591591
jmi.setToolTipText(tooltip);
592592
jmi.addActionListener(multiPathListener);

‎src/main/java/sc/fiji/snt/SNT.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,14 +2159,13 @@ public synchronized void cancelTemporary() {
21592159
if (!lastStartPointSet) {
21602160
discreteMsg(
21612161
"No initial start point has been set yet.<br>Do that with a mouse click or a Shift+" +
2162-
GuiUtils.ctrlKey() +
2163-
"-click if the start of the path should join another.");
2162+
GuiUtils.ctrlKey() + "-click if the start of the path should join another.");
21642163
return;
21652164
}
21662165

21672166
if (temporaryPath == null) {
2168-
showCanvasWarning("There is no temporary path to discard");
2169-
return;
2167+
//showCanvasWarning("There is no temporary path to discard");
2168+
return; // nothing else to do
21702169
}
21712170

21722171
removeSphere(targetBallName);

‎src/main/java/sc/fiji/snt/SNTUI.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ else if (pmUI.measurementsUnsaved())
978978
guiUtils = null;
979979
recViewerFrame = null;
980980
sciViewSNT = null;
981+
GuiUtils.closeAllPlots();
982+
GuiUtils.closeAllTables();
981983
GuiUtils.restoreLookAndFeel();
982984
}
983985

@@ -3330,9 +3332,9 @@ private JMenu analysisMenu() {
33303332
final JMenuItem shollMenuItem = GuiUtils.MenuItems.shollAnalysis();
33313333
shollMenuItem.addActionListener(e -> {
33323334
if (noPathsShollError()) return;
3335+
softWarningOnShollPreview();
33333336
final Tree tree = getPathManager().getSingleTree();
33343337
if (tree == null) return;
3335-
softWarningOnShollPreview();
33363338
final HashMap<String, Object> inputs = new HashMap<>();
33373339
inputs.put("tree", tree);
33383340
inputs.put("snt", plugin);

‎src/main/java/sc/fiji/snt/analysis/NodeProfiler.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public <T extends RealType<T>> SortedMap<Integer, List<Double>> getValues(final
308308
* @return The profile (Mean±SD of all the profiled data)
309309
*/
310310
public Plot getPlot(final Path path) {
311-
final Plot plot = new Plot(getTitle(path, -1), getXAxisLabel(path), getYAxisLabel(path, -1));
311+
final Plot plot = new PathProfiler.SNTPlot(getTitle(path, -1), getXAxisLabel(path), getYAxisLabel(path, -1));
312312
final Color[] colors = SNTColor.getDistinctColorsAWT((int) dataset.getChannels());
313313
StringBuilder legend = new StringBuilder();
314314
for (int ch = 0; ch < dataset.getChannels(); ch++) {
@@ -346,7 +346,7 @@ private ArrayList<Double> assembleXValuesFromProfiledValues(final SNTTable table
346346
* @return The profile (Mean±SD of all the profiled data)
347347
*/
348348
public Plot getPlot(final Path path, final int channel) {
349-
final Plot plot = new Plot(getTitle(path, channel), getXAxisLabel(path), getYAxisLabel(path, channel));
349+
final Plot plot = new PathProfiler.SNTPlot(getTitle(path, channel), getXAxisLabel(path), getYAxisLabel(path, channel));
350350
final SNTTable table = getTable(path, channel);
351351
final ArrayList<Double> ymeans = new ArrayList<>();
352352
final ArrayList<Double> ystds = new ArrayList<>();

‎src/main/java/sc/fiji/snt/analysis/PathProfiler.java‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
import java.util.stream.Collectors;
2828
import java.util.stream.IntStream;
2929

30+
import ij.gui.PlotWindow;
3031
import net.imagej.axis.Axes;
3132
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
3233
import org.scijava.ItemVisibility;
3334
import org.scijava.command.Command;
3435
import org.scijava.command.CommandService;
35-
import org.scijava.convert.ConvertService;
3636
import org.scijava.module.MutableModuleItem;
3737
import org.scijava.plot.LineStyle;
3838
import org.scijava.plot.MarkerStyle;
@@ -57,10 +57,7 @@
5757
import sc.fiji.snt.Tree;
5858
import sc.fiji.snt.analysis.ProfileProcessor.Shape;
5959
import sc.fiji.snt.gui.cmds.CommonDynamicCmd;
60-
import sc.fiji.snt.util.ImgUtils;
61-
import sc.fiji.snt.util.PointInImage;
62-
import sc.fiji.snt.util.SNTColor;
63-
import sc.fiji.snt.util.TreeUtils;
60+
import sc.fiji.snt.util.*;
6461

6562
/**
6663
* Command to retrieve Path profiles (plots of voxel intensities values along a
@@ -259,8 +256,7 @@ protected void init() {
259256
private Dataset getDatasetFromImp(final ImagePlus imp) {
260257
if (imp == null)
261258
throw new IllegalArgumentException("ImagePlus is null");
262-
final ConvertService convertService = getContext().service(ConvertService.class);
263-
dataset = convertService.convert(imp, Dataset.class);
259+
dataset = ImpUtils.toDataset(imp);
264260
if (dataset == null)
265261
throw new UnsupportedOperationException("BUG: Could not convert ImagePlus to Dataset");
266262
return dataset;
@@ -735,7 +731,7 @@ public Plot getPlot() throws IllegalArgumentException, ArrayIndexOutOfBoundsExce
735731
}
736732

737733
private Plot getMeanSDPlot(final int channel) {
738-
final Plot plot = new Plot(getPlotTitle(channel), getXAxisLabel(), getYAxisLabel(channel));
734+
final Plot plot = new SNTPlot(getPlotTitle(channel), getXAxisLabel(), getYAxisLabel(channel));
739735
final Color[] colors = getSeriesColorsAWT();
740736
final StringBuilder legend = new StringBuilder();
741737
for (int i = 0; i < tree.size(); i++) {
@@ -767,7 +763,7 @@ public Plot getPlot(final int channel) throws IllegalArgumentException, ArrayInd
767763
if (!valuesAssignedToTree || (channel > 0 && channel != lastprofiledChannel) ) {
768764
assignValues(channel);
769765
}
770-
final Plot plot = new Plot(getPlotTitle(channel), getXAxisLabel(), getYAxisLabel(channel));
766+
final Plot plot = new SNTPlot(getPlotTitle(channel), getXAxisLabel(), getYAxisLabel(channel));
771767
final Color[] colors = getSeriesColorsAWT();
772768
final StringBuilder legend = new StringBuilder();
773769
for (int i = 0; i < tree.size(); i++) {
@@ -785,7 +781,7 @@ public Plot getPlot(final int channel) throws IllegalArgumentException, ArrayInd
785781
}
786782

787783
private Plot getMeanSDPlot(final Path path) {
788-
final Plot plot = new Plot(getPlotTitle(-1), getXAxisLabel(), getYAxisLabel(-1));
784+
final Plot plot = new SNTPlot(getPlotTitle(-1), getXAxisLabel(), getYAxisLabel(-1));
789785
final Color[] colors = SNTColor.getDistinctColorsAWT((int) dataset.getChannels());
790786
final StringBuilder legend = new StringBuilder();
791787
for (int i = 1; i <= dataset.getChannels(); i++) {
@@ -1014,6 +1010,20 @@ public List<Map<String, List<Double>>> getTimeProfile(final Path path, final int
10141010
return result;
10151011
}
10161012

1013+
protected static class SNTPlot extends Plot {
1014+
1015+
public SNTPlot(String title, String xLabel, String yLabel) {
1016+
super(title, xLabel, yLabel);
1017+
}
1018+
1019+
@Override
1020+
public PlotWindow show() {
1021+
final PlotWindow pw = super.show();
1022+
pw.setName("snt-plot"); // See GuiUtils.closeAllPlots()
1023+
return pw;
1024+
}
1025+
}
1026+
10171027
/* IDE debug method **/
10181028
public static void main(final String[] args) {
10191029
final ImageJ ij = new ImageJ();

‎src/main/java/sc/fiji/snt/analysis/SNTChart.java‎

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
import sc.fiji.snt.gui.cmds.SaveMeasurementsCmd;
8989
import sc.fiji.snt.util.SNTColor;
9090
import smile.plot.swing.Heatmap;
91-
import smile.plot.swing.Palette;
9291

9392
/**
9493
* Extension of {@link ChartPanel} modified for scientific publications and
@@ -2069,7 +2068,7 @@ public static List<SNTChart> openCharts() {
20692068

20702069
/** Closes all open charts */
20712070
public static void closeAll() {
2072-
for (SNTChart openInstance : openInstances) {
2071+
for (final SNTChart openInstance : openInstances) {
20732072
openInstance.disposeInternal();
20742073
}
20752074
openInstances.clear();
@@ -2090,7 +2089,7 @@ public static void tileAll() {
20902089
public static void tile(final Collection<SNTChart> charts) {
20912090
final List<JFrame> frames = new ArrayList<>();
20922091
charts.forEach(oi -> frames.add(oi.getFrame()));
2093-
GuiUtils.tile(frames);
2092+
GuiUtils.tile(frames, charts.size() > 4);
20942093
}
20952094

20962095
/**
@@ -2170,13 +2169,16 @@ public static SNTChart combine(final Collection<SNTChart> charts, final String c
21702169
* @param colorTable the color table (LUT) used to color histogram bars (null allowed)
21712170
* @param prob Whether frequencies should be normalized to probabilities
21722171
* @param axisLabels Labels for the axes (optional)
2172+
* @return the frame holding the histogram
21732173
* @throws InterruptedException if the histogram cannot be displayed
21742174
* @throws InvocationTargetException if the histogram cannot be displayed
21752175
*/
2176-
public static void showHistogram3D(final double[][] data, final ColorTable colorTable, final boolean prob, final String... axisLabels) throws InterruptedException, InvocationTargetException {
2176+
public static JFrame showHistogram3D(final double[][] data, final ColorTable colorTable, final boolean prob, final String... axisLabels) throws InterruptedException, InvocationTargetException {
21772177
final int nBins1 = AnalysisUtils.computeNBins(new DescriptiveStatistics(data[0]));
21782178
final int nBins2 = AnalysisUtils.computeNBins(new DescriptiveStatistics(data[1]));
2179-
showSmilePlot(smile.plot.swing.Histogram3D.class, null, data, nBins1, nBins2, prob, colorTable, axisLabels);
2179+
final JFrame frame = showSmilePlot(smile.plot.swing.Histogram3D.class, null, data, nBins1, nBins2, prob, colorTable, axisLabels);
2180+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2181+
return frame;
21802182
}
21812183

21822184
/**
@@ -2191,8 +2193,9 @@ public static void showHistogram3D(final double[][] data, final ColorTable color
21912193
*/
21922194
public static JFrame showHeatmap(final double[][] data, final ColorTable colorTable, final String... axisLabels)
21932195
throws InterruptedException, InvocationTargetException {
2194-
return showHeatmap(null, data, colorTable, axisLabels);
2195-
2196+
final JFrame frame = showHeatmap(null, data, colorTable, axisLabels);
2197+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2198+
return frame;
21962199
}
21972200

21982201
/**
@@ -2210,7 +2213,9 @@ public static JFrame showHeatmap(final String title, final double[][] data, fina
22102213
throws InterruptedException, InvocationTargetException {
22112214
if (data == null || data.length < 2 || data[0].length < 2)
22122215
throw new IllegalArgumentException("Heatmap requires at least a 2x2 matrix (got " + (data == null ? "null" : data.length + "x" + data[0].length) + ")");
2213-
return showSmilePlot(smile.plot.swing.Heatmap.class, title, data, -1, -1, false, colorTable, axisLabels);
2216+
final JFrame frame = showSmilePlot(smile.plot.swing.Heatmap.class, title, data, -1, -1, false, colorTable, axisLabels);
2217+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2218+
return frame;
22142219
}
22152220

22162221
/**
@@ -2233,7 +2238,9 @@ public static JFrame showHistogram3D(final Collection<Double> values1, final Col
22332238
.mapToObj(i -> new double[]{v1[i], v2[i]}).toArray(double[][]::new);
22342239
final int nBins1 = AnalysisUtils.computeNBins(new DescriptiveStatistics(v1));
22352240
final int nBins2 = AnalysisUtils.computeNBins(new DescriptiveStatistics(v2));
2236-
return showSmilePlot(smile.plot.swing.Histogram3D.class, null, data, nBins1, nBins2, false, colorTable, axisLabels);
2241+
final JFrame frame = showSmilePlot(smile.plot.swing.Histogram3D.class, null, data, nBins1, nBins2, false, colorTable, axisLabels);
2242+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2243+
return frame;
22372244
}
22382245

22392246
/**
@@ -2249,7 +2256,9 @@ public static JFrame showHistogram3D(final Collection<Double> values1, final Col
22492256
*/
22502257
public static JFrame showHeatmap(final Collection<Double> values1, final Collection<Double> values2,
22512258
final ColorTable colorTable, final String... axisLabels) throws InterruptedException, InvocationTargetException {
2252-
return showHeatmap(null, values1, values2, colorTable, axisLabels);
2259+
final JFrame frame = showHeatmap(null, values1, values2, colorTable, axisLabels);
2260+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2261+
return frame;
22532262
}
22542263

22552264
/**
@@ -2270,7 +2279,9 @@ public static JFrame showHeatmap(final String title, final Collection<Double> va
22702279
final double[] v2 = values2.stream().mapToDouble(Double::doubleValue).toArray();
22712280
final double[][] data = IntStream.range(0, Math.min(v1.length, v2.length))
22722281
.mapToObj(i -> new double[]{v1[i], v2[i]}).toArray(double[][]::new);
2273-
return showSmilePlot(smile.plot.swing.Heatmap.class, title, data, -1, -1, false, colorTable, axisLabels);
2282+
final JFrame frame = showSmilePlot(smile.plot.swing.Heatmap.class, title, data, -1, -1, false, colorTable, axisLabels);
2283+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2284+
return frame;
22742285
}
22752286

22762287
/**
@@ -2293,7 +2304,9 @@ public static JFrame showHeatmap(final String title, final double[] xCoords, fin
22932304
figure.setTitle(title != null ? title : "Heatmap");
22942305
if (axisLabels != null && axisLabels.length > 0)
22952306
figure.setAxisLabels(Arrays.copyOf(axisLabels, figure.getAxisLabels().length));
2296-
return figure.show();
2307+
final JFrame frame = figure.show();
2308+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2309+
return frame;
22972310
}
22982311

22992312
/**
@@ -2311,7 +2324,9 @@ public static JFrame showHeatmap(final String title, final double[] xCoords, fin
23112324
*/
23122325
public static JFrame showHistogram3D(final String title, final DescriptiveStatistics stats1, final DescriptiveStatistics stats2,
23132326
final ColorTable colorTable, final String... axisLabels) throws InterruptedException, InvocationTargetException {
2314-
return showSmileHistogram(smile.plot.swing.Histogram3D.class, title, stats1, stats2, colorTable, axisLabels);
2327+
final JFrame frame = showSmileHistogram(smile.plot.swing.Histogram3D.class, title, stats1, stats2, colorTable, axisLabels);
2328+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2329+
return frame;
23152330
}
23162331

23172332
/**
@@ -2328,7 +2343,9 @@ public static JFrame showHistogram3D(final String title, final DescriptiveStatis
23282343
*/
23292344
public static JFrame showHistogram3D(final DescriptiveStatistics stats1, final DescriptiveStatistics stats2,
23302345
final ColorTable colorTable, final String... axisLabels) throws InterruptedException, InvocationTargetException {
2331-
return showSmileHistogram(smile.plot.swing.Histogram3D.class, null, stats1, stats2, colorTable, axisLabels);
2346+
final JFrame frame = showSmileHistogram(smile.plot.swing.Histogram3D.class, null, stats1, stats2, colorTable, axisLabels);
2347+
frame.setName("snt-smile-plot"); // see GuiUtils.closeAllPlots
2348+
return frame;
23322349
}
23332350

23342351
private static <T extends smile.plot.swing.Plot> JFrame showSmileHistogram(final Class<T> smilePlotClass, final String title, final DescriptiveStatistics stats1, final DescriptiveStatistics stats2,

0 commit comments

Comments
 (0)