-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsg_cylinder.m
65 lines (48 loc) · 1.37 KB
/
sg_cylinder.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
function cylinder = sg_cylinder(dims,radius,height,sigma,center)
%% sg_cylinder
% Geneate a cylinder with gaussian tapering. Sigma can be provided as a 2
% element array to define different sigma for radius and height tapering,
% respectively.
%
% WW 09-2018
%% Check check
% Check dimensions
n_dims = numel(dims);
if n_dims == 1
dims = [dims,dims,dims];
elseif n_dims ~= 3
error('ACHTUNG!!! Invalid number of dimensions!!!');
end
% Check centers
if nargin < 5
center = floor(dims./2)+1;
end
if numel(center) == 1
center = [center,center,center];
elseif numel(center) ~= 3
error('ACHTUNG!!! Invalid center dimensions!!!');
end
% Check sigma
if (nargin == 3) || isempty(sigma)
sigma = [0,0];
elseif numel(sigma) == 1
sigma = [sigma,sigma];
end
%% Calculate height window
% Z-distance
dist_z = abs((1:dims(3))-center(3));
% Calculate hard window
window_z = double(dist_z <= (height/2));
% Apply taper
if sigma(2)~=0 && ~isempty(sigma)
sigma_idx = dist_z > (height/2);
window_z(sigma_idx) = exp(-((dist_z(sigma_idx)-(height/2))/sigma(2)).^2);
window_z(window_z < exp(-2)) = 0;
end
% Project to 3D
window_3d = repmat(permute(window_z,[3,1,2]),[dims(1),dims(2),1]);
%% Generate cylinder
% Calculate circle
circle = sg_circle(dims(1:2),radius,sigma(1),center(1:2));
% Generate cylinder
cylinder = repmat(circle,[1,1,dims(3)]).*window_3d;