-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.js
334 lines (251 loc) · 12.4 KB
/
control.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
================== qMRLab vfa_t1 pulse sequence =
This is the controller script which is responsible for
passing the variables between the GUI (control.ui) and
RTHawk's sequencing engine.
Waveforms exported by SpinBench and described by application.apd
determine the initial state of the sequence. For this
application, initial parameters are fetched from:
- [excitation] SincRF + Z (SlabSelect.spv)
- [echodelay] in us, to be exposed to GUI. (Not linked to a file)
- [readout] 3D Cartesian Readout (CartesianReadout3D.spv)
- [spoiler] Area Trapezoid (SpoilerGradient.spv)
Author: Agah Karakuzu [email protected]
Created: October, 2019.
// =================================================
*/
// Get sequence ID
var sequenceId = rth.sequenceId();
// Fetch initial parameters described in CartesianReadout3D.spv
var xPixels = SB.readout["<Cartesian Readout>.xRes"]; // Number of samples, no need for this, acquisition emits this.
var phaseEncodes = SB.readout["<Cartesian Readout>.yRes"]; // Number of repeats
var zPartitions = SB.readout["<Phase Encode Gradient>.res"]; // Number of partitions (has attr fov as well)
// These values are changed in the SB only.
rth.addCommand(new RthUpdateChangeReconstructionParameterCommand(sequenceId, {
phaseEncodes: phaseEncodes,
zPartitions: zPartitions
}));
// Get the sequence parameters from the sequencer.
var scannerParameters = new RthUpdateGetParametersCommand(sequenceId);
rth.addCommand(scannerParameters);
var parameterList = scannerParameters.receivedData();
var instanceName = rth.instanceName();
rth.addSeriesDescription(instanceName);
rth.informationInsert(sequenceId, "mri.SequenceName", "qMRLab " + instanceName);
rth.informationInsert(sequenceId, "mri.ScanningSequence", "GR");
rth.informationInsert(sequenceId, "mri.SequenceVariant", "SS, SP");
rth.informationInsert(sequenceId, "mri.ScanOptions", "");
rth.informationInsert(sequenceId, "mri.MRAcquisitionType", "3D");
rth.informationInsert(sequenceId, "mri.NumberOfAverages", 1);
rth.informationInsert(sequenceId, "mri.NumberOfCoils", parameterList[2]);
rth.informationInsert(sequenceId, "mri.EchoTrainLength", 1);
rth.informationInsert(sequenceId,"mri.ExcitationTimeBandwidth",SB.excitation["<Sinc RF>.timeBandwidth"]);
rth.informationInsert(sequenceId,"mri.ExcitationDuration",SB.excitation["<Sinc RF>.duration"]);
rth.informationInsert(sequenceId,"mri.ExcitationType","Sinc Hamming");
// Get minimum TR
var scannerTR = new RthUpdateGetTRCommand(sequenceId, [], []);
rth.addCommand(scannerTR);
var minTR = scannerTR.tr();
var startingTR = minTR;
RTHLOGGER_WARNING("Minimum TR: " + minTR);
// Starting FOV also depends on CartesianReadout3D.spv
// In SpinBench, FOV is defined in cm. xFOV = yFOV always.
var startingFOV = SB.readout["<Cartesian Readout>.fov"]; // cm
var startingZFOV = SB.readout["<Phase Encode Gradient>.fov"]; //cm
// Slice thickness depends on SlabSelect.spv
// In SpinBench, SliceThickness is defined in mm.
// RF pulse is associated with the gradient. Changes in SSG updates RF as well.
var startingThickness = SB.excitation["<Slice Select Gradient>.thickness"]; // mm
// Insert metadata
rth.informationInsert(sequenceId,"mri.SliceThickness",startingThickness);
var startingResolution = startingFOV/xPixels* 10; // mm
rth.informationInsert(sequenceId,"mri.VoxelSpacing",[startingResolution*10,startingResolution*10,startingZFOV/zPartitions*10]);
// Specify TE delay interval
var minTE = SB.excitation['<Sinc RF>.end'] - SB.excitation['<Sinc RF>.peak'] + SB.readout['<Cartesian Readout>.readoutCenter'];
var startingTE = minTE + rth.apdKey("echodelay/duration")/1000; //ms
rth.informationInsert(sequenceId,"mri.EchoTime",startingTE);
// Assume FA from SB as the smaller.
var startingFA2 = SB.excitation["<Sinc RF>.tip"]; //20
// FA should be in decreasing order (FA1 > FA2)
var startingFA1 = startingFA2 - 17;
// To store the current values
var sliceThickness = startingThickness;
var fieldOfView = startingFOV;
//FIXME: This is temporary. Fix the order
var flipAngle1 = startingFA2;
var flipAngle2 = startingFA1;
var echoTime = startingTE;
var repetitionTime = startingTR;
// Import display tool
rth.importJS("lib:RthDisplayThreePlaneTools.js");
var displayTools = new RthDisplayThreePlaneTools();
// Change functions
function changeFOV(fov){
if (fov<startingFOV) fov = startingFOV;
var scale = startingFOV/fov;
// Scale gradients (x,y,z) assuming in-plane isometry
rth.addCommand(new RthUpdateScaleGradientsCommand(sequenceId,"readout",scale,scale, startingThickness/sliceThickness));
// Waveforms are not affected by the below:
rth.addCommand(new RthUpdateChangeResolutionCommand(sequenceId,startingResolution/scale));
rth.addCommand(new RthUpdateChangeFieldOfViewCommand(sequenceId, fov*10,fov*10,startingThickness));
// Annotation
displayTools.setFOV(fov * 10);
//displayTool.setResolution(startingResolution/scale,startingResolution/scale);
// Update
fieldOfView = fov;
}
function changeSliceThickness(thickness){
if (thickness < startingThickness) thickness = startingThickness;
// Scale SS gradient
// The scaling is always performed with respect to the STARTING VALUE (1). Factors must be always smaller than 1.
rth.addCommand(new RthUpdateFloatParameterCommand(sequenceId,"excitation","scaleGradients","",startingThickness/thickness));
// If the slice thickness is increased, so should the zFOV (by scaling down z-grad)
rth.addCommand(new RthUpdateScaleGradientsCommand(sequenceId,"readout",startingFOV/fieldOfView,startingFOV/fieldOfView,startingThickness/thickness));
// Update slice prescription UI tools (the green lines in the UI)
displayTools.setSliceThickness(thickness);
// Update metadata.
rth.informationInsert(sequenceId,"mri.SliceThickness",thickness);
rth.addCommand(new RthUpdateChangeFieldOfViewCommand(sequenceId, fieldOfView*10,fieldOfView*10,thickness));
rth.addCommand(new RthUpdateChangeSliceThicknessCommand(sequenceId, thickness));
// zFOV is not equal to the slice thickness, it has a padding of 10mm. Not sure why, but this
// was the convention in other 3D waveforms I saw, so I followed.
rth.informationInsert(sequenceId,"mri.VoxelSpacing",[fieldOfView/xPixels*10,fieldOfView/phaseEncodes*10,(startingZFOV*thickness/startingThickness)/zPartitions*10]);
sliceThickness = thickness;
}
function changeTR(tr) {
if (tr < minTR) {
tr = minTR;
}
// TR is a generic integer parameter, so to be updated by RthUpdateIntParameterCommand
// Method name is given by "setDesiredTR", defined in microseconds!
var value = tr * 1000; // Convert from milisec to microsec
var trCommand = new RthUpdateIntParameterCommand(sequenceId, "", "setDesiredTR", "", value);
rth.addCommand(trCommand);
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "RepetitionTime", tr));
repetitionTime = tr;
}
function changeFlipAngle1(angle1) {
//var flipCommand = RthUpdateFloatParameterCommand(sequenceId, "sequence", "scaleRF", "", angle / startingFA1);
//rth.addCommand(flipCommand);
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "FlipAngle1", angle1));
flipAngle1 = angle1;
}
function changeFlipAngle2(angle2){
// Just referencing global var here.
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "FlipAngle2", angle2));
flipAngle2 = angle2;
}
function changeTE(te)
{
rth.informationInsert(sequenceId,"mri.EchoTime",te);
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "EchoTime", te));
var echoDelay = (te - minTE) * 1000; // Convert to usec
rth.addCommand(new RthUpdateIntParameterCommand(sequenceId, "echodelay", "setDelay", "", echoDelay));
}
/* Define UI element settings and link outputs from change events to the respective vars
inputWidget_FOV (Done)
inputWidget_SliceThickness (Done)
inputWidget_FA1 (Done)
inputWidget_FA2 (Done)
inputWidget_TR (Done)
*/
// Send metadata to recon
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
ExcitationTimeBandwidth: SB.excitation["<Sinc RF>.timeBandwidth"],
ExcitationDuration: SB.excitation["<Sinc RF>.duration"],
NumberOfCoils: parameterList[2],
PreAcqDuration: SB.readout["<Preacquisitions>.duration"]
}));
controlWidget.inputWidget_SliceThickness.minimum = startingThickness;
controlWidget.inputWidget_SliceThickness.maximum = startingThickness*2;
controlWidget.inputWidget_SliceThickness.value = startingThickness;
controlWidget.inputWidget_FOV.minimum = startingFOV;
controlWidget.inputWidget_FOV.maximum = startingFOV*2;
controlWidget.inputWidget_FOV.value = startingFOV;
controlWidget.inputWidget_TR.minimum = minTR;
controlWidget.inputWidget_TR.maximum = minTR + 30;
controlWidget.inputWidget_TR.value = minTR;
//FIXME: FA param names
controlWidget.inputWidget_FA1.minimum = startingFA1;
controlWidget.inputWidget_FA1.maximum = 90;
controlWidget.inputWidget_FA1.value = startingFA2;
//FIXME: FA param names
controlWidget.inputWidget_FA2.minimum = startingFA1;
controlWidget.inputWidget_FA2.maximum = startingFA1+5;
controlWidget.inputWidget_FA2.value = startingFA1;
controlWidget.inputWidget_TE.minimum = minTE;
controlWidget.inputWidget_TE.maximum = 8;
controlWidget.inputWidget_TE.value = 5;
function sessionClicked(chck){
if (chck){
controlWidget.sessionBIDS.enabled = true;
controlWidget.sessionBIDS.setText("00");
}else{
controlWidget.sessionBIDS.enabled = false;
controlWidget.sessionBIDS.text = "";
controlWidget.sessionBIDS.placeholderText = "_ses-<index>";
}
}
function acqClicked(chck){
if (chck){
controlWidget.acqBIDS.enabled = true;
controlWidget.acqBIDS.setText("freeform");
}else{
controlWidget.acqBIDS.enabled = false;
controlWidget.acqBIDS.text = "";
controlWidget.acqBIDS.placeholderText = "_acq-<label>";
}
}
var acqLabel = "";
function acqTextChanged(txt){
acqLabel = txt;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,"AcquisitionBIDS",acqLabel));
}
var sesIndex = "";
function sesTextChanged(txt){
sesIndex = txt;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,"SessionBIDS",sesIndex));
}
var subIndex = "";
function subTextChanged(txt){
subIndex = txt;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,"SubjectBIDS",subIndex));
}
// Connect UI elements to the callback functions.
controlWidget.acqBIDS.textChanged.connect(acqTextChanged);
acqTextChanged(controlWidget.acqBIDS.text);
controlWidget.sessionBIDS.textChanged.connect(sesTextChanged);
sesTextChanged(controlWidget.sessionBIDS.text);
controlWidget.subjectBIDS.textChanged.connect(subTextChanged);
subTextChanged(controlWidget.subjectBIDS.text);
controlWidget.isSessionBIDS.toggled.connect(sessionClicked);
sessionClicked(controlWidget.isSessionBIDS.checked)
controlWidget.isAcqBIDS.toggled.connect(acqClicked);
acqClicked(controlWidget.isAcqBIDS.checked)
controlWidget.inputWidget_FOV.valueChanged.connect(changeFOV);
changeFOV(controlWidget.inputWidget_FOV.value);
controlWidget.inputWidget_TR.valueChanged.connect(changeTR);
changeTR(controlWidget.inputWidget_TR.value);
controlWidget.inputWidget_FA1.valueChanged.connect(changeFlipAngle1);
changeFlipAngle1(controlWidget.inputWidget_FA1.value);
controlWidget.inputWidget_FA2.valueChanged.connect(changeFlipAngle2);
changeFlipAngle2(controlWidget.inputWidget_FA2.value);
controlWidget.inputWidget_TE.valueChanged.connect(changeTE);
changeTE(controlWidget.inputWidget_TE.value);
controlWidget.inputWidget_SliceThickness.valueChanged.connect(changeSliceThickness);
changeSliceThickness(controlWidget.inputWidget_SliceThickness.value);
// ADD LOOP COMMANDS
//var bigAngleCommand = new RthUpdateFloatParameterCommand(sequenceId, "excitation", "scaleRF", "", 1);
// Following sets FlipAngle to 3 when FA1 = 30 and FA2=25
//var smallAngleCommand = new RthUpdateFloatParameterCommand(sequenceId, "excitation", "scaleRF", "", flipAngle2/flipAngle1);
//rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
// SubjectBIDS: controlWidget.subjectBIDS.text,
// SessionBIDS: controlWidget.sessionBIDS.text,
// AcquisitionBIDS: controlWidget.acqBIDS.text
//}));
//var infoCommand1 = new RthUpdateChangeMRIParameterCommand(sequenceId,{FlipAngle: flipAngle1, FlipIndex: "01"});
//var infoCommand2 = new RthUpdateChangeMRIParameterCommand(sequenceId,{FlipAngle: flipAngle2, FlipIndex: "02"});
//var updateGroup1 = new RthUpdateGroup([bigAngleCommand, infoCommand1]);
//var updateGroup2 = new RthUpdateGroup([smallAngleCommand, infoCommand2]);
//var loopCommands = [updateGroup1, updateGroup2];
//rth.setLoopCommands(sequenceId, "tiploop", loopCommands);