-
Notifications
You must be signed in to change notification settings - Fork 4
/
Cylindrical.m
49 lines (36 loc) · 1.87 KB
/
Cylindrical.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
classdef Cylindrical < ChiDist
properties
R = 5; % radius of sphere in [mm]
theta = 0; % angle between main axis of cylinder and z-axis (in radians)
end
methods
function obj = Cylindrical( matrix, image_res, R, theta, sus )
% Method Spherical (constructor)
% - Call superclass constructor.
obj = obj@ChiDist( matrix, image_res, sus, 'Cylindrical' ) ;
% - Define class properties.
obj.R = R;
obj.theta = theta;
obj.cylindrical();
end
function obj = cylindrical(obj)
% define image grid
[x,y,z] = ndgrid(linspace(-(obj.matrix(1)-1)/2,(obj.matrix(1)-1)/2,obj.matrix(1)),linspace(-(obj.matrix(2)-1)/2,(obj.matrix(2)-1)/2,obj.matrix(2)),linspace(-(obj.matrix(3)-1)/2,(obj.matrix(3)-1)/2,obj.matrix(3)));
% in-plane radial position (in [mm])
r = sqrt((x.*obj.image_res(1)).^2 + (y.*obj.image_res(2)).^2);
obj.volume = zeros(obj.matrix(1), obj.matrix(2), obj.matrix(3));
obj.volume(r <= obj.R ) = obj.sus(1);
obj.volume(r > obj.R ) = obj.sus(2);
% rotate chi distribution about the y-axis
t = [cos(obj.theta) 0 sin(obj.theta) 0
0 1 0 0
-sin(obj.theta) 0 cos(obj.theta) 0
0 0 0 1];
tform = affine3d(t);
obj.volume = imwarp(obj.volume,tform, 'FillValues', obj.sus(2));
% Troncate the rotated volume to the desired size
margins = ((size(obj.volume)-obj.matrix) / 2);
obj.volume = obj.volume(1 + margins(1):margins(1) + obj.matrix(1), 1 + margins(2):margins(2) + obj.matrix(2), 1 + margins(3):margins(3) + obj.matrix(3));
end
end
end