9
9
* About the code:
10
10
* - 1 macro Tool per click tool
11
11
* - 1 associated Option macro (identical name) to set the tool options by right click
12
- * - Tools share common parameters define in get/addDefaultOptions (nextSlice , measure..)
12
+ * - Tools share common parameters define in get/addDefaultOptions (doNextSlice , measure..)
13
13
* - Update custom ROI and Help button are Action Tool
14
14
* This code is under BSD-2 licence.
15
15
* Author: Laurent Thomas
@@ -51,17 +51,32 @@ macro "Custom shortcut [1]" {
51
51
52
52
// ----------- Helper functions -----------------//
53
53
54
+ // Global variables
54
55
var addToManager = true;
55
56
var runMeasure = true;
56
- var nextSlice = true;
57
+ var doNextSlice = true;
58
+ var dimension = "time"; //default scrolling dimension for next-slice
57
59
var doExtraCmd = false;
58
60
var extraCmd = "run('Duplicate...', 'title=crop');";
59
61
var leftButton = 16;
60
62
61
63
function goNextSlice(){
62
64
Stack.getDimensions(stackWidth, stackHeight, channels, slices, frames);
63
- if ((slices>1) && (nextSlice)) run("Next Slice [>]");
65
+
66
+ if (slices>1) {
67
+
68
+ if (Stack.isHyperstack){
69
+ Stack.getPosition(channel, slice, frame);
70
+
71
+ // Update slide position accordingly (no issue if new value above mex slider position)
72
+ if (dimension=="time") Stack.setFrame(frame+1);
73
+ else if (dimension=="channel") Stack.setChannel(channel+1);
74
+ else if (dimension=="Z-slice") Stack.setSlice(slice+1);
75
+ }
76
+ else run("Next Slice [>]"); // for 1D stack
77
+ }
64
78
}
79
+
65
80
function roiActions(){
66
81
if (addToManager){
67
82
roiManager("Associate", "true"); // associate ROI with slice (this does not set the Roi position though)
@@ -88,14 +103,19 @@ function addDefaultOption(){
88
103
// Recover previous parameters
89
104
addToManager = call("ij.Prefs.get", "default.addToManager", addToManager);
90
105
runMeasure = call("ij.Prefs.get", "default.runMeasure", runMeasure);
91
- nextSlice = call("ij.Prefs.get", "default.nextSlice", nextSlice);
106
+ doNextSlice = call("ij.Prefs.get", "default.doNextSlice", doNextSlice);
107
+ dimension = call("ij.Prefs.get", "default.dimension", dimension);
92
108
doExtraCmd = call("ij.Prefs.get", "default.doExtraCmd", doExtraCmd);
93
109
extraCmd = call("ij.Prefs.get", "default.extraCmd", extraCmd);
94
110
95
111
if (IJ.getFullVersion()>="1.52t") Dialog.addNumber("Current ROI group (or use keypad shortcut)", Roi.getDefaultGroup());
96
112
Dialog.addCheckbox("Add to Roi Manager", addToManager);
97
113
Dialog.addCheckbox("Run measure", runMeasure );
98
- Dialog.addCheckbox("Auto-Next slice", nextSlice);
114
+
115
+ Dialog.addCheckbox("Auto-Next slice", doNextSlice);
116
+ Dialog.addToSameRow();
117
+ Dialog.addChoice("Dimension (for hyperstacks)", newArray("time","channel","Z-slice"), dimension );
118
+
99
119
Dialog.addCheckbox("Run custom macro-commands", doExtraCmd);
100
120
Dialog.addString("Custom macro-commands", extraCmd, 25);
101
121
@@ -113,18 +133,20 @@ function getDefaultOptions(){
113
133
114
134
addToManager = Dialog.getCheckbox();
115
135
runMeasure = Dialog.getCheckbox();
116
- nextSlice = Dialog.getCheckbox();
136
+ doNextSlice = Dialog.getCheckbox();
137
+ dimension = Dialog.getChoice();
117
138
doExtraCmd = Dialog.getCheckbox();
118
139
extraCmd = Dialog.getString();
119
140
120
141
call("ij.Prefs.set", "default.addToManager", addToManager);
121
142
call("ij.Prefs.set", "default.runMeasure", runMeasure);
122
- call("ij.Prefs.set", "default.nextSlice", nextSlice);
143
+ call("ij.Prefs.set", "default.doNextSlice", doNextSlice);
144
+ call("ij.Prefs.set", "default.dimension", dimension);
123
145
call("ij.Prefs.set", "default.doExtraCmd", doExtraCmd);
124
146
call("ij.Prefs.set", "default.extraCmd", extraCmd);
125
147
}
126
148
127
- /* Default actions, in this order: AddToManager, runMeasure, nextSlice , customAction and select None */
149
+ /* Default actions, in this order: AddToManager, runMeasure, doNextSlice , customAction and select None */
128
150
// Issue with stack and extra command crop : if NextSlice then crop, wrong
129
151
function defaultActions(){
130
152
if (nSlices>1){
@@ -147,7 +169,7 @@ function defaultActions(){
147
169
148
170
selectImage(imageName); // select back initial image, before calling next slice
149
171
150
- goNextSlice(); // only if nextSlice is True
172
+ if (doNextSlice) goNextSlice(); // only if doNextSlice is True
151
173
//run("Select None"); // Deselect last drawn ROI - commented: if not adding to ROI Manager then ROI not visible at all !
152
174
153
175
}
@@ -198,7 +220,7 @@ macro "Line Click Tool Options" {
198
220
199
221
lineLength = Dialog.getNumber();
200
222
lineAngle = Dialog.getNumber();
201
- getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
223
+ getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
202
224
203
225
// Save entered value
204
226
call("ij.Prefs.set", "line.length", lineLength);
@@ -233,7 +255,7 @@ macro "Circle Click Tool Options" {
233
255
Dialog.show();
234
256
235
257
radius = Dialog.getNumber();
236
- getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
258
+ getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
237
259
238
260
// Save typed value
239
261
call("ij.Prefs.set", "circle.radius", radius);
@@ -347,7 +369,7 @@ macro "Rotated Rectangle Click Tool Options" {
347
369
rotRectWidth = Dialog.getNumber();
348
370
rotRectHeight = Dialog.getNumber();
349
371
rotRectAngle = Dialog.getNumber();
350
- getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
372
+ getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
351
373
352
374
// Save entered variables
353
375
call("ij.Prefs.set", "rect.width", rotRectWidth);
@@ -401,7 +423,7 @@ macro "Ellipse Click Tool Options" {
401
423
ellipseWidth = Dialog.getNumber();
402
424
ellipseHeight = Dialog.getNumber();
403
425
ellipseAngle = Dialog.getNumber();
404
- getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
426
+ getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
405
427
406
428
// Save entered values
407
429
call("ij.Prefs.set", "ellipse.width", ellipseWidth);
@@ -485,7 +507,7 @@ macro "Custom ROI Click Tool Options" {
485
507
addDefaultOption();
486
508
Dialog.show();
487
509
488
- getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
510
+ getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
489
511
}
490
512
491
513
0 commit comments