Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Bug fixes for v3.1.5 #28

Merged
merged 15 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>sc.fiji</groupId>
<artifactId>Simple_Neurite_Tracer</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.1.5</version>

<name>Simple Neurite Tracer</name>
<description>The ImageJ framework for semi-automated tracing of neurons and other tube-like structures.</description>
Expand Down
44 changes: 31 additions & 13 deletions src/main/java/tracing/NeuriteTracerResultsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,8 +102,9 @@ 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;
protected JMenu fileMenu;
Expand Down Expand Up @@ -478,7 +480,7 @@ protected void exitRequested() {

plugin.cancelSearch(true);
plugin.notifyListeners(new SNTEvent(SNTEvent.QUIT));
new SNTPrefs(plugin).savePluginPrefs();
prefs.savePluginPrefs();
pw.dispose();
fw.dispose();
dispose();
Expand Down Expand Up @@ -762,6 +764,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;

Expand Down Expand Up @@ -1175,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);
Expand Down Expand Up @@ -1600,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() {
Expand Down Expand Up @@ -1885,7 +1895,7 @@ private JMenu tracingMenu() {
optionsMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new SNTPrefs(plugin).promptForOptions();
prefs.promptForOptions();
}
});
tracingMenu.add(optionsMenuItem);
Expand Down Expand Up @@ -1976,4 +1986,12 @@ public void actionPerformed(final ActionEvent e) {
return mi;
}

public PathWindow getPathWindow() {
return pw;
}

public FillWindow getFillWindow() {
return fw;
}

}
12 changes: 11 additions & 1 deletion src/main/java/tracing/PathAndFillManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,17 @@ synchronized void setPathPointsInVolume(final ArrayList<Path> paths, final byte[
*/
final List<Bresenham3D.IntegerPoint> 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 * %d + %d]",
z, y, width, x));
}
}
}

Expand Down
39 changes: 38 additions & 1 deletion src/main/java/tracing/SNTPrefs.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tracing;

import java.awt.Font;
import java.awt.Point;

import ij.Prefs;
import ij.gui.GenericDialog;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -60,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);
Expand Down Expand Up @@ -121,6 +129,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) {
Expand All @@ -130,11 +153,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;
}

Expand All @@ -144,7 +177,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];
Expand Down Expand Up @@ -176,6 +209,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];
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/tracing/ShollAnalysisPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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("(?<!^)(\\\\|/){2,}", Matcher.quoteReplacement(File.separator));
}

private String swcTypeCodesToString() {
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/tracing/SimpleNeuriteTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1219,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);

Expand All @@ -1236,7 +1237,7 @@ public void startFillerThread(final FillerThread filler) {
synchronized public void startFillingPaths(final Set<Path> fromPaths) {

// currentlyFilling = true;
resultsDialog.fw.pauseOrRestartFilling.setText("Pause");
resultsDialog.getFillWindow().pauseOrRestartFilling.setText("Pause");

filler = new FillerThread(xy, stackMin, stackMax, false, // startPaused
true, // reciprocal
Expand All @@ -1246,7 +1247,7 @@ synchronized public void startFillingPaths(final Set<Path> fromPaths) {
addThreadToDraw(filler);

filler.addProgressListener(this);
filler.addProgressListener(resultsDialog.fw);
filler.addProgressListener(resultsDialog.getFillWindow());

filler.setSourcePaths(fromPaths);

Expand Down Expand Up @@ -1565,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<Path> 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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tracing/Simple_Neurite_Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")");
Expand Down