Skip to content

Commit c3f959c

Browse files
committed
1 parent 015016f commit c3f959c

4 files changed

Lines changed: 41 additions & 45 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ public boolean save(final String filePath) {
293293
* @param context the SciJava application context
294294
*/
295295
public void setContext(final Context context) throws IllegalArgumentException {
296-
context.inject(this);
296+
if (displayService == null)
297+
context.inject(this);
297298
if (tableIO == null)
298299
tableIO = context.getService(IOService.class).getInstance(DefaultTableIOPlugin.class);
299300
}

‎src/main/java/sc/fiji/snt/analysis/sholl/gui/ShollTable.java‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ else if (stat.getDataMode() == ShollStats.DataMode.EXTRA)
132132
: "log(" + yFitHeader + "/" + nStats.getNormalizerDescription() + ")";
133133
addColumn(yHeader, nStats.getFitYValues());
134134
}
135-
case PolarProfileStats pStats -> {
136-
pStats.detailReport(this);
137-
}
135+
case PolarProfileStats pStats -> pStats.detailReport(this);
138136
default -> {
139137
}
140138
}
@@ -213,7 +211,7 @@ public void summarize(final String header) {
213211
final int c = Integer.parseInt(props.getProperty(Profile.KEY_CHANNEL_POS));
214212
final int z = Integer.parseInt(props.getProperty(Profile.KEY_SLICE_POS));
215213
final int t = Integer.parseInt(props.getProperty(Profile.KEY_FRAME_POS));
216-
set(getCol("CZT Position "), row, "" + c + ":" + z + ":" + t);
214+
set(getCol("CZT Position "), row, c + ":" + z + ":" + t);
217215
}
218216
final int nSamples = Integer.parseInt(props.getProperty(Profile.KEY_NSAMPLES, "1"));
219217
set(getCol("Samples/radius"), row, nSamples);
@@ -248,9 +246,7 @@ public void summarize(final String header) {
248246
set(getCol("Regression slope"), row, nStats.getSlope());
249247
}
250248
}
251-
case PolarProfileStats pStats -> {
252-
pStats.appendSummaryReport(this);
253-
}
249+
case PolarProfileStats pStats -> pStats.appendSummaryReport(this);
254250
case null, default -> {
255251
}
256252
}
@@ -340,6 +336,8 @@ private int getCol(final DefaultGenericTable table, final String header) {
340336
@Override
341337
public void setContext(final Context context) throws IllegalStateException, IllegalArgumentException {
342338
super.setContext(context);
339+
if (prefService == null)
340+
prefService = context.getService(PrefService.class);
343341
if (prefService != null) {
344342
final boolean detailedMetrics = prefService.getBoolean(ShollAnalysisPrefsCmd.class, "detailedMetrics", ShollAnalysisPrefsCmd.DEF_DETAILED_METRICS);
345343
setDetailedSummary(detailedMetrics);

‎src/main/java/sc/fiji/snt/plugin/ShollAnalysisImgCommonCmd.java‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.scijava.command.CommandService;
4343
import org.scijava.command.DynamicCommand;
4444
import org.scijava.convert.ConvertService;
45-
import org.scijava.display.Display;
4645
import org.scijava.module.ModuleItem;
4746
import org.scijava.module.MutableModuleItem;
4847
import org.scijava.plugin.Parameter;
@@ -289,8 +288,9 @@ public class ShollAnalysisImgCommonCmd extends DynamicCommand {
289288
private Thread analysisThread;
290289
private AnalysisRunner analysisRunner;
291290
private Profile profile;
292-
private ShollTable commonSummaryTable;
293-
private Display<?> detailedTableDisplay;
291+
292+
/* Common summary table shared by all instances */
293+
private static volatile ShollTable commonSummaryTable;
294294

295295
/* Preferences */
296296
private int minDegree;
@@ -464,7 +464,7 @@ private void getNewDataset() {
464464
logger.debug("Failed to change dataset");
465465
return;
466466
}
467-
ImagePlus newImp = null;
467+
ImagePlus newImp;
468468
try {
469469
newImp = convertService.convert(newDataset, ImagePlus.class);
470470
} catch (final UnsupportedOperationException exc) {
@@ -1213,9 +1213,6 @@ public void run() {
12131213
? new ShollTable(lStats, nStats) : new ShollTable(lStats, nStats, pStats);
12141214
dTable.listProfileEntries();
12151215
dTable.setTitle(imp.getTitle()+"_Sholl-Profiles");
1216-
if (detailedTableDisplay != null) {
1217-
detailedTableDisplay.close();
1218-
}
12191216
outputs.add(dTable);
12201217
dTable.createOrUpdateDisplay();
12211218
}
@@ -1224,12 +1221,15 @@ public void run() {
12241221

12251222
final ShollTable sTable = (pStats==null)
12261223
? new ShollTable(lStats, nStats) : new ShollTable(lStats, nStats, pStats);
1227-
if (commonSummaryTable == null)
1228-
commonSummaryTable = new ShollTable();
1229-
sTable.summarize(commonSummaryTable, imp.getTitle());
1230-
sTable.setTitle("Sholl_Results");
1231-
outputs.add(sTable);
1232-
sTable.createOrUpdateDisplay();
1224+
synchronized (ShollAnalysisImgCommonCmd.class) { // thread safety
1225+
if (commonSummaryTable == null) {
1226+
commonSummaryTable = new ShollTable();
1227+
commonSummaryTable.setTitle("Sholl_Results");
1228+
}
1229+
sTable.summarize(commonSummaryTable, imp.getTitle());
1230+
outputs.add(commonSummaryTable);
1231+
commonSummaryTable.createOrUpdateDisplay();
1232+
}
12331233
}
12341234

12351235
setProfile(profile);
@@ -1246,10 +1246,9 @@ else if (output instanceof ShollTable table) {
12461246
if (!table.hasContext()) table.setContext(getContext());
12471247
if (!table.saveSilently(saveDir)) ++failures;
12481248
}
1249-
else if (output instanceof ImagePlus) {
1250-
final ImagePlus imp = (ImagePlus)output;
1251-
final File outFile = new File(saveDir, imp.getTitle());
1252-
if (!IJ.saveAsTiff(imp, outFile.getAbsolutePath())) ++failures;
1249+
else if (output instanceof ImagePlus impO) {
1250+
final File outFile = new File(saveDir, impO.getTitle());
1251+
if (!IJ.saveAsTiff(impO, outFile.getAbsolutePath())) ++failures;
12531252
}
12541253
}
12551254
if (failures > 0)

‎src/main/java/sc/fiji/snt/plugin/ShollAnalysisTreeCmd.java‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.scijava.app.StatusService;
3535
import org.scijava.command.Command;
3636
import org.scijava.command.CommandService;
37-
import org.scijava.display.Display;
3837
import org.scijava.menu.MenuConstants;
3938
import org.scijava.module.MutableModuleItem;
4039
import org.scijava.plugin.Menu;
@@ -226,11 +225,12 @@ public class ShollAnalysisTreeCmd extends CommonDynamicCmd {
226225
private Map<String, URL> luts;
227226
private Future<?> analysisFuture;
228227
private PreviewOverlay previewOverlay;
229-
private ShollTable commonSummaryTable;
230-
private Display<?> detailedTableDisplay;
231228
private boolean multipleTreesExist;
232229
private boolean noFocalPointSpecified;
233230

231+
/* Common summary table shared by all instances */
232+
private static volatile ShollTable commonSummaryTable;
233+
234234
/* Interactive runs: References to previous outputs */
235235
private ShollPlot lPlot;
236236
private ShollPlot nPlot;
@@ -809,30 +809,28 @@ else if (polynomialChoice.contains("degree") && polynomialDegree > 1) {
809809
final ShollTable dTable = (pStats==null)
810810
? new ShollTable(lStats, nStats) : new ShollTable(lStats, nStats, pStats);
811811
dTable.listProfileEntries();
812-
if (detailedTableDisplay != null) {
813-
detailedTableDisplay.close();
814-
}
815812
dTable.show("Sholl-Profiles");
816813
outputs.add(dTable);
817814
}
818815
if (tableOutputDescription.contains("Summary")) {
819816
final ShollTable sTable = (pStats==null)
820817
? new ShollTable(lStats, nStats) : new ShollTable(lStats, nStats, pStats);
821-
if (commonSummaryTable == null) {
822-
commonSummaryTable = new ShollTable();
823-
commonSummaryTable.setTitle(SUMMARY_TABLE_NAME);
824-
}
825-
String header;
826-
if (snt == null) {
827-
header = file.getName();
828-
}
829-
else {
830-
header = "Analysis " + (commonSummaryTable.getRowCount() + 1);
831-
sTable.setContext(snt.getContext());
818+
sTable.setContext(getContext());
819+
820+
synchronized (ShollAnalysisTreeCmd.class) { // thread safety
821+
if (commonSummaryTable == null) {
822+
commonSummaryTable = new ShollTable();
823+
commonSummaryTable.setTitle(SUMMARY_TABLE_NAME);
824+
}
825+
String header = (snt == null)
826+
? file.getName()
827+
: "Analysis " + (commonSummaryTable.getRowCount() + 1);
828+
if (!filterChoice.contains("None"))
829+
header += "(" + filterChoice + ")";
830+
sTable.summarize(commonSummaryTable, header);
831+
commonSummaryTable.createOrUpdateDisplay();
832832
}
833-
if (!filterChoice.contains("None")) header += "(" + filterChoice + ")";
834-
sTable.summarize(commonSummaryTable, header);
835-
commonSummaryTable.createOrUpdateDisplay();
833+
836834
}
837835

838836
if (snt != null && !"None".equalsIgnoreCase(annotationsDescription)) {

0 commit comments

Comments
 (0)