From d0d30b4e2ba79bb0972dadd1f9b8d42b98cb5874 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 9 Sep 2020 18:35:18 +0200 Subject: [PATCH 1/8] small changes on aperture function --- src/aperture/apertureTexture.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aperture/apertureTexture.m b/src/aperture/apertureTexture.m index e541abc..bf70a81 100644 --- a/src/aperture/apertureTexture.m +++ b/src/aperture/apertureTexture.m @@ -10,7 +10,7 @@ cfg = apertureInit(cfg); cfg.aperture.texture = Screen('MakeTexture', cfg.screen.win, ... - cfg.color.background(1) * ones(cfg.screen.winRect([4 3]))); + cfg.color.background(1) * ones(cfg.screen.winRect([3 3]))); case 'make' @@ -91,7 +91,9 @@ % We let the stimulus through Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... - CenterRect([0, 0, repmat(cfg.stimRect(3), 1, 2)], cfg.screen.winRect)); + CenterRect(... + [0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ... + cfg.screen.winRect)); % Then we add the position of the bar aperture @@ -122,9 +124,7 @@ % Draw aperture and we rotate to match the required condition Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ... cfg.screen.winRect, ... - CenterRect( ... cfg.screen.winRect, ... - cfg.screen.winRect), ... thisEvent.condition - 90); else From 6061353a6932f5f0c15e32b60c65c792430aeaa5 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 9 Sep 2020 20:17:56 +0200 Subject: [PATCH 2/8] make it possible to scale bar aperture --- src/aperture/apertureTexture.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/aperture/apertureTexture.m b/src/aperture/apertureTexture.m index bf70a81..783d699 100644 --- a/src/aperture/apertureTexture.m +++ b/src/aperture/apertureTexture.m @@ -120,12 +120,18 @@ case 'draw' if strcmp(cfg.aperture.type, 'bar') - + + scalingFactor = 1; + if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor) + scalingFactor = cfg.scalingFactor; + end + % Draw aperture and we rotate to match the required condition Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ... cfg.screen.winRect, ... - cfg.screen.winRect, ... + CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ... thisEvent.condition - 90); + else Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture); @@ -187,4 +193,4 @@ end -end +end \ No newline at end of file From 28a77c025830998e86e6b1e6d42c738fc9ef54aa Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Mon, 14 Sep 2020 17:59:22 +0200 Subject: [PATCH 3/8] mh fix --- src/aperture/apertureTexture.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aperture/apertureTexture.m b/src/aperture/apertureTexture.m index 783d699..bff90f2 100644 --- a/src/aperture/apertureTexture.m +++ b/src/aperture/apertureTexture.m @@ -91,7 +91,7 @@ % We let the stimulus through Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... - CenterRect(... + CenterRect( ... [0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ... cfg.screen.winRect)); @@ -120,18 +120,18 @@ case 'draw' if strcmp(cfg.aperture.type, 'bar') - + scalingFactor = 1; - if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor) + if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor) scalingFactor = cfg.scalingFactor; end - + % Draw aperture and we rotate to match the required condition Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ... cfg.screen.winRect, ... CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ... thisEvent.condition - 90); - + else Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture); @@ -193,4 +193,4 @@ end -end \ No newline at end of file +end From e33a550cf05af82c7d6aa9338e13d04689c3ad3c Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 15 Sep 2020 09:28:02 +0200 Subject: [PATCH 4/8] fix aperture for ring and wedge to adapt to scaling --- src/aperture/apertureTexture.m | 132 ++++++++++++++++----------------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/src/aperture/apertureTexture.m b/src/aperture/apertureTexture.m index bff90f2..b23d067 100644 --- a/src/aperture/apertureTexture.m +++ b/src/aperture/apertureTexture.m @@ -2,68 +2,68 @@ % [cfg, thisEvent] = apertureTexture(action, cfg, thisEvent) % % - + switch action - + case 'init' - + cfg = apertureInit(cfg); - + cfg.aperture.texture = Screen('MakeTexture', cfg.screen.win, ... cfg.color.background(1) * ones(cfg.screen.winRect([3 3]))); - + case 'make' - + TRANSPARENT = [0, 0, 0, 0]; - + xCenter = cfg.screen.center(1); yCenter = cfg.screen.center(2); - + switch cfg.aperture.type - + case 'none' - + Screen('Fillrect', cfg.aperture.texture, TRANSPARENT); - + case 'circle' - + diameter = cfg.aperture.widthPix; - + if isfield(cfg.aperture, 'xPosPix') xCenter = cfg.screen.center(1) + cfg.aperture.xPosPix; end if isfield(cfg.aperture, 'yPosPix') yCenter = cfg.screen.center(2) + cfg.aperture.yPosPix; end - + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ... xCenter, yCenter)); - + case 'ring' - + % expansion speed is log over eccentricity [cfg] = eccenLogSpeed(cfg, thisEvent.time); - + Screen('Fillrect', cfg.aperture.texture, cfg.color.background); - + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... CenterRectOnPoint( ... [0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ... xCenter, yCenter)); - + Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ... CenterRectOnPoint( ... [0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ... xCenter, yCenter)); - + case 'wedge' - + cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle; - + % Update angle for rotation of background and for apperture for wedge switch cfg.direction - + case '+' thisEvent.angle = 90 - ... cfg.aperture.width / 2 + ... @@ -72,80 +72,76 @@ thisEvent.angle = 90 - ... cfg.aperture.width / 2 - ... (thisEvent.time / cycleDuration) * 360; - + end - + Screen('Fillrect', cfg.aperture.texture, cfg.color.background); - + Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ... CenterRect( ... - [0, 0, repmat(cfg.stimRect(4), 1, 2)], ... + cfg.destinationRect, ... cfg.screen.winRect), ... thisEvent.angle, ... % start angle cfg.aperture.width); % arc angle - + case 'bar' - + % aperture is the color of the background Screen('FillRect', cfg.aperture.texture, cfg.color.background); - + % We let the stimulus through Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... CenterRect( ... [0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ... cfg.screen.winRect)); - + % Then we add the position of the bar aperture - + % which one is the right and which one is the left?? - + Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... [0, ... 0, ... thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ... cfg.screen.winRect(4)]); - + Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... [thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ... 0, ... cfg.screen.winRect(3), ... cfg.screen.winRect(4)]); - + otherwise - + error('unknown aperture type: %s.', cfg.aperture.type); - + end - + case 'draw' - + + scalingFactor = 1; + if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor) + scalingFactor = cfg.scalingFactor; + end + + rotationAngle = []; if strcmp(cfg.aperture.type, 'bar') - - scalingFactor = 1; - if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor) - scalingFactor = cfg.scalingFactor; - end - - % Draw aperture and we rotate to match the required condition - Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ... - cfg.screen.winRect, ... - CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ... - thisEvent.condition - 90); - - else - - Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture); - + rotationAngle = thisEvent.condition - 90; end - + + Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ... + cfg.screen.winRect, ... + CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ... + rotationAngle); + end - + end function cfg = apertureInit(cfg) - + switch cfg.aperture.type - + case 'circle' % we take the screen height as maximum aperture width if not % specified. @@ -153,9 +149,9 @@ cfg.aperture.width = cfg.screen.winRect(4) / cfg.screen.ppd; end cfg.aperture = degToPix('width', cfg.aperture, cfg); - + case 'ring' - + % Set parameters for rings if strcmp(cfg.aperture.type, 'ring') % scale of outer ring (exceeding screen until @@ -172,25 +168,25 @@ log(cfg.ring.maxEcc + exp(1)) - ... (cfg.ring.maxEcc + exp(1))); end - + case 'bar' - + % Set parameters drifting bars cfg.aperture.barWidthPix = cfg.stimRect(3) / cfg.volsPerCycle; - + barPosPix = ... [0:cfg.aperture.barWidthPix:cfg.stimRect(3) - cfg.aperture.barWidthPix] + ... (cfg.screen.winRect(3) / 2 - cfg.stimRect(3) / 2) + ... cfg.aperture.barWidthPix / 2; %#ok - + cfg.aperture.barPosPix = barPosPix; - + % Width of bar in degrees of VA (needed for saving) cfg.aperture.width = cfg.aperture.barWidthPix / cfg.screen.ppd; cfg.aperture.barPos = ... (cfg.aperture.barPosPix - cfg.screen.center(1)) / ... cfg.screen.ppd; - + end - + end From d8a4de9a9dd2f7c909655552da10a9d4f9ca7587 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 15 Sep 2020 15:38:39 +0200 Subject: [PATCH 5/8] mh fix --- src/aperture/apertureTexture.m | 108 ++++++++++++++++----------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/aperture/apertureTexture.m b/src/aperture/apertureTexture.m index b23d067..7bbda89 100644 --- a/src/aperture/apertureTexture.m +++ b/src/aperture/apertureTexture.m @@ -2,68 +2,68 @@ % [cfg, thisEvent] = apertureTexture(action, cfg, thisEvent) % % - + switch action - + case 'init' - + cfg = apertureInit(cfg); - + cfg.aperture.texture = Screen('MakeTexture', cfg.screen.win, ... cfg.color.background(1) * ones(cfg.screen.winRect([3 3]))); - + case 'make' - + TRANSPARENT = [0, 0, 0, 0]; - + xCenter = cfg.screen.center(1); yCenter = cfg.screen.center(2); - + switch cfg.aperture.type - + case 'none' - + Screen('Fillrect', cfg.aperture.texture, TRANSPARENT); - + case 'circle' - + diameter = cfg.aperture.widthPix; - + if isfield(cfg.aperture, 'xPosPix') xCenter = cfg.screen.center(1) + cfg.aperture.xPosPix; end if isfield(cfg.aperture, 'yPosPix') yCenter = cfg.screen.center(2) + cfg.aperture.yPosPix; end - + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ... xCenter, yCenter)); - + case 'ring' - + % expansion speed is log over eccentricity [cfg] = eccenLogSpeed(cfg, thisEvent.time); - + Screen('Fillrect', cfg.aperture.texture, cfg.color.background); - + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... CenterRectOnPoint( ... [0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ... xCenter, yCenter)); - + Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ... CenterRectOnPoint( ... [0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ... xCenter, yCenter)); - + case 'wedge' - + cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle; - + % Update angle for rotation of background and for apperture for wedge switch cfg.direction - + case '+' thisEvent.angle = 90 - ... cfg.aperture.width / 2 + ... @@ -72,76 +72,76 @@ thisEvent.angle = 90 - ... cfg.aperture.width / 2 - ... (thisEvent.time / cycleDuration) * 360; - + end - + Screen('Fillrect', cfg.aperture.texture, cfg.color.background); - + Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ... CenterRect( ... cfg.destinationRect, ... cfg.screen.winRect), ... thisEvent.angle, ... % start angle cfg.aperture.width); % arc angle - + case 'bar' - + % aperture is the color of the background Screen('FillRect', cfg.aperture.texture, cfg.color.background); - + % We let the stimulus through Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... CenterRect( ... [0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ... cfg.screen.winRect)); - + % Then we add the position of the bar aperture - + % which one is the right and which one is the left?? - + Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... [0, ... 0, ... thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ... cfg.screen.winRect(4)]); - + Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... [thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ... 0, ... cfg.screen.winRect(3), ... cfg.screen.winRect(4)]); - + otherwise - + error('unknown aperture type: %s.', cfg.aperture.type); - + end - + case 'draw' - + scalingFactor = 1; if isfield(cfg, 'scalingFactor') && ~isempty(cfg.scalingFactor) scalingFactor = cfg.scalingFactor; end - + rotationAngle = []; if strcmp(cfg.aperture.type, 'bar') - rotationAngle = thisEvent.condition - 90; + rotationAngle = thisEvent.condition - 90; end - + Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture, ... cfg.screen.winRect, ... CenterRect(cfg.screen.winRect * scalingFactor, cfg.screen.winRect), ... rotationAngle); - + end - + end function cfg = apertureInit(cfg) - + switch cfg.aperture.type - + case 'circle' % we take the screen height as maximum aperture width if not % specified. @@ -149,9 +149,9 @@ cfg.aperture.width = cfg.screen.winRect(4) / cfg.screen.ppd; end cfg.aperture = degToPix('width', cfg.aperture, cfg); - + case 'ring' - + % Set parameters for rings if strcmp(cfg.aperture.type, 'ring') % scale of outer ring (exceeding screen until @@ -168,25 +168,25 @@ log(cfg.ring.maxEcc + exp(1)) - ... (cfg.ring.maxEcc + exp(1))); end - + case 'bar' - + % Set parameters drifting bars cfg.aperture.barWidthPix = cfg.stimRect(3) / cfg.volsPerCycle; - + barPosPix = ... [0:cfg.aperture.barWidthPix:cfg.stimRect(3) - cfg.aperture.barWidthPix] + ... (cfg.screen.winRect(3) / 2 - cfg.stimRect(3) / 2) + ... cfg.aperture.barWidthPix / 2; %#ok - + cfg.aperture.barPosPix = barPosPix; - + % Width of bar in degrees of VA (needed for saving) cfg.aperture.width = cfg.aperture.barWidthPix / cfg.screen.ppd; cfg.aperture.barPos = ... (cfg.aperture.barPosPix - cfg.screen.center(1)) / ... cfg.screen.ppd; - + end - + end From bc2c371e74920ff8afae96d5003b37324aecf652 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 15 Sep 2020 16:38:12 +0200 Subject: [PATCH 6/8] make skipSynchTest a parameter in cfg with 0 as default --- src/initPTB.m | 9 ++++++--- src/utils/setDefaultsPTB.m | 2 ++ tests/test_setDefaultsPTB.m | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/initPTB.m b/src/initPTB.m index 6e669a8..b25b2bc 100644 --- a/src/initPTB.m +++ b/src/initPTB.m @@ -34,6 +34,8 @@ AssertOpenGL; cfg = setDefaultsPTB(cfg); + + Screen('Preference', 'SkipSyncTests', cfg.skipSyncTests); initKeyboard; initDebug(cfg); @@ -120,10 +122,11 @@ function initDebug(cfg) % init PTB with different options in concordance to the debug Parameters - Screen('Preference', 'SkipSyncTests', 0); + if cfg.debug.do - - Screen('Preference', 'SkipSyncTests', 2); + + cfg.skipSyncTests = 2; + Screen('Preference', 'SkipSyncTests', cfg.skipSyncTests); Screen('Preference', 'Verbosity', 0); Screen('Preference', 'SuppressAllWarnings', 1); diff --git a/src/utils/setDefaultsPTB.m b/src/utils/setDefaultsPTB.m index 66b1460..ba276bf 100644 --- a/src/utils/setDefaultsPTB.m +++ b/src/utils/setDefaultsPTB.m @@ -9,6 +9,8 @@ %% list the default values fieldsToSet.testingDevice = 'pc'; + + fieldsToSet.skipSyncTests = 0; % keyboard defaults fieldsToSet.keyboard.keyboard = []; diff --git a/tests/test_setDefaultsPTB.m b/tests/test_setDefaultsPTB.m index b7aefc3..216aea3 100644 --- a/tests/test_setDefaultsPTB.m +++ b/tests/test_setDefaultsPTB.m @@ -69,6 +69,8 @@ function test_setDefaultsPtbAudio() expectedCFG.screen.monitorWidth = 42; expectedCFG.screen.monitorDistance = 134; expectedCFG.screen.resolution = {[], [], []}; + + expectedCFG.skipSyncTests = 0; % fixation cross or dot expectedCFG.fixation.type = 'cross'; From 38b92cfa174f1f676baf32ab58b6857ca8115e7d Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 15 Sep 2020 16:47:42 +0200 Subject: [PATCH 7/8] mh fix --- src/initPTB.m | 6 +++--- src/utils/setDefaultsPTB.m | 2 +- tests/test_setDefaultsPTB.m | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/initPTB.m b/src/initPTB.m index b25b2bc..fc38635 100644 --- a/src/initPTB.m +++ b/src/initPTB.m @@ -34,7 +34,7 @@ AssertOpenGL; cfg = setDefaultsPTB(cfg); - + Screen('Preference', 'SkipSyncTests', cfg.skipSyncTests); initKeyboard; @@ -122,9 +122,9 @@ function initDebug(cfg) % init PTB with different options in concordance to the debug Parameters - + if cfg.debug.do - + cfg.skipSyncTests = 2; Screen('Preference', 'SkipSyncTests', cfg.skipSyncTests); Screen('Preference', 'Verbosity', 0); diff --git a/src/utils/setDefaultsPTB.m b/src/utils/setDefaultsPTB.m index ba276bf..856f8f9 100644 --- a/src/utils/setDefaultsPTB.m +++ b/src/utils/setDefaultsPTB.m @@ -9,7 +9,7 @@ %% list the default values fieldsToSet.testingDevice = 'pc'; - + fieldsToSet.skipSyncTests = 0; % keyboard defaults diff --git a/tests/test_setDefaultsPTB.m b/tests/test_setDefaultsPTB.m index 216aea3..ae61b66 100644 --- a/tests/test_setDefaultsPTB.m +++ b/tests/test_setDefaultsPTB.m @@ -69,7 +69,7 @@ function test_setDefaultsPtbAudio() expectedCFG.screen.monitorWidth = 42; expectedCFG.screen.monitorDistance = 134; expectedCFG.screen.resolution = {[], [], []}; - + expectedCFG.skipSyncTests = 0; % fixation cross or dot From 47fd27f5bb42773578ea7ecb51135465b29e08bf Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 15 Sep 2020 16:48:30 +0200 Subject: [PATCH 8/8] refactor aperture texture --- src/aperture/apertureTexture.m | 210 +++++++++++++++++---------------- 1 file changed, 108 insertions(+), 102 deletions(-) diff --git a/src/aperture/apertureTexture.m b/src/aperture/apertureTexture.m index 7bbda89..49086ee 100644 --- a/src/aperture/apertureTexture.m +++ b/src/aperture/apertureTexture.m @@ -14,108 +14,7 @@ case 'make' - TRANSPARENT = [0, 0, 0, 0]; - - xCenter = cfg.screen.center(1); - yCenter = cfg.screen.center(2); - - switch cfg.aperture.type - - case 'none' - - Screen('Fillrect', cfg.aperture.texture, TRANSPARENT); - - case 'circle' - - diameter = cfg.aperture.widthPix; - - if isfield(cfg.aperture, 'xPosPix') - xCenter = cfg.screen.center(1) + cfg.aperture.xPosPix; - end - if isfield(cfg.aperture, 'yPosPix') - yCenter = cfg.screen.center(2) + cfg.aperture.yPosPix; - end - - Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... - CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ... - xCenter, yCenter)); - - case 'ring' - - % expansion speed is log over eccentricity - [cfg] = eccenLogSpeed(cfg, thisEvent.time); - - Screen('Fillrect', cfg.aperture.texture, cfg.color.background); - - Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... - CenterRectOnPoint( ... - [0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ... - xCenter, yCenter)); - - Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ... - CenterRectOnPoint( ... - [0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ... - xCenter, yCenter)); - - case 'wedge' - - cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle; - - % Update angle for rotation of background and for apperture for wedge - switch cfg.direction - - case '+' - thisEvent.angle = 90 - ... - cfg.aperture.width / 2 + ... - (thisEvent.time / cycleDuration) * 360; - case '-' - thisEvent.angle = 90 - ... - cfg.aperture.width / 2 - ... - (thisEvent.time / cycleDuration) * 360; - - end - - Screen('Fillrect', cfg.aperture.texture, cfg.color.background); - - Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ... - CenterRect( ... - cfg.destinationRect, ... - cfg.screen.winRect), ... - thisEvent.angle, ... % start angle - cfg.aperture.width); % arc angle - - case 'bar' - - % aperture is the color of the background - Screen('FillRect', cfg.aperture.texture, cfg.color.background); - - % We let the stimulus through - Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... - CenterRect( ... - [0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ... - cfg.screen.winRect)); - - % Then we add the position of the bar aperture - - % which one is the right and which one is the left?? - - Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... - [0, ... - 0, ... - thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ... - cfg.screen.winRect(4)]); - - Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... - [thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ... - 0, ... - cfg.screen.winRect(3), ... - cfg.screen.winRect(4)]); - - otherwise - - error('unknown aperture type: %s.', cfg.aperture.type); - - end + cfg = apertureTextureMake(cfg, thisEvent); case 'draw' @@ -190,3 +89,110 @@ end end + +function cfg = apertureTextureMake(cfg, thisEvent) + + TRANSPARENT = [0, 0, 0, 0]; + + xCenter = cfg.screen.center(1); + yCenter = cfg.screen.center(2); + + switch cfg.aperture.type + + case 'none' + + Screen('Fillrect', cfg.aperture.texture, TRANSPARENT); + + case 'circle' + + diameter = cfg.aperture.widthPix; + + if isfield(cfg.aperture, 'xPosPix') + xCenter = xCenter + cfg.aperture.xPosPix; + end + if isfield(cfg.aperture, 'yPosPix') + yCenter = yCenter + cfg.aperture.yPosPix; + end + + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... + CenterRectOnPoint([0, 0, repmat(diameter, 1, 2)], ... + xCenter, yCenter)); + + case 'ring' + + % expansion speed is log over eccentricity + [cfg] = eccenLogSpeed(cfg, thisEvent.time); + + Screen('Fillrect', cfg.aperture.texture, cfg.color.background); + + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... + CenterRectOnPoint( ... + [0, 0, repmat(cfg.ring.outerRimPix, 1, 2)], ... + xCenter, yCenter)); + + Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ... + CenterRectOnPoint( ... + [0, 0, repmat(cfg.ring.innerRimPix, 1, 2)], ... + xCenter, yCenter)); + + case 'wedge' + + cycleDuration = cfg.mri.repetitionTime * cfg.volsPerCycle; + + % Update angle for rotation of background and for apperture for wedge + switch cfg.direction + + case '+' + thisEvent.angle = 90 - ... + cfg.aperture.width / 2 + ... + (thisEvent.time / cycleDuration) * 360; + case '-' + thisEvent.angle = 90 - ... + cfg.aperture.width / 2 - ... + (thisEvent.time / cycleDuration) * 360; + + end + + Screen('Fillrect', cfg.aperture.texture, cfg.color.background); + + Screen('FillArc', cfg.aperture.texture, TRANSPARENT, ... + CenterRect( ... + cfg.destinationRect, ... + cfg.screen.winRect), ... + thisEvent.angle, ... % start angle + cfg.aperture.width); % arc angle + + case 'bar' + + % aperture is the color of the background + Screen('FillRect', cfg.aperture.texture, cfg.color.background); + + % We let the stimulus through + Screen('FillOval', cfg.aperture.texture, TRANSPARENT, ... + CenterRect( ... + [0, 0, repmat(cfg.screen.winRect(4), 1, 2)], ... + cfg.screen.winRect)); + + % Then we add the position of the bar aperture + + % which one is the right and which one is the left?? + + Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... + [0, ... + 0, ... + thisEvent.barPosPix - cfg.aperture.barWidthPix / 2, ... + cfg.screen.winRect(4)]); + + Screen('FillRect', cfg.aperture.texture, cfg.color.background, ... + [thisEvent.barPosPix + cfg.aperture.barWidthPix / 2, ... + 0, ... + cfg.screen.winRect(3), ... + cfg.screen.winRect(4)]); + + otherwise + + error('unknown aperture type: %s.', cfg.aperture.type); + + end + +end