Skip to content

Commit

Permalink
vis.grating without nested functions to help with scope issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Burgess committed Apr 1, 2016
1 parent 843f32a commit 9fcc861
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
1 change: 0 additions & 1 deletion +vis/checker3.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
86 changes: 43 additions & 43 deletions +vis/grating.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
2 changes: 1 addition & 1 deletion +vis/rgba.m
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9fcc861

Please sign in to comment.