Skip to content

Commit e33a550

Browse files
committed
fix aperture for ring and wedge to adapt to scaling
1 parent 28a77c0 commit e33a550

File tree

1 file changed

+64
-68
lines changed

1 file changed

+64
-68
lines changed

src/aperture/apertureTexture.m

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,68 @@
22
% [cfg, thisEvent] = apertureTexture(action, cfg, thisEvent)
33
%
44
%
5-
5+
66
switch action
7-
7+
88
case 'init'
9-
9+
1010
cfg = apertureInit(cfg);
11-
11+
1212
cfg.aperture.texture = Screen('MakeTexture', cfg.screen.win, ...
1313
cfg.color.background(1) * ones(cfg.screen.winRect([3 3])));
14-
14+
1515
case 'make'
16-
16+
1717
TRANSPARENT = [0, 0, 0, 0];
18-
18+
1919
xCenter = cfg.screen.center(1);
2020
yCenter = cfg.screen.center(2);
21-
21+
2222
switch cfg.aperture.type
23-
23+
2424
case 'none'
25-
25+
2626
Screen('Fillrect', cfg.aperture.texture, TRANSPARENT);
27-
27+
2828
case 'circle'
29-
29+
3030
diameter = cfg.aperture.widthPix;
31-
31+
3232
if isfield(cfg.aperture, 'xPosPix')
3333
xCenter = cfg.screen.center(1) + cfg.aperture.xPosPix;
3434
end
3535
if isfield(cfg.aperture, 'yPosPix')
3636
yCenter = cfg.screen.center(2) + cfg.aperture.yPosPix;
3737
end
38-
38+
3939
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
4040
CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ...
4141
xCenter, yCenter));
42-
42+
4343
case 'ring'
44-
44+
4545
% expansion speed is log over eccentricity
4646
[cfg] = eccenLogSpeed(cfg, thisEvent.time);
47-
47+
4848
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
49-
49+
5050
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
5151
CenterRectOnPoint( ...
5252
[0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ...
5353
xCenter, yCenter));
54-
54+
5555
Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ...
5656
CenterRectOnPoint( ...
5757
[0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ...
5858
xCenter, yCenter));
59-
59+
6060
case 'wedge'
61-
61+
6262
cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle;
63-
63+
6464
% Update angle for rotation of background and for apperture for wedge
6565
switch cfg.direction
66-
66+
6767
case '+'
6868
thisEvent.angle = 90 - ...
6969
cfg.aperture.width / 2 + ...
@@ -72,90 +72,86 @@
7272
thisEvent.angle = 90 - ...
7373
cfg.aperture.width / 2 - ...
7474
(thisEvent.time / cycleDuration) * 360;
75-
75+
7676
end
77-
77+
7878
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
79-
79+
8080
Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ...
8181
CenterRect( ...
82-
[0, 0, repmat(cfg.stimRect(4), 1, 2)], ...
82+
cfg.destinationRect, ...
8383
cfg.screen.winRect), ...
8484
thisEvent.angle, ... % start angle
8585
cfg.aperture.width); % arc angle
86-
86+
8787
case 'bar'
88-
88+
8989
% aperture is the color of the background
9090
Screen('FillRect', cfg.aperture.texture, cfg.color.background);
91-
91+
9292
% We let the stimulus through
9393
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
9494
CenterRect( ...
9595
[0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ...
9696
cfg.screen.winRect));
97-
97+
9898
% Then we add the position of the bar aperture
99-
99+
100100
% which one is the right and which one is the left??
101-
101+
102102
Screen('FillRect', cfg.aperture.texture, cfg.color.background, ...
103103
[0, ...
104104
0, ...
105105
thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ...
106106
cfg.screen.winRect(4)]);
107-
107+
108108
Screen('FillRect', cfg.aperture.texture, cfg.color.background, ...
109109
[thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ...
110110
0, ...
111111
cfg.screen.winRect(3), ...
112112
cfg.screen.winRect(4)]);
113-
113+
114114
otherwise
115-
115+
116116
error('unknown aperture type: %s.', cfg.aperture.type);
117-
117+
118118
end
119-
119+
120120
case 'draw'
121-
121+
122+
scalingFactor = 1;
123+
if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor)
124+
scalingFactor = cfg.scalingFactor;
125+
end
126+
127+
rotationAngle = [];
122128
if strcmp(cfg.aperture.type, 'bar')
123-
124-
scalingFactor = 1;
125-
if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor)
126-
scalingFactor = cfg.scalingFactor;
127-
end
128-
129-
% Draw aperture and we rotate to match the required condition
130-
Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ...
131-
cfg.screen.winRect, ...
132-
CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ...
133-
thisEvent.condition - 90);
134-
135-
else
136-
137-
Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture);
138-
129+
rotationAngle = thisEvent.condition - 90;
139130
end
140-
131+
132+
Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ...
133+
cfg.screen.winRect, ...
134+
CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ...
135+
rotationAngle);
136+
141137
end
142-
138+
143139
end
144140

145141
function cfg = apertureInit(cfg)
146-
142+
147143
switch cfg.aperture.type
148-
144+
149145
case 'circle'
150146
% we take the screen height as maximum aperture width if not
151147
% specified.
152148
if ~isfield(cfg.aperture, 'width') || isempty(cfg.aperture.width)
153149
cfg.aperture.width = cfg.screen.winRect(4) / cfg.screen.ppd;
154150
end
155151
cfg.aperture = degToPix('width', cfg.aperture, cfg);
156-
152+
157153
case 'ring'
158-
154+
159155
% Set parameters for rings
160156
if strcmp(cfg.aperture.type, 'ring')
161157
% scale of outer ring (exceeding screen until
@@ -172,25 +168,25 @@
172168
log(cfg.ring.maxEcc + exp(1)) - ...
173169
(cfg.ring.maxEcc + exp(1)));
174170
end
175-
171+
176172
case 'bar'
177-
173+
178174
% Set parameters drifting bars
179175
cfg.aperture.barWidthPix = cfg.stimRect(3) / cfg.volsPerCycle;
180-
176+
181177
barPosPix = ...
182178
[0:cfg.aperture.barWidthPix:cfg.stimRect(3) - cfg.aperture.barWidthPix] + ...
183179
(cfg.screen.winRect(3) / 2 - cfg.stimRect(3) / 2) + ...
184180
cfg.aperture.barWidthPix / 2; %#ok<NBRAK>
185-
181+
186182
cfg.aperture.barPosPix = barPosPix;
187-
183+
188184
% Width of bar in degrees of VA (needed for saving)
189185
cfg.aperture.width = cfg.aperture.barWidthPix / cfg.screen.ppd;
190186
cfg.aperture.barPos = ...
191187
(cfg.aperture.barPosPix - cfg.screen.center(1)) / ...
192188
cfg.screen.ppd;
193-
189+
194190
end
195-
191+
196192
end

0 commit comments

Comments
 (0)