Skip to content

Commit 104773c

Browse files
committed
fix macro mode running in EDT
1 parent f763e7c commit 104773c

12 files changed

Lines changed: 221 additions & 126 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>nl.uu.science.cellbiology</groupId>
1313
<artifactId>bigtrace</artifactId>
14-
<version>0.8.3</version>
14+
<version>0.8.3-SNAPSHOT</version>
1515

1616
<name>BigTrace</name>
1717
<description>Tracing of curvilinear structures in 3D</description>

src/main/java/bigtrace/BigTrace.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public class BigTrace < T extends RealType< T > & NativeType< T > > implements P
115115
public VolumeViewerFrame bvvFrame;
116116

117117
/** flag to check if user interface is frozen.
118-
* It should be modified only in the main thread (or in done() of SwingWorker,
119-
* since when running in macro mode main thread becomes EDT => problems! **/
118+
* It should be modified only in the main thread (or in done method of SwingWorker,
119+
* since when running in macro mode main thread becomes EDT = problems! **/
120120
public volatile boolean bInputLock = false;
121121

122122
/** visualization of coordinates origin axes **/
@@ -173,8 +173,7 @@ public void run(String arg)
173173

174174
btData = new BigTraceData<>(this);
175175
btLoad = new BigTraceLoad<>(this);
176-
177-
176+
178177
if(arg.equals(""))
179178
{
180179
btData.sFileNameFullImg = IJ.getFilePath("Open TIF/BDV/Bioformats file (3D, composite, time)...");
@@ -228,25 +227,31 @@ public void run(String arg)
228227

229228
roiManager = new RoiManager3D<>(this);
230229

231-
initSourcesCanvas(0.25*Math.min(btData.nDimIni[1][0], Math.min(btData.nDimIni[1][1],btData.nDimIni[1][2])));
230+
initSourcesCanvas(0.25 * Math.min(btData.nDimIni[1][0], Math.min(btData.nDimIni[1][1],btData.nDimIni[1][2])));
231+
if(!btMacro.bMacroMode)
232+
{
233+
//not sure we really need it, but anyway
234+
javax.swing.SwingUtilities.invokeLater(new Runnable() {
235+
@Override
236+
public void run() {
237+
createAndShowGUI();
238+
}
239+
});
240+
}
241+
else
242+
{
243+
createAndShowGUI();
244+
}
232245

233-
//not sure we really need it, but anyway
234-
javax.swing.SwingUtilities.invokeLater(new Runnable() {
235-
@Override
236-
public void run() {
237-
createAndShowGUI();
238-
}
239-
});
240-
241246

242247
}
243248

244249
public void initOriginAndBox(double axis_length)
245250
{
246251
int i;
247252
//basis vectors
248-
RealPoint basis = new RealPoint(-0.1*axis_length, -0.1*axis_length,-0.1*axis_length);
249-
for(i=0;i<3;i++)
253+
RealPoint basis = new RealPoint(-0.1 * axis_length, -0.1 * axis_length,-0.1 * axis_length);
254+
for(i = 0; i < 3; i++)
250255
{
251256
ArrayList< RealPoint > point_coords = new ArrayList< >();
252257
point_coords.add(new RealPoint(basis));
@@ -262,7 +267,7 @@ public void initOriginAndBox(double axis_length)
262267

263268
float [][] nDimBox = new float [2][3];
264269

265-
for(i=0;i<3;i++)
270+
for(i = 0; i < 3; i++)
266271
{
267272
//why is this shift?! I don't know,
268273
// but looks better like this

src/main/java/bigtrace/BigTraceMacro.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ public void macroRunFullAutoTrace(final double dMinIntensity, final int nMinNumP
152152
{
153153
Thread.sleep(1000);
154154
}
155-
bt.bInputLock = true;
156-
155+
157156
int nFirstTP = 0;
158157
int nLastTP = 0;
159158

@@ -298,9 +297,7 @@ public void macroLoadROIs(String sFileName, String input) throws InterruptedExce
298297
{
299298
Thread.sleep(1000);
300299
}
301-
302-
bt.bInputLock = true;
303-
300+
304301
if(input == null)
305302
return;
306303
int nLoadMode = 0;
@@ -326,7 +323,7 @@ public void macroSaveROIs(String sFileName, String output) throws InterruptedExc
326323
{
327324
Thread.sleep(1000);
328325
}
329-
bt.bInputLock = true;
326+
330327
String out = "";
331328
if(output == null)
332329
{
@@ -361,13 +358,13 @@ void macroStraighten(final int nStraightenAxis, String sSaveDir, String sShape)
361358
{
362359
while(bt.bInputLock)
363360
{
364-
Thread.sleep(100);
361+
Thread.sleep(1000);
365362
}
366363

367364
//it should be later unlocked by StraightenCurve,
368365
//if we call it
369366
bt.bInputLock = true;
370-
367+
bt.setLockMode(true);
371368
//build list of ROIs
372369
final ArrayList<AbstractCurve3D> curvesOut = new ArrayList<>();
373370
IJ.log( "Total " + Integer.toString(bt.roiManager.rois.size()) +" ROIs" );
@@ -400,15 +397,15 @@ void macroStraighten(final int nStraightenAxis, String sSaveDir, String sShape)
400397
{
401398
StraightenCurve<T> straightBG = new StraightenCurve<>(curvesOut, bt, -1.0f, nAxis, nShape, 0, 1, sSaveDir);
402399
straightBG.addPropertyChangeListener(bt.btPanel);
403-
straightBG.execute();
400+
straightBG.runStraightenCurve();
404401
}
405402
else
406403
{
407404
IJ.log("Cannot find proper curve ROIs to straighten.");
408405
bt.btPanel.progressBar.setString("curve straightening aborted.");
409-
bt.bInputLock = false;
410406
}
411-
407+
bt.setLockMode(false);
408+
bt.bInputLock = false;
412409
}
413410

414411
public void macroShapeInterpolation(String sShapeInterpol, int nSmoothWindow) throws InterruptedException
@@ -446,7 +443,7 @@ void macroIntensityInterpolation(String sInterpol) throws InterruptedException
446443
{
447444
while(bt.bInputLock)
448445
{
449-
Thread.sleep(100);
446+
Thread.sleep(1000);
450447
}
451448
bt.bInputLock = true;
452449
switch (sInterpol)
@@ -476,7 +473,7 @@ void macroCloseBT() throws InterruptedException
476473
{
477474
while(bt.bInputLock)
478475
{
479-
Thread.sleep(100);
476+
Thread.sleep(1000);
480477
}
481478
bt.closeWindows();
482479
IJ.log("BigTrace closed.");

src/main/java/bigtrace/gui/PanelFullAutoTrace.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,17 @@ public void launchFullAutoTrace(final double dAutoMinStartTrace, final int nAuto
198198
butAuto.setToolTipText( "Stop auto trace" );
199199
fullAutoTrace.butAuto = butAuto;
200200
fullAutoTrace.tabIconRestore = tabIconAuto;
201-
fullAutoTrace.execute();
201+
if( !bt.btMacro.bMacroMode )
202+
{
203+
fullAutoTrace.execute();
204+
}
205+
else
206+
{
207+
fullAutoTrace.runFullAutoTrace();
208+
bt.setLockMode(true);
209+
bt.bInputLock = true;
210+
211+
}
202212
}
203213

204214
@Override

src/main/java/bigtrace/io/ROIsExportCSV.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ public String getProgressState()
3434
@Override
3535
public void setProgressState(String state_)
3636
{
37-
progressState=state_;
37+
progressState = state_;
3838
}
39-
39+
4040
@Override
41-
protected Void doInBackground() throws Exception {
42-
41+
protected Void doInBackground() throws Exception
42+
{
43+
runROIsExportCSV();
44+
return null;
45+
}
46+
47+
public void runROIsExportCSV()
48+
{
4349
int nRoi, nRoiN;
4450

4551
try {
@@ -61,13 +67,13 @@ protected Void doInBackground() throws Exception {
6167
String sRadius;
6268
int nRoiCurrN = 0;
6369
//writer.write("ROIsNumber," + Integer.toString(nRoiN)+"\n");
64-
for(nRoi=0; nRoi<nRoiN; nRoi++)
70+
for(nRoi = 0; nRoi < nRoiN; nRoi++)
6571
{
66-
//Sleep for up to one second.
72+
//Sleep for up to one second.
6773
try {
6874
Thread.sleep(1);
6975
} catch (InterruptedException ignore) {}
70-
setProgress(nRoi*100/nRoiN);
76+
setProgress(nRoi * 100 / nRoiN);
7177
if(bt.roiManager.rois.get( nRoi ) instanceof AbstractCurve3D)
7278
{
7379
nRoiCurrN++;
@@ -78,10 +84,10 @@ protected Void doInBackground() throws Exception {
7884
sRoiGroup = bt.roiManager.groups.get(currRoi.getGroupInd()).getName();
7985
sRadius = df3.format( currRoi.getLineThickness() * 0.5 * bt.btData.dMinVoxelSize);
8086
ArrayList< RealPoint > points = currRoi.getJointSegmentResampled();
81-
for(int nP=0; nP<points.size(); nP++)
87+
for(int nP = 0; nP < points.size(); nP++)
8288
{
8389
writer.write( Integer.toString( nRoiCurrN ) +"," );
84-
for (int d=0;d<3;d++)
90+
for (int d = 0; d < 3; d++)
8591
{
8692
writer.write( df3.format(points.get( nP ).getDoublePosition( d ) ) +"," );
8793
}
@@ -98,8 +104,10 @@ protected Void doInBackground() throws Exception {
98104
IJ.log(e.getMessage());
99105
//e.printStackTrace();
100106
}
101-
return null;
107+
return;
108+
102109
}
110+
103111
/*
104112
* Executed in event dispatching thread
105113
*/

src/main/java/bigtrace/io/ROIsExportSWC.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public void setProgressState(String state_)
3939

4040
@Override
4141
protected Void doInBackground() throws Exception
42+
{
43+
runROIsExportSWC();
44+
return null;
45+
}
46+
47+
public void runROIsExportSWC()
4248
{
4349
int nRoi, nRoiN;
4450

@@ -114,8 +120,10 @@ protected Void doInBackground() throws Exception
114120
IJ.log(e.getMessage());
115121
//e.printStackTrace();
116122
}
117-
return null;
123+
return;
124+
118125
}
126+
119127
/*
120128
* Executed in event dispatching thread
121129
*/

src/main/java/bigtrace/io/ROIsIO.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ public static <T extends RealType< T > & NativeType< T > > void loadROIs(String
2727
loadTask.nLoadMode = nLoadMode;
2828
loadTask.bt = bt;
2929
loadTask.addPropertyChangeListener(bt.btPanel);
30-
loadTask.execute();
30+
31+
if(!bt.btMacro.bMacroMode)
32+
{
33+
loadTask.execute();
34+
}
35+
else
36+
{
37+
loadTask.runROIsload();
38+
bt.setLockMode(false);
39+
bt.bInputLock = false;
40+
41+
}
3142
}
3243

3344
public static <T extends RealType< T > & NativeType< T > > void saveROIs(String fullFilename, final int nSaveMode, final BigTrace<T> bt)
@@ -43,22 +54,49 @@ public static <T extends RealType< T > & NativeType< T > > void saveROIs(String
4354
saveTask.sFilename = fullFilename;
4455
saveTask.bt = bt;
4556
saveTask.addPropertyChangeListener(bt.btPanel);
46-
saveTask.execute();
57+
if( !bt.btMacro.bMacroMode )
58+
{
59+
saveTask.execute();
60+
}
61+
else
62+
{
63+
saveTask.runROIsSave();
64+
}
4765
break;
4866
case 1:
4967
ROIsExportCSV<T> exportTask = new ROIsExportCSV<>();
5068
exportTask.sFilename = fullFilename;
5169
exportTask.bt = bt;
5270
exportTask.addPropertyChangeListener(bt.btPanel);
53-
exportTask.execute();
71+
if( !bt.btMacro.bMacroMode )
72+
{
73+
exportTask.execute();
74+
}
75+
else
76+
{
77+
exportTask.runROIsExportCSV();
78+
}
5479
break;
5580
case 2:
5681
ROIsExportSWC<T> exportSWCTask = new ROIsExportSWC<>();
5782
exportSWCTask.sFilename = fullFilename;
5883
exportSWCTask.bt = bt;
5984
exportSWCTask.addPropertyChangeListener(bt.btPanel);
60-
exportSWCTask.execute();
85+
if( !bt.btMacro.bMacroMode )
86+
{
87+
exportSWCTask.execute();
88+
}
89+
else
90+
{
91+
exportSWCTask.runROIsExportSWC();
92+
}
6193
break;
6294
}
95+
96+
if( bt.btMacro.bMacroMode )
97+
{
98+
bt.setLockMode(false);
99+
bt.bInputLock = false;
100+
}
63101
}
64102
}

0 commit comments

Comments
 (0)