-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfindOffset_nonius_fixationV4.m
328 lines (285 loc) · 12.5 KB
/
findOffset_nonius_fixationV4.m
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
function [vertOffsets,horiOffsets] = findOffset_nonius_fixationV3(subject, session, debug)
%%%%%%%%%%%%%%%%%%%
% BASIC SETTINGS
%%%%%%%%%%%%%%%%%%%
%%%% resolution
if debug == 1
SetResolution(max(Screen('Screens')), 1280,1024,85);
else
SetResolution(max(Screen('Screens')),1280,1024,85);
end
experiment.runNum = input('Run number :');
%%%% keyboards
[keyboardIndices, productNames, ~] = GetKeyboardIndices ;
deviceNumber = keyboardIndices(1);
%%%% response listening - so we don't read in scanner triggers!
responseKeys = zeros(1,256);
responseKeys(KbName('2'))=1; % button box 1
responseKeys(KbName('4'))=1; % button box 2
responseKeys(KbName('6'))=1; % button box 3
responseKeys(KbName('8'))=1; % button box 4
responseKeys(KbName('LeftArrow'))=1; % button box 5
responseKeys(KbName('RightArrow'))=1; % button box 5
responseKeys(KbName('Enter'))=1; % button box 3
Screen('Preference', 'SkipSyncTests', 0);
%%%% input this at the beginning of the scan session for 7T
ex.vertOffsetL = 0; % vertical offset
ex.horiOffsetL = 0;
ex.vertOffsetR = 0; % vertical offset
ex.horiOffsetR = 0;
% scSize.screenDeg = 14; % pRF screen size
ex.screenDegY = 8; %figSizeDeg;
ex.screenDegX = 16; %figSizeDeg*3;%9; % pRF screen size
% scSize.centerDeg = 4; % center circle size in diameter
% scSize.surroundDeg = 12; % surround circle size in diameter
%%%% scales all of the stimuli in DVA to the screensize
ex.screenWidth = 40; % in cm; laptop=27.5, office=43, 3Tb=19, 7T=17, miniHelm=39;
ex.viewingDist = 46; % in cm; 3Tb/office=43, 7T=48, miniHelm=57;
ex.backgroundColor = [128 128 128]; % color
ex.boxColor = ex.backgroundColor * .7;
%%%% Fixation
ex.littleFixDeg = .2; % in degrees, the size of the biggest white dot in the fixation
ex.bigFixSizeDeg = 0.5;
ex.outerFixPixels = 2; % in pixels, the black ring around fixation
%%%% Lines
ex.lineHdeg = 1/2;%1/sqrt(2);
ex.lineThdeg = 0.1;
ex.lineHdegSq = 5; %square size
%%% horizontal line
ex.horiLineWdeg = 0.7;
%%%%%%%%%%%%%%%%
% OPEN SCREEN
%%%%%%%%%%%%%%%%
HideCursor;
Priority(9); % highest priority
%%%% open screen
% Screen('Preference', 'SkipSyncTests', 1);
screen=max(Screen('Screens'));
[w, rect]=Screen('OpenWindow',screen,180,[],[],[],[],[],kPsychNeed32BPCFloat);
% [w, rect]=Screen('OpenWindow',screen,ex.backgroundColor,[],[],[],[],[],kPsychNeed32BPCFloat); %might need to switch 900 and 600 by 1600 and 1200 for room 425
Screen(w, 'TextSize', 32);
Screen('BlendFunction', w, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); % Set up alpha-blending for smooth (anti-aliased) lines
% xc = rect(3)/2;
% yc = rect(4)/2;
%Load the gamma table of the specified screen
load("phase2_photometry.mat");
Screen('LoadNormalizedGammaTable', w, inverseCLUT);
%%%% scale the stims for the screen
ex.ppd = pi* rect(3) / (atan(ex.screenWidth/ex.viewingDist/2)) / 360;
ex.fixSize = round(ex.littleFixDeg*ex.ppd);
%%%% Fixation dot
% ex.yFixOffset = 3*ex.ppd;
ex.lineH = ex.lineHdeg*ex.ppd;
ex.lineW = ex.lineHdeg*ex.ppd;
ex.lineTh = ex.lineThdeg*ex.ppd;
ex.lineHsq = ex.lineHdegSq*ex.ppd;
ex.lineColor = [0 0 0];
%%%% find center Y
Screen('FillRect',w,ex.backgroundColor)
text = 'Find CENTER X,Y for left eye. \n\n 8 = Up, 2 = Down, \n\n 6 = Right , 4: Left, \n\n Enter: Accept\n\nPress any button to start';
width = RectWidth(Screen('TextBounds',w,text));
xc =rect(3)/2;
yc = rect(4)/2;
DrawFormattedText(w, text, xc/5, yc/2);
DrawFormattedText(w, text, xc+xc/5, yc/2);
Screen(w, 'Flip', 0);
% WaitSecs(1); KbPressWait; KbQueueFlush();
% KbTriggerWait(KbName('Space'), deviceNumber);
KbWait(deviceNumber,2)
text = 'Press left or right arrow \n\n to select a square to move.';
DrawFormattedText(w, text, xc/5, yc/2);
DrawFormattedText(w, text, xc+xc/5, yc/2);
Screen(w, 'Flip', 0);
%%%%%%%%
% RUN
%%%%%%%%
KbQueueCreate(deviceNumber,responseKeys);
KbQueueStart();
KbWait(deviceNumber,2)
% % [secs, keyCode, ~] = KbWait(deviceNumber,2); %KbCheck;
% [pressed, firstPress]= KbQueueCheck();
% if find(firstPress,1) == KbName('LeftArrow')%
% chosenSquare = 'Left';
% % break;
% KbQueueFlush();
% elseif find(firstPress,1) == KbName('RightArrow')%keyCode(KbName('RightArrow'))
% chosenSquare = 'Right';
% % break;
% KbQueueFlush();
% end
% KbQueueStop();
chosenSquare = 'Left';
while 1
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown
if keyCode(KbName('LeftArrow'))%
chosenSquare = 'Left';
elseif keyCode(KbName('RightArrow'))%keyCode(KbName('RightArrow'))
chosenSquare = 'Right';
end
end
KbQueueStart();
%Dot coordinates
% xcL = rect(3)*3/2+ex.horiOffsetL;
% ycL = rect(4)/2+ex.vertOffsetL;
%% RIGHT SQUARE
% Grid Line coordinates
% 45 deg line coordinates
xRforLl = 3 * xc / 2-ex.lineW+ex.horiOffsetR;
xRforLr = 3 * xc / 2+ex.lineW+ex.horiOffsetR;
yRforLBot = yc + ex.lineH+ex.vertOffsetR;
yRforLTop = yc - ex.lineH+ex.vertOffsetR;
% 135 deg line coordinates
xRbackRl = 3 * xc / 2-ex.lineW+ex.horiOffsetR;
xRbackRr = 3 * xc / 2+ex.lineW+ex.horiOffsetR;
yRbackRTop = yc- ex.lineH+ex.vertOffsetR;
yRbackRBot = yc +ex.lineH+ex.vertOffsetR;
%
% Grid lines
for c = 1:3
xshift = 2*ex.lineH*(c-1);
for r=1:3
yshift = 2*ex.lineW*(r-1);
%lower right cross/grid
Screen('DrawLines', w, [xRforLl+xshift, xRforLr+xshift; yRforLBot+yshift, yRforLTop+yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl+xshift, xRbackRr+xshift; yRbackRTop+yshift, yRbackRBot+yshift], ex.lineTh, ex.lineColor);
%Upper right grid
Screen('DrawLines', w, [xRforLl+xshift, xRforLr+xshift; yRforLBot-yshift, yRforLTop-yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl+xshift, xRbackRr+xshift; yRbackRTop-yshift, yRbackRBot-yshift], ex.lineTh, ex.lineColor);
end
end
for c = 1:3
xshift = 2*ex.lineH*(c-1);
for r=1:3
yshift = 2*ex.lineW*(r-1);
%lower left cross/grid
Screen('DrawLines', w, [xRforLl-xshift, xRforLr-xshift; yRforLBot+yshift, yRforLTop+yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl-xshift, xRbackRr-xshift; yRbackRTop+yshift, yRbackRBot+yshift], ex.lineTh, ex.lineColor);
%Upper left grid
Screen('DrawLines', w, [xRforLl-xshift, xRforLr-xshift; yRforLBot-yshift, yRforLTop-yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl-xshift, xRbackRr-xshift; yRbackRTop-yshift, yRbackRBot-yshift], ex.lineTh, ex.lineColor);
end
end
% %% square
% Define the square parameters (position and size)
squareRectRight = [3 * xc / 2-ex.lineHsq/2+ex.horiOffsetR, yc - ex.lineHsq/2+ex.vertOffsetR, 3 * xc / 2+ex.lineHsq/2+ex.horiOffsetR, yc + ex.lineHsq/2+ex.vertOffsetR];
% Draw the square
Screen('FrameRect', w, [0 0 0], squareRectRight, ex.lineTh);
%%%% FLIP
Screen(w, 'Flip', 0);
WaitSecs(0.5);
%% LEFT SQUARE
% Line coordinates
% 45 deg line coordinates
xLforl = xc / 2-ex.lineW+ex.horiOffsetL;
xLforr = xc / 2+ex.lineW+ex.horiOffsetL;
yLforBot = yc + ex.lineH+ex.vertOffsetL;
yLforTop = yc - ex.lineH+ex.vertOffsetL;
% 135 deg line coordinates
xLbackl = xc / 2-ex.lineW+ex.horiOffsetL;
xLbackr = xc / 2+ex.lineW+ex.horiOffsetL;
yLbackTop = yc- ex.lineH+ex.vertOffsetL;
yLbackBot = yc +ex.lineH+ex.vertOffsetL;
% Define the square parameters (position and size)
squareRectLeft = [xc / 2-ex.lineHsq/2+ex.horiOffsetL, yc - ex.lineHsq/2+ex.vertOffsetL, xc / 2+ex.lineHsq/2+ex.horiOffsetL, yc + ex.lineHsq/2+ex.vertOffsetL];
for c = 1:3
xshift = 2*ex.lineH*(c-1);
for r=1:3
yshift = 2*ex.lineW*(r-1);
%lower right cross/grid
Screen('DrawLines', w, [xLforl+xshift, xLforr+xshift; yLforBot+yshift, yLforTop+yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xLbackl+xshift, xLbackr+xshift; yLbackTop+yshift, yLbackBot+yshift], ex.lineTh, ex.lineColor);
%Upper right grid
Screen('DrawLines', w, [xLforl+xshift, xLforr+xshift; yLforBot-yshift, yLforTop-yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xLbackl+xshift, xLbackr+xshift; yLbackTop-yshift, yLbackBot-yshift], ex.lineTh, ex.lineColor);
end
end
for c = 1:3
xshift = 2*ex.lineH*(c-1);
for r=1:3
yshift = 2*ex.lineW*(r-1);
%lower left cross/grid
Screen('DrawLines', w, [xLforl-xshift, xLforr-xshift; yLforBot+yshift, yLforTop+yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xLbackl-xshift, xLbackr-xshift; yLbackTop+yshift, yLbackBot+yshift], ex.lineTh, ex.lineColor);
%Upper left grid
Screen('DrawLines', w, [xLforl-xshift, xLforr-xshift; yLforBot-yshift, yLforTop-yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xLbackl-xshift, xLbackr-xshift; yLbackTop-yshift, yLbackBot-yshift], ex.lineTh, ex.lineColor);
end
end
%right grid lines
% Grid lines
for c = 1:3
xshift = 2*ex.lineH*(c-1);
for r=1:3
yshift = 2*ex.lineW*(r-1);
%lower right cross/grid
Screen('DrawLines', w, [xRforLl+xshift, xRforLr+xshift; yRforLBot+yshift, yRforLTop+yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl+xshift, xRbackRr+xshift; yRbackRTop+yshift, yRbackRBot+yshift], ex.lineTh, ex.lineColor);
%Upper right grid
Screen('DrawLines', w, [xRforLl+xshift, xRforLr+xshift; yRforLBot-yshift, yRforLTop-yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl+xshift, xRbackRr+xshift; yRbackRTop-yshift, yRbackRBot-yshift], ex.lineTh, ex.lineColor);
end
end
for c = 1:3
xshift = 2*ex.lineH*(c-1);
for r=1:3
yshift = 2*ex.lineW*(r-1);
%lower left cross/grid
Screen('DrawLines', w, [xRforLl-xshift, xRforLr-xshift; yRforLBot+yshift, yRforLTop+yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl-xshift, xRbackRr-xshift; yRbackRTop+yshift, yRbackRBot+yshift], ex.lineTh, ex.lineColor);
%Upper left grid
Screen('DrawLines', w, [xRforLl-xshift, xRforLr-xshift; yRforLBot-yshift, yRforLTop-yshift], ex.lineTh, ex.lineColor);
Screen('DrawLines', w, [xRbackRl-xshift, xRbackRr-xshift; yRbackRTop-yshift, yRbackRBot-yshift], ex.lineTh, ex.lineColor);
end
end
% Draw the square
Screen('FrameRect', w, [0 0 0], squareRectLeft, ex.lineTh);
Screen('FrameRect', w, [0 0 0], squareRectRight, ex.lineTh);
%%%% FLIP
Screen(w, 'Flip', 0);
WaitSecs(0.5);
Screen(w, 'Flip', 0);
KbWait(deviceNumber,2)
%%%% check for responses
[pressed, firstPress]= KbQueueCheck();
if contains(chosenSquare, 'Right')
if find(firstPress,1) == KbName('8')
ex.vertOffsetR = ex.vertOffsetR - 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('2')
ex.vertOffsetR = ex.vertOffsetR + 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('4')
ex.horiOffsetR = ex.horiOffsetR - 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('6')
ex.horiOffsetR = ex.horiOffsetR + 5;
elseif find(firstPress,1) == KbName('Enter')
break;
KbQueueFlush();
end
elseif contains(chosenSquare, 'Left')
if find(firstPress,1) == KbName('8')
ex.vertOffsetL = ex.vertOffsetL - 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('2')
ex.vertOffsetL = ex.vertOffsetL + 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('4')
ex.horiOffsetL = ex.horiOffsetL - 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('6')
ex.horiOffsetL = ex.horiOffsetL + 5;
KbQueueFlush();
elseif find(firstPress,1) == KbName('Enter')
break;
KbQueueFlush();
end
end
end
vertOffsets = [ex.vertOffsetL; ex.vertOffsetR];
horiOffsets = [ex.horiOffsetL;ex.horiOffsetR];
KbQueueRelease();
ShowCursor;
Screen('Close');
Screen('CloseAll');