-
Notifications
You must be signed in to change notification settings - Fork 0
/
grating.m
88 lines (71 loc) · 2.89 KB
/
grating.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
classdef grating < stm_img
properties
orientation = 0; % clockwise rotation in range 0:180, counter-clockwise rotation in range: -180:0.
spatial_frq = 0.02; % cycles per degree
phase = 1/2*pi; % in range 0:2*pi
contrast = 1; % for sine gratings: in range 0:1, for square gratings, set contrast to inf
end
properties (Dependent = true, SetAccess = private, Hidden = true)
cycles
end
properties (Dependent = true, SetAccess = protected, Hidden = true)
tex
end
methods
% construct method:------------------------------------------------
function grating = grating(ori, sf, phase, contrast)
if nargin>1&&~isempty(ori); grating.orientation = ori; end
if nargin>2&&~isempty(sf); grating.spatial_frq = sf; end
if nargin>3&&~isempty(phase); grating.phase = phase; end
if nargin>4&&~isempty(contrast); grating.contrast = contrast; end
end
% set methods:-----------------------------------------------------
function self = set.orientation(self, input)
if numel(input)~=1
error('grating: only scalar orientation is allowed')
else
self.orientation = input;
end
end
function self = set.spatial_frq(self, input)
if numel(input)~=1
error('grating: only scalar spatial frequency is allowed')
else
self.spatial_frq = input;
end
end
function self = set.phase(self, input)
if numel(input)~=1
error('grating: only scalar phase is allowed')
else
self.phase = input;
end
end
function self = set.contrast(self, input)
if numel(input)~=1
error('grating: only scalar contrast is allowed')
else
self.contrast = input;
end
end
% get methods:-----------------------------------------------------
function out = get.cycles(self)
out = self.scr.view_angle(2) *180/pi * self.spatial_frq;
end
function out = get.tex(self)
% Build grating textures:
[~,y] = self.coordinates(self.orientation);
f=self.spatial_frq*360;
m=sin(f*y - self.phase);
inc=mean(self.color.white-self.color.gray)*self.contrast;
out=(mean(self.color.gray)+inc*m);
out(out>self.max_tex)=self.max_tex;
out(out<self.min_tex)=self.min_tex;
end
end
methods (Access = protected) % protected methods can be overridden by subclass
% function tex = fill_tex(grating)
% tex = grating.gen_grating_tex;
% end
end
end