diff --git a/+vis/checker3.m b/+vis/checker3.m index 259fdd5..687f977 100644 --- a/+vis/checker3.m +++ b/+vis/checker3.m @@ -4,7 +4,6 @@ elem = t.Node.Net.subscriptableOrigin('checker'); -% defRectSize = [10 10]; %% make initial layers to be used as templates maskTemplate = vis.emptyLayer(); maskTemplate.isPeriodic = false; diff --git a/+vis/grating.m b/+vis/grating.m index 3af2df5..2785437 100644 --- a/+vis/grating.m +++ b/+vis/grating.m @@ -10,6 +10,8 @@ grating = 'sinusoid'; end elem = t.Node.Net.subscriptableOrigin('gabor'); +elem.grating = grating; +elem.window = window; elem.azimuth = 0; elem.altitude = 0; elem.sigma = [10 10]; @@ -20,50 +22,48 @@ elem.show = false; elem.layers = elem.map(@makeLayers).flattenStruct(); +end + +function layers = makeLayers(newelem) +%% make a grating layer of the specified type +switch lower(newelem.grating) + case {'sinusoid' 'sine' 'sin'} + [gratingLayer, gratingImg] = vis.sinusoidLayer(newelem.azimuth,... + newelem.spatialFreq, newelem.phase, newelem.orientation); + gratingLayer.textureId = 'sinusoidGrating'; + case {'squarewave' 'square' 'sq'} + [gratingLayer, gratingImg] = vis.squareWaveLayer(newelem.azimuth,... + newelem.spatialFreq, newelem.phase, newelem.orientation); + gratingLayer.textureId = 'squareWaveGrating'; + otherwise + error('Invalid grating type ''%s''', grating); +end +[gratingLayer.rgba, gratingLayer.rgbaSize] = vis.rgba(gratingImg, 1); +gratingLayer.blending = 'destination'; +l = 0.5 - 0.5*newelem.contrast; +h = 0.5 + 0.5*newelem.contrast; +gratingLayer.minColour = l.*[1 1 1 0]; +gratingLayer.maxColour = [h.*ones(1, 3) 1]; +gratingLayer.show = newelem.show; - function layers = makeLayers(newelem) - clear elem t; % eliminate references to unsed outer variables - %% make a grating layer of the specified type - switch lower(grating) - case {'sinusoid' 'sine' 'sin'} - [gratingLayer, gratingImg] = vis.sinusoidLayer(newelem.azimuth,... - newelem.spatialFreq, newelem.phase, newelem.orientation); - gratingLayer.textureId = 'sinusoidGrating'; - case {'squarewave' 'square' 'sq'} - [gratingLayer, gratingImg] = vis.squareWaveLayer(newelem.azimuth,... - newelem.spatialFreq, newelem.phase, newelem.orientation); - gratingLayer.textureId = 'squareWaveGrating'; - otherwise - error('Invalid grating type ''%s''', grating); - end - [gratingLayer.rgba, gratingLayer.rgbaSize] = vis.rgba(gratingImg, 1); - gratingLayer.blending = 'destination'; - l = 0.5 - 0.5*newelem.contrast; - h = 0.5 + 0.5*newelem.contrast; - gratingLayer.minColour = l.*[1 1 1 0]; - gratingLayer.maxColour = [h.*ones(1, 3) 1]; - gratingLayer.show = newelem.show; - - %% make a stencil layer using a window of the specified type - if ~strcmpi(window, 'none') - switch lower(window) - case {'gaussian' 'gauss'} - [winLayer, winImg] = vis.gaussianLayer(... - [newelem.azimuth; newelem.altitude], newelem.sigma); - winLayer.textureId = 'gaussianStencil'; - otherwise - error('Invalid window type ''%s''', window); - end - [winLayer.rgba, winLayer.rgbaSize] = vis.rgba(0, winImg); - winLayer.blending = 'none'; - winLayer.colourMask = [false false false true]; - winLayer.show = newelem.show; - else % no window - winLayer = []; - end - - % window layer rendered first like a stencil - layers = [winLayer, gratingLayer]; +%% make a stencil layer using a window of the specified type +if ~strcmpi(newelem.window, 'none') + switch lower(newelem.window) + case {'gaussian' 'gauss'} + [winLayer, winImg] = vis.gaussianLayer(... + [newelem.azimuth; newelem.altitude], newelem.sigma); + winLayer.textureId = 'gaussianStencil'; + otherwise + error('Invalid window type ''%s''', window); end + [winLayer.rgba, winLayer.rgbaSize] = vis.rgba(0, winImg); + winLayer.blending = 'none'; + winLayer.colourMask = [false false false true]; + winLayer.show = newelem.show; +else % no window + winLayer = []; +end +% window layer rendered first like a stencil +layers = [winLayer, gratingLayer]; end \ No newline at end of file diff --git a/+vis/rgba.m b/+vis/rgba.m index f4feb2e..5de23b1 100644 --- a/+vis/rgba.m +++ b/+vis/rgba.m @@ -10,7 +10,7 @@ alpha = uint8(round(255*alpha)); if ~isscalar(colour) && size(colour, 3) == 1 % overall luminance specified - colour = repmat(colour, 1, 1, 3); % replicate to rgb + colour = repmat(colour, [1, 1, 3]); % replicate to rgb end img = zeros(h, w, 4, 'uint8');