Skip to content

Commit 50d30a1

Browse files
committed
Choice of dimension for next slice
1 parent 8b72d02 commit 50d30a1

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

Fiji.app/macros/toolsets/Roi 1-Click Tools.ijm

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* About the code:
1010
* - 1 macro Tool per click tool
1111
* - 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..)
1313
* - Update custom ROI and Help button are Action Tool
1414
* This code is under BSD-2 licence.
1515
* Author: Laurent Thomas
@@ -51,17 +51,32 @@ macro "Custom shortcut [1]" {
5151

5252
// ----------- Helper functions -----------------//
5353

54+
// Global variables
5455
var addToManager = true;
5556
var runMeasure = true;
56-
var nextSlice = true;
57+
var doNextSlice = true;
58+
var dimension = "time"; //default scrolling dimension for next-slice
5759
var doExtraCmd = false;
5860
var extraCmd = "run('Duplicate...', 'title=crop');";
5961
var leftButton = 16;
6062

6163
function goNextSlice(){
6264
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+
}
6478
}
79+
6580
function roiActions(){
6681
if (addToManager){
6782
roiManager("Associate", "true"); // associate ROI with slice (this does not set the Roi position though)
@@ -88,14 +103,19 @@ function addDefaultOption(){
88103
// Recover previous parameters
89104
addToManager = call("ij.Prefs.get", "default.addToManager", addToManager);
90105
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);
92108
doExtraCmd = call("ij.Prefs.get", "default.doExtraCmd", doExtraCmd);
93109
extraCmd = call("ij.Prefs.get", "default.extraCmd", extraCmd);
94110

95111
if (IJ.getFullVersion()>="1.52t") Dialog.addNumber("Current ROI group (or use keypad shortcut)", Roi.getDefaultGroup());
96112
Dialog.addCheckbox("Add to Roi Manager", addToManager);
97113
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+
99119
Dialog.addCheckbox("Run custom macro-commands", doExtraCmd);
100120
Dialog.addString("Custom macro-commands", extraCmd, 25);
101121

@@ -113,18 +133,20 @@ function getDefaultOptions(){
113133

114134
addToManager = Dialog.getCheckbox();
115135
runMeasure = Dialog.getCheckbox();
116-
nextSlice = Dialog.getCheckbox();
136+
doNextSlice = Dialog.getCheckbox();
137+
dimension = Dialog.getChoice();
117138
doExtraCmd = Dialog.getCheckbox();
118139
extraCmd = Dialog.getString();
119140

120141
call("ij.Prefs.set", "default.addToManager", addToManager);
121142
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);
123145
call("ij.Prefs.set", "default.doExtraCmd", doExtraCmd);
124146
call("ij.Prefs.set", "default.extraCmd", extraCmd);
125147
}
126148

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 */
128150
// Issue with stack and extra command crop : if NextSlice then crop, wrong
129151
function defaultActions(){
130152
if (nSlices>1){
@@ -147,7 +169,7 @@ function defaultActions(){
147169

148170
selectImage(imageName); // select back initial image, before calling next slice
149171

150-
goNextSlice(); // only if nextSlice is True
172+
if (doNextSlice) goNextSlice(); // only if doNextSlice is True
151173
//run("Select None"); // Deselect last drawn ROI - commented: if not adding to ROI Manager then ROI not visible at all !
152174

153175
}
@@ -198,7 +220,7 @@ macro "Line Click Tool Options" {
198220

199221
lineLength = Dialog.getNumber();
200222
lineAngle = Dialog.getNumber();
201-
getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
223+
getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
202224

203225
// Save entered value
204226
call("ij.Prefs.set", "line.length", lineLength);
@@ -233,7 +255,7 @@ macro "Circle Click Tool Options" {
233255
Dialog.show();
234256

235257
radius = Dialog.getNumber();
236-
getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
258+
getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
237259

238260
// Save typed value
239261
call("ij.Prefs.set", "circle.radius", radius);
@@ -347,7 +369,7 @@ macro "Rotated Rectangle Click Tool Options" {
347369
rotRectWidth = Dialog.getNumber();
348370
rotRectHeight = Dialog.getNumber();
349371
rotRectAngle = Dialog.getNumber();
350-
getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
372+
getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
351373

352374
// Save entered variables
353375
call("ij.Prefs.set", "rect.width", rotRectWidth);
@@ -401,7 +423,7 @@ macro "Ellipse Click Tool Options" {
401423
ellipseWidth = Dialog.getNumber();
402424
ellipseHeight = Dialog.getNumber();
403425
ellipseAngle = Dialog.getNumber();
404-
getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
426+
getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
405427

406428
// Save entered values
407429
call("ij.Prefs.set", "ellipse.width", ellipseWidth);
@@ -485,7 +507,7 @@ macro "Custom ROI Click Tool Options" {
485507
addDefaultOption();
486508
Dialog.show();
487509

488-
getDefaultOptions(); //Update the global variables addToManager, runMeasure, nextSlice
510+
getDefaultOptions(); //Update the global variables addToManager, runMeasure, doNextSlice
489511
}
490512

491513

0 commit comments

Comments
 (0)