Skip to content

Commit 47fd27f

Browse files
committed
refactor aperture texture
1 parent 38b92cf commit 47fd27f

File tree

1 file changed

+108
-102
lines changed

1 file changed

+108
-102
lines changed

src/aperture/apertureTexture.m

Lines changed: 108 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -14,108 +14,7 @@
1414

1515
case 'make'
1616

17-
TRANSPARENT = [0, 0, 0, 0];
18-
19-
xCenter = cfg.screen.center(1);
20-
yCenter = cfg.screen.center(2);
21-
22-
switch cfg.aperture.type
23-
24-
case 'none'
25-
26-
Screen('Fillrect', cfg.aperture.texture, TRANSPARENT);
27-
28-
case 'circle'
29-
30-
diameter = cfg.aperture.widthPix;
31-
32-
if isfield(cfg.aperture, 'xPosPix')
33-
xCenter = cfg.screen.center(1) + cfg.aperture.xPosPix;
34-
end
35-
if isfield(cfg.aperture, 'yPosPix')
36-
yCenter = cfg.screen.center(2) + cfg.aperture.yPosPix;
37-
end
38-
39-
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
40-
CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ...
41-
xCenter, yCenter));
42-
43-
case 'ring'
44-
45-
% expansion speed is log over eccentricity
46-
[cfg] = eccenLogSpeed(cfg, thisEvent.time);
47-
48-
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
49-
50-
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
51-
CenterRectOnPoint( ...
52-
[0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ...
53-
xCenter, yCenter));
54-
55-
Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ...
56-
CenterRectOnPoint( ...
57-
[0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ...
58-
xCenter, yCenter));
59-
60-
case 'wedge'
61-
62-
cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle;
63-
64-
% Update angle for rotation of background and for apperture for wedge
65-
switch cfg.direction
66-
67-
case '+'
68-
thisEvent.angle = 90 - ...
69-
cfg.aperture.width / 2 + ...
70-
(thisEvent.time / cycleDuration) * 360;
71-
case '-'
72-
thisEvent.angle = 90 - ...
73-
cfg.aperture.width / 2 - ...
74-
(thisEvent.time / cycleDuration) * 360;
75-
76-
end
77-
78-
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
79-
80-
Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ...
81-
CenterRect( ...
82-
cfg.destinationRect, ...
83-
cfg.screen.winRect), ...
84-
thisEvent.angle, ... % start angle
85-
cfg.aperture.width); % arc angle
86-
87-
case 'bar'
88-
89-
% aperture is the color of the background
90-
Screen('FillRect', cfg.aperture.texture, cfg.color.background);
91-
92-
% We let the stimulus through
93-
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
94-
CenterRect( ...
95-
[0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ...
96-
cfg.screen.winRect));
97-
98-
% Then we add the position of the bar aperture
99-
100-
% which one is the right and which one is the left??
101-
102-
Screen('FillRect', cfg.aperture.texture, cfg.color.background, ...
103-
[0, ...
104-
0, ...
105-
thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ...
106-
cfg.screen.winRect(4)]);
107-
108-
Screen('FillRect', cfg.aperture.texture, cfg.color.background, ...
109-
[thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ...
110-
0, ...
111-
cfg.screen.winRect(3), ...
112-
cfg.screen.winRect(4)]);
113-
114-
otherwise
115-
116-
error('unknown aperture type: %s.', cfg.aperture.type);
117-
118-
end
17+
cfg = apertureTextureMake(cfg, thisEvent);
11918

12019
case 'draw'
12120

@@ -190,3 +89,110 @@
19089
end
19190

19291
end
92+
93+
function cfg = apertureTextureMake(cfg, thisEvent)
94+
95+
TRANSPARENT = [0, 0, 0, 0];
96+
97+
xCenter = cfg.screen.center(1);
98+
yCenter = cfg.screen.center(2);
99+
100+
switch cfg.aperture.type
101+
102+
case 'none'
103+
104+
Screen('Fillrect', cfg.aperture.texture, TRANSPARENT);
105+
106+
case 'circle'
107+
108+
diameter = cfg.aperture.widthPix;
109+
110+
if isfield(cfg.aperture, 'xPosPix')
111+
xCenter = xCenter + cfg.aperture.xPosPix;
112+
end
113+
if isfield(cfg.aperture, 'yPosPix')
114+
yCenter = yCenter + cfg.aperture.yPosPix;
115+
end
116+
117+
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
118+
CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ...
119+
xCenter, yCenter));
120+
121+
case 'ring'
122+
123+
% expansion speed is log over eccentricity
124+
[cfg] = eccenLogSpeed(cfg, thisEvent.time);
125+
126+
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
127+
128+
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
129+
CenterRectOnPoint( ...
130+
[0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ...
131+
xCenter, yCenter));
132+
133+
Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ...
134+
CenterRectOnPoint( ...
135+
[0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ...
136+
xCenter, yCenter));
137+
138+
case 'wedge'
139+
140+
cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle;
141+
142+
% Update angle for rotation of background and for apperture for wedge
143+
switch cfg.direction
144+
145+
case '+'
146+
thisEvent.angle = 90 - ...
147+
cfg.aperture.width / 2 + ...
148+
(thisEvent.time / cycleDuration) * 360;
149+
case '-'
150+
thisEvent.angle = 90 - ...
151+
cfg.aperture.width / 2 - ...
152+
(thisEvent.time / cycleDuration) * 360;
153+
154+
end
155+
156+
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
157+
158+
Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ...
159+
CenterRect( ...
160+
cfg.destinationRect, ...
161+
cfg.screen.winRect), ...
162+
thisEvent.angle, ... % start angle
163+
cfg.aperture.width); % arc angle
164+
165+
case 'bar'
166+
167+
% aperture is the color of the background
168+
Screen('FillRect', cfg.aperture.texture, cfg.color.background);
169+
170+
% We let the stimulus through
171+
Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ...
172+
CenterRect( ...
173+
[0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ...
174+
cfg.screen.winRect));
175+
176+
% Then we add the position of the bar aperture
177+
178+
% which one is the right and which one is the left??
179+
180+
Screen('FillRect', cfg.aperture.texture, cfg.color.background, ...
181+
[0, ...
182+
0, ...
183+
thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ...
184+
cfg.screen.winRect(4)]);
185+
186+
Screen('FillRect', cfg.aperture.texture, cfg.color.background, ...
187+
[thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ...
188+
0, ...
189+
cfg.screen.winRect(3), ...
190+
cfg.screen.winRect(4)]);
191+
192+
otherwise
193+
194+
error('unknown aperture type: %s.', cfg.aperture.type);
195+
196+
end
197+
198+
end

0 commit comments

Comments
 (0)