Skip to content

Commit 7dbc577

Browse files
committed
fix autotrace macro call, no thread sleep, misc
1 parent 2bc6d3f commit 7dbc577

5 files changed

Lines changed: 103 additions & 167 deletions

File tree

src/main/java/bigtrace/BigTrace.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,17 @@ public void windowClosing( WindowEvent ev )
341341
bInputLock = false;
342342

343343
//check if there is a saved view
344-
File f = new File(btData.sFileNameFullImg+"_btview.csv");
344+
File f = new File(btData.sFileNameFullImg + "_btview.csv");
345345

346346
if(f.exists() && !f.isDirectory() && !btMacro.bMacroMode)
347347
{
348348
if (JOptionPane.showConfirmDialog(null, "There is a saved view state for this file,\ndo you want to load it?", "Load saved view?",
349349
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
350350
{
351-
ViewsIO.loadView( this, btData.sFileNameFullImg+"_btview.csv" );
351+
ViewsIO.loadView( this, btData.sFileNameFullImg + "_btview.csv" );
352352
}
353353
}
354+
354355
if(btData.bStartFullScreen)
355356
{
356357
btPanel.makeFullScreen();

src/main/java/bigtrace/BigTraceMacro.java

Lines changed: 78 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -59,100 +59,88 @@ public BigTraceMacro(final BigTrace<T> bt_)
5959

6060
public String handleExtension(String name, Object[] args)
6161
{
62-
try
62+
63+
if (name.equals("btLoadROIs"))
6364
{
64-
if (name.equals("btLoadROIs"))
65-
{
66-
macroLoadROIs( (String)args[0],(String)args[1]);
67-
}
68-
if (name.equals("btSaveROIs"))
69-
{
70-
macroSaveROIs( (String)args[0],(String)args[1]);
71-
}
72-
if (name.equals("btStraighten"))
73-
{
74-
if(args[2] == null)
75-
{
76-
//backwards compartibility
77-
macroStraighten((int)Math.round(((Double)args[0]).doubleValue()), (String)args[1], "Square");
78-
}
79-
else
80-
{
81-
macroStraighten((int)Math.round(((Double)args[0]).doubleValue()), (String)args[1], (String)args[2]);
82-
}
83-
}
84-
if (name.equals("btShapeInterpolation"))
85-
{
86-
macroShapeInterpolation( (String)args[0],(int)Math.round(((Double)args[1]).doubleValue()));
87-
}
88-
if (name.equals("btIntensityInterpolation"))
89-
{
90-
macroIntensityInterpolation( (String)args[0]);
91-
}
92-
if (name.equals("btSetActiveChannel"))
65+
macroLoadROIs( (String)args[0],(String)args[1]);
66+
}
67+
if (name.equals("btSaveROIs"))
68+
{
69+
macroSaveROIs( (String)args[0],(String)args[1]);
70+
}
71+
if (name.equals("btStraighten"))
72+
{
73+
if(args[2] == null)
9374
{
94-
macroSetActiveChannel( (int) Math.abs(Math.round(((Double)args[0]).doubleValue())));
75+
//backwards compartibility
76+
macroStraighten((int)Math.round(((Double)args[0]).doubleValue()), (String)args[1], "Square");
9577
}
96-
if (name.equals("btSetTracingThickness"))
78+
else
9779
{
98-
final double [] sigmas = new double[3];
99-
for(int d=0; d<3; d++)
100-
{
101-
sigmas[d] = Math.abs(((Double)args[d]).doubleValue());
102-
}
103-
104-
macroSetTracingThickness(sigmas);
105-
80+
macroStraighten((int)Math.round(((Double)args[0]).doubleValue()), (String)args[1], (String)args[2]);
10681
}
107-
if (name.equals("btSetTracingROI"))
82+
}
83+
if (name.equals("btShapeInterpolation"))
84+
{
85+
macroShapeInterpolation( (String)args[0],(int)Math.round(((Double)args[1]).doubleValue()));
86+
}
87+
if (name.equals("btIntensityInterpolation"))
88+
{
89+
macroIntensityInterpolation( (String)args[0]);
90+
}
91+
if (name.equals("btSetActiveChannel"))
92+
{
93+
macroSetActiveChannel( (int) Math.abs(Math.round(((Double)args[0]).doubleValue())));
94+
}
95+
if (name.equals("btSetTracingThickness"))
96+
{
97+
final double [] sigmas = new double[3];
98+
for(int d=0; d<3; d++)
10899
{
109-
macroSetTracingROI((String)args[0],Math.abs(((Double)args[1]).doubleValue()), (String)args[2]);
100+
sigmas[d] = Math.abs(((Double)args[d]).doubleValue());
110101
}
111-
if (name.equals("btSetOneClickParameters"))
112-
{
113-
if(args[2] == null || args[3] == null)
114-
{
115-
macroSetOneClickParameters((int)Math.round(((Double)args[0]).doubleValue()), ((Double)args[1]).doubleValue(), "false", 0.0);
116-
return null;
117-
}
118102

119-
macroSetOneClickParameters((int)Math.round(((Double)args[0]).doubleValue()), ((Double)args[1]).doubleValue(), (String)args[2],((Double)args[3]).doubleValue() );
120-
}
121-
122-
if (name.equals("btRunFullAutoTrace"))
103+
macroSetTracingThickness(sigmas);
104+
105+
}
106+
if (name.equals("btSetTracingROI"))
107+
{
108+
macroSetTracingROI((String)args[0],Math.abs(((Double)args[1]).doubleValue()), (String)args[2]);
109+
}
110+
if (name.equals("btSetOneClickParameters"))
111+
{
112+
if(args[2] == null || args[3] == null)
123113
{
124-
int nFirstTP = 0;
125-
int nLastTP = bt.btData.nNumTimepoints - 1;
126-
if(args[2] != null && args[3] != null )
127-
{
128-
nFirstTP = (int)Math.round(((Double)args[2]).doubleValue());
129-
nLastTP = (int)Math.round(((Double)args[3]).doubleValue());
130-
}
131-
macroRunFullAutoTrace(((Double)args[0]).doubleValue(),(int)Math.round(((Double)args[1]).doubleValue()),nFirstTP,nLastTP);
114+
macroSetOneClickParameters((int)Math.round(((Double)args[0]).doubleValue()), ((Double)args[1]).doubleValue(), "false", 0.0);
115+
return null;
132116
}
133-
if (name.equals("btClose"))
117+
118+
macroSetOneClickParameters((int)Math.round(((Double)args[0]).doubleValue()), ((Double)args[1]).doubleValue(), (String)args[2],((Double)args[3]).doubleValue() );
119+
}
120+
121+
if (name.equals("btRunFullAutoTrace"))
122+
{
123+
int nFirstTP = 0;
124+
int nLastTP = bt.btData.nNumTimepoints - 1;
125+
if(args[2] != null && args[3] != null )
134126
{
135-
macroCloseBT();
127+
nFirstTP = (int)Math.round(((Double)args[2]).doubleValue());
128+
nLastTP = (int)Math.round(((Double)args[3]).doubleValue());
136129
}
137-
if (name.equals("btTest"))
138-
{
139-
macroTest();
140-
}
130+
macroRunFullAutoTrace(((Double)args[0]).doubleValue(),(int)Math.round(((Double)args[1]).doubleValue()),nFirstTP,nLastTP);
141131
}
142-
catch ( InterruptedException exc )
132+
133+
if (name.equals("btClose"))
143134
{
144-
exc.printStackTrace();
135+
macroCloseBT();
145136
}
137+
146138
return null;
147139
}
148140

149-
public void macroRunFullAutoTrace(final double dMinIntensity, final int nMinNumPoints, final int nFirstFrame, final int nLastFrame) throws InterruptedException
141+
public void macroRunFullAutoTrace(final double dMinIntensity, final int nMinNumPoints, final int nFirstFrame, final int nLastFrame)
150142
{
151-
while(bt.bInputLock)
152-
{
153-
Thread.sleep(1000);
154-
}
155-
143+
156144
int nFirstTP = 0;
157145
int nLastTP = 0;
158146

@@ -172,12 +160,8 @@ public void macroRunFullAutoTrace(final double dMinIntensity, final int nMinNumP
172160
bt.roiManager.panelFullAutoTrace.launchFullAutoTrace( dMinIntensity, nMinNumPoints, nFirstFrame, nLastFrame );
173161
}
174162

175-
public void macroSetTracingThickness(final double [] sigmas) throws InterruptedException
163+
public void macroSetTracingThickness(final double [] sigmas)
176164
{
177-
while(bt.bInputLock)
178-
{
179-
Thread.sleep(1000);
180-
}
181165
bt.bInputLock = true;
182166
String [] axes = new String[] {"X","Y","Z"};
183167
IJ.log( "Setting tracing thickness:" );
@@ -193,12 +177,8 @@ public void macroSetTracingThickness(final double [] sigmas) throws InterruptedE
193177

194178
}
195179

196-
public void macroSetActiveChannel (final int nChannel) throws InterruptedException
180+
public void macroSetActiveChannel (final int nChannel)
197181
{
198-
while(bt.bInputLock)
199-
{
200-
Thread.sleep(1000);
201-
}
202182
bt.bInputLock = true;
203183
int nFinCh = Math.max(nChannel,1);
204184
nFinCh = Math.min( nFinCh, bt.btData.nTotalChannels );
@@ -207,12 +187,8 @@ public void macroSetActiveChannel (final int nChannel) throws InterruptedExcepti
207187
bt.bInputLock = false;
208188
}
209189

210-
public void macroSetTracingROI(String sEnable, final double coeff, String sMethod) throws InterruptedException
190+
public void macroSetTracingROI(String sEnable, final double coeff, String sMethod)
211191
{
212-
while(bt.bInputLock)
213-
{
214-
Thread.sleep(1000);
215-
}
216192
bt.bInputLock = true;
217193
IJ.log( "Setting ROI thickness from tracing parameters: " );
218194
bt.btData.bEstimateROIThicknessFromParams = false;
@@ -255,12 +231,8 @@ public void macroSetTracingROI(String sEnable, final double coeff, String sMetho
255231
bt.bInputLock = false;
256232
}
257233

258-
public void macroSetOneClickParameters(int nVertexPlacementPointN, double dDirectionalityOneClick, String sOCIntensityStop, double dOCIntensityThreshold) throws InterruptedException
234+
public void macroSetOneClickParameters(int nVertexPlacementPointN, double dDirectionalityOneClick, String sOCIntensityStop, double dOCIntensityThreshold)
259235
{
260-
while(bt.bInputLock)
261-
{
262-
Thread.sleep(1000);
263-
}
264236
bt.bInputLock = true;
265237
IJ.log( "Setting one-click tracing parameters:" );
266238

@@ -291,13 +263,9 @@ public void macroSetOneClickParameters(int nVertexPlacementPointN, double dDirec
291263
bt.bInputLock = false;
292264
}
293265

294-
public void macroLoadROIs(String sFileName, String input) throws InterruptedException
266+
public void macroLoadROIs(String sFileName, String input)
295267
{
296-
while(bt.bInputLock)
297-
{
298-
Thread.sleep(1000);
299-
}
300-
268+
301269
if(input == null)
302270
return;
303271
int nLoadMode = 0;
@@ -317,13 +285,9 @@ public void macroLoadROIs(String sFileName, String input) throws InterruptedExce
317285
IJ.log( "BigTrace ROIs loaded from " + sFileName);
318286
}
319287

320-
public void macroSaveROIs(String sFileName, String output) throws InterruptedException
288+
public void macroSaveROIs(String sFileName, String output)
321289
{
322-
while(bt.bInputLock)
323-
{
324-
Thread.sleep(1000);
325-
}
326-
290+
327291
String out = "";
328292
if(output == null)
329293
{
@@ -354,13 +318,8 @@ public void macroSaveROIs(String sFileName, String output) throws InterruptedExc
354318
IJ.log( "BigTrace ROIs saved to " + sFileName);
355319
}
356320

357-
void macroStraighten(final int nStraightenAxis, String sSaveDir, String sShape) throws InterruptedException
358-
{
359-
while(bt.bInputLock)
360-
{
361-
Thread.sleep(1000);
362-
}
363-
321+
void macroStraighten(final int nStraightenAxis, String sSaveDir, String sShape)
322+
{
364323
//it should be later unlocked by StraightenCurve,
365324
//if we call it
366325
bt.bInputLock = true;
@@ -408,12 +367,8 @@ void macroStraighten(final int nStraightenAxis, String sSaveDir, String sShape)
408367
bt.bInputLock = false;
409368
}
410369

411-
public void macroShapeInterpolation(String sShapeInterpol, int nSmoothWindow) throws InterruptedException
370+
public void macroShapeInterpolation(String sShapeInterpol, int nSmoothWindow)
412371
{
413-
while(bt.bInputLock)
414-
{
415-
Thread.sleep(100);
416-
}
417372
bt.bInputLock = true;
418373
switch (sShapeInterpol)
419374
{
@@ -439,12 +394,9 @@ public void macroShapeInterpolation(String sShapeInterpol, int nSmoothWindow) th
439394
bt.bInputLock = false;
440395
}
441396

442-
void macroIntensityInterpolation(String sInterpol) throws InterruptedException
397+
void macroIntensityInterpolation(String sInterpol)
443398
{
444-
while(bt.bInputLock)
445-
{
446-
Thread.sleep(1000);
447-
}
399+
448400
bt.bInputLock = true;
449401
switch (sInterpol)
450402
{
@@ -469,29 +421,13 @@ void macroIntensityInterpolation(String sInterpol) throws InterruptedException
469421
}
470422

471423

472-
void macroCloseBT() throws InterruptedException
424+
void macroCloseBT()
473425
{
474-
while(bt.bInputLock)
475-
{
476-
Thread.sleep(1000);
477-
}
426+
478427
bt.closeWindows();
479428
IJ.log("BigTrace closed.");
480429
}
481430

482-
void macroTest() throws InterruptedException
483-
{
484-
while(bt.bInputLock)
485-
{
486-
IJ.log( "not unlocked" );
487-
Thread.sleep(100);
488-
}
489-
IJ.log( "unlocked" );
490-
bt.resetViewXY();
491-
IJ.log("test ok right away");
492-
493-
}
494-
495431
@SuppressWarnings({ "rawtypes", "unchecked" })
496432
public static void main(String... args) throws Exception
497433
{

src/main/java/bigtrace/animation/AnimationPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ public void mouseClicked(MouseEvent evt) {
347347
JPanel panTotTime = new JPanel(new GridBagLayout());
348348
panTotTime.setBorder(new PanelTitle(""));
349349
cr = new GridBagConstraints();
350-
cr.gridx=0;
351-
cr.gridy=0;
350+
cr.gridx = 0;
351+
cr.gridy = 0;
352352
panTotTime.add(new JLabel("Total time (s)"),cr);
353353
cr.gridx++;
354354
nfTotalTime = new NumberField(4);

0 commit comments

Comments
 (0)