From eb3a9b22d77ac0b5d220f358f7ff0840a5fd4ae3 Mon Sep 17 00:00:00 2001 From: Tiago Date: Fri, 9 Jun 2017 00:06:55 -0400 Subject: [PATCH 1/9] Bugfix in Bresenham3D: Force out-of-bounds points to canvas boundaries --- src/main/java/tracing/PathAndFillManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/tracing/PathAndFillManager.java b/src/main/java/tracing/PathAndFillManager.java index 26d8a63fe..bf21aefd5 100644 --- a/src/main/java/tracing/PathAndFillManager.java +++ b/src/main/java/tracing/PathAndFillManager.java @@ -2024,7 +2024,17 @@ synchronized void setPathPointsInVolume(final ArrayList paths, final byte[ */ final List pointsToDraw = Bresenham3D.bresenham3D(previous, current); for (final Bresenham3D.IntegerPoint ip : pointsToDraw) { - slices[ip.z][ip.y * width + ip.x] = (byte) 255; + try { + slices[ip.z][ip.y * width + ip.x] = (byte) 255; + } catch (final ArrayIndexOutOfBoundsException ignored) { + final int x = Math.min(width - 1, Math.max(0, ip.x)); + final int y = Math.min(height - 1, Math.max(0, ip.y)); + final int z = Math.min(depth - 1, Math.max(0, ip.z)); + slices[z][y * width + x] = (byte) 255; + if (SimpleNeuriteTracer.verbose) + SNT.log(String.format("Bresenham3D: Forced out-of-bounds point to [%d][%d]", z, + (y * width + x))); + } } } From fbc42b4d2eee7af7647a512d0536b197fabfd7e9 Mon Sep 17 00:00:00 2001 From: Tiago Date: Sun, 13 Aug 2017 22:19:01 -0400 Subject: [PATCH 2/9] (Temporary) Bugfix for issue #27. With this, we're doing two things: - Enable the OK button at all times, even if specified paths are tagged as invalid - improve the detection of repeated file separators in specified file paths --- src/main/java/tracing/ShollAnalysisPlugin.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/tracing/ShollAnalysisPlugin.java b/src/main/java/tracing/ShollAnalysisPlugin.java index 00c9bad5c..7d97080f1 100644 --- a/src/main/java/tracing/ShollAnalysisPlugin.java +++ b/src/main/java/tracing/ShollAnalysisPlugin.java @@ -285,7 +285,7 @@ private boolean showDialog() { if (gd.wasCanceled()) return false; else if (gd.wasOKed()) { - sholl.gui.Utils.improveRecording(); + Utils.improveRecording(); return dialogItemChanged(gd, null); } return false; @@ -317,7 +317,7 @@ public void run() { popup.addSeparator(); mi = Utils.menuItemTrigerringURL("Online Documentation", Sholl_Analysis.URL + "#Traces"); popup.add(mi); - mi = sholl.gui.Utils.menuItemTriggeringResources(); + mi = Utils.menuItemTriggeringResources(); popup.add(mi); return popup; } @@ -356,15 +356,15 @@ public boolean dialogItemChanged(final GenericDialog arg0, final AWTEvent event) for (int i = 2; i < cbxs.size(); i++) ((Checkbox) cbxs.get(i)).setEnabled(restrictBySWCType); - boolean enableOK = true; + //boolean enableOK = true; String warning = ""; if (impRequired && !validImageFile(new File(imgPath))) { - enableOK = false; + //enableOK = false; warning += "Not a valid image. "; } if (!validTracesFile(new File(tracesPath))) { - enableOK = false; + //enableOK = false; warning += "Not a valid .traces/.(e)swc file"; } if (!warning.isEmpty()) { @@ -375,7 +375,7 @@ public boolean dialogItemChanged(final GenericDialog arg0, final AWTEvent event) infoMsg.setText(defaultInfoMsg); } - return enableOK; + return true; //enableOK } private String getFilePathWithoutExtension(final String filePath) { @@ -451,10 +451,8 @@ private boolean validTracesFile(final File file) { * We'll need to remove those to avoid I/O errors. */ private String normalizedPath(final String path) { - // This is way to simplistic: See // chase-seibert.github.io/blog/2009/04/10/java-replaceall-fileseparator.html - return path.replaceAll(Matcher.quoteReplacement(File.separator) + "+", - Matcher.quoteReplacement(File.separator)); + return path.replaceAll("(? Date: Mon, 14 Aug 2017 16:10:09 -0400 Subject: [PATCH 3/9] Reuse the same preferences instance --- src/main/java/tracing/NeuriteTracerResultsDialog.java | 6 ++++-- src/main/java/tracing/SimpleNeuriteTracer.java | 1 + src/main/java/tracing/Simple_Neurite_Tracer.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/tracing/NeuriteTracerResultsDialog.java b/src/main/java/tracing/NeuriteTracerResultsDialog.java index 760323332..9b868b054 100644 --- a/src/main/java/tracing/NeuriteTracerResultsDialog.java +++ b/src/main/java/tracing/NeuriteTracerResultsDialog.java @@ -103,6 +103,7 @@ public class NeuriteTracerResultsDialog extends JDialog implements ActionListene public PathWindow pw; public FillWindow fw; + private SNTPrefs prefs; protected JMenuBar menuBar; protected JMenu fileMenu; @@ -478,7 +479,7 @@ protected void exitRequested() { plugin.cancelSearch(true); plugin.notifyListeners(new SNTEvent(SNTEvent.QUIT)); - new SNTPrefs(plugin).savePluginPrefs(); + prefs.savePluginPrefs(); pw.dispose(); fw.dispose(); dispose(); @@ -762,6 +763,7 @@ public NeuriteTracerResultsDialog(final String title, final SimpleNeuriteTracer new ClarifyingKeyListener().addKeyAndContainerListenerRecursively(this); this.plugin = plugin; + prefs = plugin.prefs; final SimpleNeuriteTracer thisPlugin = plugin; this.launchedByArchive = launchedByArchive; @@ -1885,7 +1887,7 @@ private JMenu tracingMenu() { optionsMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { - new SNTPrefs(plugin).promptForOptions(); + prefs.promptForOptions(); } }); tracingMenu.add(optionsMenuItem); diff --git a/src/main/java/tracing/SimpleNeuriteTracer.java b/src/main/java/tracing/SimpleNeuriteTracer.java index 1f8ddfe75..7733f13e8 100644 --- a/src/main/java/tracing/SimpleNeuriteTracer.java +++ b/src/main/java/tracing/SimpleNeuriteTracer.java @@ -96,6 +96,7 @@ public class SimpleNeuriteTracer extends ThreePanes protected static final int ballRadiusMultiplier = 5; protected PathAndFillManager pathAndFillManager; + protected SNTPrefs prefs; protected boolean use3DViewer; protected Image3DUniverse univ; diff --git a/src/main/java/tracing/Simple_Neurite_Tracer.java b/src/main/java/tracing/Simple_Neurite_Tracer.java index d32b5bc80..6e14f10aa 100644 --- a/src/main/java/tracing/Simple_Neurite_Tracer.java +++ b/src/main/java/tracing/Simple_Neurite_Tracer.java @@ -184,7 +184,7 @@ public void run(final String ignoredArguments) { spacing_units = "" + calibration.getUnit(); } - final SNTPrefs prefs = new SNTPrefs(this); + prefs = new SNTPrefs(this); prefs.loadStartupPrefs(); final GenericDialog gd = new GenericDialog("Simple Neurite Tracer (v" + SNT.VERSION + ")"); From 3337828fee0c603cadc4b68badf7b689f5e5af4f Mon Sep 17 00:00:00 2001 From: Tiago Date: Mon, 14 Aug 2017 21:31:14 -0400 Subject: [PATCH 4/9] Make debug message more informative --- src/main/java/tracing/PathAndFillManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/tracing/PathAndFillManager.java b/src/main/java/tracing/PathAndFillManager.java index bf21aefd5..862b91c20 100644 --- a/src/main/java/tracing/PathAndFillManager.java +++ b/src/main/java/tracing/PathAndFillManager.java @@ -2032,8 +2032,8 @@ synchronized void setPathPointsInVolume(final ArrayList paths, final byte[ final int z = Math.min(depth - 1, Math.max(0, ip.z)); slices[z][y * width + x] = (byte) 255; if (SimpleNeuriteTracer.verbose) - SNT.log(String.format("Bresenham3D: Forced out-of-bounds point to [%d][%d]", z, - (y * width + x))); + SNT.log(String.format("Bresenham3D: Forced out-of-bounds point to [%d][%d * %d + %d]", + z, y, width, x)); } } } From 88f7099f2bd509a77691b1ecdad0af83c5dd327e Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 15 Aug 2017 02:00:30 +0000 Subject: [PATCH 5/9] Add getters for PathWindow/FillWindow --- .../java/tracing/NeuriteTracerResultsDialog.java | 12 ++++++++++-- src/main/java/tracing/SimpleNeuriteTracer.java | 14 +++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/tracing/NeuriteTracerResultsDialog.java b/src/main/java/tracing/NeuriteTracerResultsDialog.java index 9b868b054..35cffef04 100644 --- a/src/main/java/tracing/NeuriteTracerResultsDialog.java +++ b/src/main/java/tracing/NeuriteTracerResultsDialog.java @@ -101,8 +101,8 @@ public class NeuriteTracerResultsDialog extends JDialog implements ActionListene public static final boolean verbose = SimpleNeuriteTracer.verbose; - public PathWindow pw; - public FillWindow fw; + private PathWindow pw; + private FillWindow fw; private SNTPrefs prefs; protected JMenuBar menuBar; @@ -1978,4 +1978,12 @@ public void actionPerformed(final ActionEvent e) { return mi; } + public PathWindow getPathWindow() { + return pw; + } + + public FillWindow getFillWindow() { + return fw; + } + } diff --git a/src/main/java/tracing/SimpleNeuriteTracer.java b/src/main/java/tracing/SimpleNeuriteTracer.java index 7733f13e8..1ccfa48b8 100644 --- a/src/main/java/tracing/SimpleNeuriteTracer.java +++ b/src/main/java/tracing/SimpleNeuriteTracer.java @@ -1220,7 +1220,7 @@ public void startFillerThread(final FillerThread filler) { this.filler = filler; filler.addProgressListener(this); - filler.addProgressListener(resultsDialog.fw); + filler.addProgressListener(resultsDialog.getFillWindow()); addThreadToDraw(filler); @@ -1237,7 +1237,7 @@ public void startFillerThread(final FillerThread filler) { synchronized public void startFillingPaths(final Set fromPaths) { // currentlyFilling = true; - resultsDialog.fw.pauseOrRestartFilling.setText("Pause"); + resultsDialog.getFillWindow().pauseOrRestartFilling.setText("Pause"); filler = new FillerThread(xy, stackMin, stackMax, false, // startPaused true, // reciprocal @@ -1247,7 +1247,7 @@ synchronized public void startFillingPaths(final Set fromPaths) { addThreadToDraw(filler); filler.addProgressListener(this); - filler.addProgressListener(resultsDialog.fw); + filler.addProgressListener(resultsDialog.getFillWindow()); filler.setSourcePaths(fromPaths); @@ -1566,14 +1566,14 @@ public void selectPath(final Path p, final boolean addToExistingSelection) { else pathsToSelect.add(p); if (addToExistingSelection) { - pathsToSelect.addAll(resultsDialog.pw.getSelectedPaths()); + pathsToSelect.addAll(resultsDialog.getPathWindow().getSelectedPaths()); } - resultsDialog.pw.setSelectedPaths(pathsToSelect, this); + resultsDialog.getPathWindow().setSelectedPaths(pathsToSelect, this); } public Set getSelectedPaths() { - if (resultsDialog.pw != null) { - return resultsDialog.pw.getSelectedPaths(); + if (resultsDialog.getPathWindow() != null) { + return resultsDialog.getPathWindow().getSelectedPaths(); } throw new RuntimeException("getSelectedPaths was called when resultsDialog.pw was null"); } From 9f287a91dfa7eab22b2c583e07423a23c0cc7cc0 Mon Sep 17 00:00:00 2001 From: Tiago Date: Mon, 14 Aug 2017 22:04:28 -0400 Subject: [PATCH 6/9] Store PathWindow/FillWindow locations in preferences Hopefully this will circumvent #26 --- src/main/java/tracing/SNTPrefs.java | 38 ++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/tracing/SNTPrefs.java b/src/main/java/tracing/SNTPrefs.java index ffe850b1f..bcef8c3e2 100644 --- a/src/main/java/tracing/SNTPrefs.java +++ b/src/main/java/tracing/SNTPrefs.java @@ -1,6 +1,7 @@ package tracing; import java.awt.Font; +import java.awt.Point; import ij.Prefs; import ij.gui.GenericDialog; @@ -22,6 +23,7 @@ public class SNTPrefs { private static final int LOOK_FOR_TUBES = 128; private static final int LOOK_FOR_OOF = 256; private static final int SHOW_ONLY_SELECTED = 512; + private static final int STORE_WIN_LOCATIONS = 1024; // private static final int JUST_NEAR_SLICES = 1024; private static final int ENFORCE_DEFAULT_PATH_COLORS = 2048; private static final int DEBUG = 4096; @@ -31,6 +33,11 @@ public class SNTPrefs { private static final String BOOLEANS = "tracing.snt.booleans"; private static final String SNAP_XY = "tracing.snt.xysnap"; private static final String SNAP_Z = "tracing.snt.zsnap"; + private static final String PATHWIN_LOC = "tracing.snt.pwloc"; + private static final String FILLWIN_LOC = "tracing.snt.fwloc"; + + //private static final String SNAP_Z = "tracing.snt.zsnap"; + // private final static String NEARBY_VIEW = "tracing.snt.nearbyview"; private final int UNSET_PREFS = -1; @@ -121,6 +128,21 @@ protected void savePluginPrefs() { setPref(DEBUG, SimpleNeuriteTracer.verbose); Prefs.set(BOOLEANS, currentBooleans); clearLegacyPrefs(); + if (isSaveWinLocations()) { + final NeuriteTracerResultsDialog rd = snt.resultsDialog; + if (rd == null) + return; + final PathWindow pw = rd.getPathWindow(); + if (pw != null) + Prefs.saveLocation(PATHWIN_LOC, pw.getLocation()); + final FillWindow fw = rd.getFillWindow(); + if (fw != null) + Prefs.saveLocation(FILLWIN_LOC, fw.getLocation()); + } + } + + protected boolean isSaveWinLocations() { + return getPref(STORE_WIN_LOCATIONS); } private void setPref(final int key, final boolean value) { @@ -130,11 +152,21 @@ private void setPref(final int key, final boolean value) { currentBooleans &= ~key; } + protected Point getPathWindowLocation() { + return Prefs.getLocation(PATHWIN_LOC); + } + + protected Point getFillWindowLocation() { + return Prefs.getLocation(FILLWIN_LOC); + } + private void resetOptions() { clearLegacyPrefs(); Prefs.set(BOOLEANS, null); Prefs.set(SNAP_XY, null); Prefs.set(SNAP_Z, null); + Prefs.set(FILLWIN_LOC, null); + Prefs.set(PATHWIN_LOC, null); currentBooleans = UNSET_PREFS; } @@ -144,7 +176,7 @@ private void clearLegacyPrefs() { protected void promptForOptions() { - final int startupOptions = 6; + final int startupOptions = 7; final int pluginOptions = 2; final String[] startupLabels = new String[startupOptions]; @@ -176,6 +208,10 @@ protected void promptForOptions() { startupLabels[idx] = "Load_default \".traces\" file (if present)"; startupStates[idx++] = snt.look4tracesFile; + startupItems[idx] = STORE_WIN_LOCATIONS; + startupLabels[idx] = "Remember window locations across restarts"; + startupStates[idx++] = isSaveWinLocations(); + final String[] pluginLabels = new String[pluginOptions]; final int[] pluginItems = new int[pluginOptions]; final boolean[] pluginStates = new boolean[pluginOptions]; From 53fb086612f195a73c02e98a643747bb021de5b1 Mon Sep 17 00:00:00 2001 From: Tiago Date: Mon, 14 Aug 2017 22:05:13 -0400 Subject: [PATCH 7/9] Fix preferences not being properly reload after reset --- src/main/java/tracing/SNTPrefs.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/tracing/SNTPrefs.java b/src/main/java/tracing/SNTPrefs.java index bcef8c3e2..a68411e54 100644 --- a/src/main/java/tracing/SNTPrefs.java +++ b/src/main/java/tracing/SNTPrefs.java @@ -67,6 +67,7 @@ private void getBooleans() { } protected void loadPluginPrefs() { + getBooleans(); snt.useCompressedXML = getPref(COMPRESSED_XML); snt.autoCanvasActivation = getPref(AUTO_CANVAS_ACTIVATION); snt.snapCursor = getPref(SNAP_CURSOR); From e7f2f6ce38c324b575788006b913f196aa289405 Mon Sep 17 00:00:00 2001 From: Tiago Date: Mon, 14 Aug 2017 22:08:04 -0400 Subject: [PATCH 8/9] Replace auto-placement of windows with stored locations from previous session With multiple displays, this is likely to only work with the main one, but at least will work on Windows hiDPI displays (as per #26) --- .../tracing/NeuriteTracerResultsDialog.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/tracing/NeuriteTracerResultsDialog.java b/src/main/java/tracing/NeuriteTracerResultsDialog.java index 35cffef04..5975bc37a 100644 --- a/src/main/java/tracing/NeuriteTracerResultsDialog.java +++ b/src/main/java/tracing/NeuriteTracerResultsDialog.java @@ -38,6 +38,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.Point; import java.awt.Rectangle; import java.awt.TextField; import java.awt.event.ActionEvent; @@ -1177,7 +1178,8 @@ protected void displayOnStarting() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - arrangeDialogs(); + if (plugin.prefs.isSaveWinLocations()) + arrangeDialogs(); arrangeCanvases(); setVisible(true); setPathListVisible(true, false); @@ -1602,14 +1604,20 @@ else if (reset) } private void arrangeDialogs() { - final GraphicsDevice activeScreen = getGraphicsConfiguration().getDevice(); - final int screenWidth = activeScreen.getDisplayMode().getWidth(); - final int screenHeight = activeScreen.getDisplayMode().getHeight(); - final Rectangle bounds = activeScreen.getDefaultConfiguration().getBounds(); - - setLocation(bounds.x, bounds.y); - pw.setLocation(screenWidth - pw.getWidth(), bounds.y); - fw.setLocation(bounds.x + getWidth(), screenHeight - fw.getHeight()); + Point loc = prefs.getPathWindowLocation(); + if (loc != null) + pw.setLocation(loc); + loc = prefs.getFillWindowLocation(); + if (loc != null) + fw.setLocation(loc); +// final GraphicsDevice activeScreen = getGraphicsConfiguration().getDevice(); +// final int screenWidth = activeScreen.getDisplayMode().getWidth(); +// final int screenHeight = activeScreen.getDisplayMode().getHeight(); +// final Rectangle bounds = activeScreen.getDefaultConfiguration().getBounds(); +// +// setLocation(bounds.x, bounds.y); +// pw.setLocation(screenWidth - pw.getWidth(), bounds.y); +// fw.setLocation(bounds.x + getWidth(), screenHeight - fw.getHeight()); } private void arrangeCanvases() { From 8450f3b026493567f57429df8f5cbaff288244eb Mon Sep 17 00:00:00 2001 From: Tiago Date: Mon, 14 Aug 2017 22:23:03 -0400 Subject: [PATCH 9/9] Release v3.1.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 16e45d68f..8a80f3706 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ sc.fiji Simple_Neurite_Tracer - 3.1.5-SNAPSHOT + 3.1.5 Simple Neurite Tracer The ImageJ framework for semi-automated tracing of neurons and other tube-like structures.