summaryrefslogtreecommitdiffstats
path: root/matlab/tools/astra_geom_visualize.m
blob: 0044844a621541abb8405ad7837062ed6dfdb93f (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
function astra_geom_visualize(proj_geom, vol_geom)

	if strcmp(proj_geom.type,'parallel') ||  strcmp(proj_geom.type,'fanflat') ||strcmp(proj_geom.type,'parallel3d') ||  strcmp(proj_geom.type,'cone')
		proj_geom = astra_geom_2vec(proj_geom);
	end

	% open window
	f = figure('Visible','off');
	hold on

	% display projection 1
	displayProjection(1);

	% label
	txt = uicontrol('Style','text', 'Position',[10 10 70 20], 'String','Projection');

	% slider
	anglecount = size(proj_geom.Vectors,1);
	sld = uicontrol('Style', 'slider', ...
		'Min', 1, 'Max', anglecount, 'SliderStep', [1 1]/anglecount, 'Value', 1, ...
		'Position', [80 10 200 20], ...
		'Callback', @updateProjection); 

	f.Visible = 'on';

    function updateProjection(source, callbackdata)
		displayProjection(floor(source.Value));
    end

    function displayProjection(a)

		colours = get(gca,'ColorOrder');

    	
    	% set title
    	title(['projection ' num2str(a)]);

		if strcmp(proj_geom.type,'parallel_vec')

			v = proj_geom.Vectors;
			d = proj_geom.DetectorCount;

			if ~isfield(vol_geom, 'option')
				minx = -vol_geom.GridRowCount/2;
				miny = -vol_geom.GridColCount/2;
				minz = -vol_geom.GridSliceCount/2;
				maxx = vol_geom.GridRowCount/2;
			else
				minx = vol_geom.option.WindowMinX;
				miny = vol_geom.option.WindowMinY;
				maxx = vol_geom.option.WindowMaxX;
				maxy = vol_geom.option.WindowMaxY;
			end
		
			% axis
			cla
			axis([minx maxx miny maxy]*2.25)
			axis square

			% volume
			plot([minx minx maxx maxx minx], [miny maxy maxy miny miny], 'LineWidth', 1, 'Color', colours(1,:))

			% ray
			s = maxx - minx;
			plot([0 v(a,1)]*s*0.33, [0 v(a,2)]*s*0.33, 'LineWidth', 2, 'Color', colours(3,:))

			% detector
			s2 = s*0.75;
			plot([-d/2 d/2]*v(a,5) + v(a,3) + s2*v(a,1), [-d/2 d/2]*v(a,6) + v(a,4) + s2*v(a,2), 'LineWidth', 2, 'Color', colours(5,:))

		elseif strcmp(proj_geom.type,'fanflat_vec')

			v = proj_geom.Vectors;
			d = proj_geom.DetectorCount;

			if ~isfield(vol_geom, 'option')
				minx = -vol_geom.GridRowCount/2;
				miny = -vol_geom.GridColCount/2;
				minz = -vol_geom.GridSliceCount/2;
				maxx = vol_geom.GridRowCount/2;
			else
				minx = vol_geom.option.WindowMinX;
				miny = vol_geom.option.WindowMinY;
				maxx = vol_geom.option.WindowMaxX;
				maxy = vol_geom.option.WindowMaxY;
			end

			% axis
			cla
			axis([minx maxx miny maxy]*2.25)
			axis square

			% volume
			plot([minx minx maxx maxx minx], [miny maxy maxy miny miny], 'LineWidth', 1, 'Color', colours(1,:))

			% detector
			D1 = v(a,3:4) - d/2*v(a,5:6);
			D2 = v(a,3:4) + d/2*v(a,5:6);
			plot([D1(1) D2(1)], [D1(2) D2(2)], 'LineWidth', 2, 'Color', colours(5,:))

			% beam
			plot([v(a,1) D1(1)], [v(a,2) D1(2)], 'LineWidth', 1, 'Color', colours(3,:))
			plot([v(a,1) D2(1)], [v(a,2) D2(2)], 'LineWidth', 1, 'Color', colours(3,:))

		elseif strcmp(proj_geom.type,'parallel3d_vec')

			v = proj_geom.Vectors;
			d1 = proj_geom.DetectorRowCount;
			d2 = proj_geom.DetectorColCount;

			if ~isfield(vol_geom, 'option')
				minx = -vol_geom.GridRowCount/2;
				miny = -vol_geom.GridColCount/2;
				minz = -vol_geom.GridSliceCount/2;
				maxx = vol_geom.GridRowCount/2;
				maxy = vol_geom.GridColCount/2;
				maxz = vol_geom.GridSliceCount/2;
			else
				minx = vol_geom.option.WindowMinX;
				miny = vol_geom.option.WindowMinY;
				minz = vol_geom.option.WindowMinZ;
				maxx = vol_geom.option.WindowMaxX;
				maxy = vol_geom.option.WindowMaxY;
				maxz = vol_geom.option.WindowMaxZ;
			end

			% axis
			windowminx = min(v(:,4));
			windowminy = min(v(:,5));
			windowminz = max(v(:,6));
			windowmaxx = max(v(:,4));
			windowmaxy = max(v(:,5));
			windowmaxz = max(v(:,6));
			cla
			axis([minx maxx miny maxy minz maxz]*5.10)

			% volume
			plot3([minx minx maxx maxx minx], [miny maxy maxy miny miny], [minz minz minz minz minz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([minx minx maxx maxx minx], [miny maxy maxy miny miny], [maxz maxz maxz maxz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([minx minx], [miny miny], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([maxx maxx], [miny miny], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([minx minx], [maxy maxy], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([maxx maxx], [maxy maxy], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))

			% detector
			D1 = v(a,4:6) - d1/2*v(a,7:9) - d2/2*v(a,10:12);
			D2 = v(a,4:6) + d1/2*v(a,7:9) - d2/2*v(a,10:12);
			D3 = v(a,4:6) + d1/2*v(a,7:9) + d2/2*v(a,10:12);
			D4 = v(a,4:6) - d1/2*v(a,7:9) + d2/2*v(a,10:12);
			plot3([D1(1) D2(1) D3(1) D4(1) D1(1)], [D1(2) D2(2) D3(2) D4(2) D1(2)], [D1(3) D2(3) D3(3) D4(3) D1(3)], 'LineWidth', 2, 'Color', colours(5,:))

			% ray
			s = maxx - minx;
			plot3([0 v(a,1)]*s*0.30, [0 v(a,2)]*s*0.30, [0 v(a,3)]*s*0.30, 'LineWidth', 2, 'Color', colours(3,:))

		elseif strcmp(proj_geom.type,'cone_vec')

			v = proj_geom.Vectors;
			d1 = proj_geom.DetectorRowCount;
			d2 = proj_geom.DetectorColCount;

			if ~isfield(vol_geom, 'option')
				minx = -vol_geom.GridRowCount/2;
				miny = -vol_geom.GridColCount/2;
				minz = -vol_geom.GridSliceCount/2;
				maxx = vol_geom.GridRowCount/2;
				maxy = vol_geom.GridColCount/2;
				maxz = vol_geom.GridSliceCount/2;
			else
				minx = vol_geom.option.WindowMinX;
				miny = vol_geom.option.WindowMinY;
				minz = vol_geom.option.WindowMinZ;
				maxx = vol_geom.option.WindowMaxX;
				maxy = vol_geom.option.WindowMaxY;
				maxz = vol_geom.option.WindowMaxZ;
			end

			% axis
			windowminx = min(v(:,4));
			windowminy = min(v(:,5));
			windowminz = max(v(:,6));
			windowmaxx = max(v(:,4));
			windowmaxy = max(v(:,5));
			windowmaxz = max(v(:,6));
			cla
			axis([minx maxx miny maxy minz maxz]*5.10)

			% volume
			plot3([minx minx maxx maxx minx], [miny maxy maxy miny miny], [minz minz minz minz minz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([minx minx maxx maxx minx], [miny maxy maxy miny miny], [maxz maxz maxz maxz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([minx minx], [miny miny], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([maxx maxx], [miny miny], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([minx minx], [maxy maxy], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))
			plot3([maxx maxx], [maxy maxy], [minz maxz], 'LineWidth', 1, 'Color', colours(1,:))

			% detector
			D1 = v(a,4:6) - d1/2*v(a,7:9) - d2/2*v(a,10:12);
			D2 = v(a,4:6) + d1/2*v(a,7:9) - d2/2*v(a,10:12);
			D3 = v(a,4:6) + d1/2*v(a,7:9) + d2/2*v(a,10:12);
			D4 = v(a,4:6) - d1/2*v(a,7:9) + d2/2*v(a,10:12);
			plot3([D1(1) D2(1) D3(1) D4(1) D1(1)], [D1(2) D2(2) D3(2) D4(2) D1(2)], [D1(3) D2(3) D3(3) D4(3) D1(3)], 'LineWidth', 2, 'Color', colours(5,:))

			% beam
			plot3([v(a,1) D1(1)], [v(a,2) D1(2)], [v(a,3) D1(3)], 'LineWidth', 1, 'Color', colours(3,:))
			plot3([v(a,1) D2(1)], [v(a,2) D2(2)], [v(a,3) D2(3)], 'LineWidth', 1, 'Color', colours(3,:))
			plot3([v(a,1) D3(1)], [v(a,2) D3(2)], [v(a,3) D3(3)], 'LineWidth', 1, 'Color', colours(3,:))
			plot3([v(a,1) D4(1)], [v(a,2) D4(2)], [v(a,3) D4(3)], 'LineWidth', 1, 'Color', colours(3,:))


		else
			error('invalid projector type')

		end
    end

end