-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmp2rage_display_volume.m
48 lines (36 loc) · 1.43 KB
/
mp2rage_display_volume.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
function V = mp2rage_display_volume(V,Y)
%MP2RAGE_DISPLAY_VOLUME will write a volume in a temporary file, and
%display it using SPM image display.
%
% INPUT
% - V is a structure, output of V = spm_vol('path/to/volume.nii')
% - Y is a 3D cube, output of Y = spm_read_vols(V)
% this is the cube==image you want to display
%
% OUTPUT
% - V is the updated V input, modified by spm_write_vol if necessary
%
% see also spm_vol spm_read_vols tempname spm_write_vol spm_image spm_orthviews
%% Initialazation : get or set temporary file name
persistent tmpvolname
global st % this is SPM variable containing all information about the orthview, including the volume.
if isempty(tmpvolname) % First call, create a temporary file name
tmpvolname = [tempname '.nii'] ; % generate a temporary nifti name
end
V.fname = tmpvolname;
%% Write volume
% Write in the temporary volume the new "cube" Y
assert( logical( strfind(V.fname,tempdir) ), 'Something went wring, the temporary volume is not in tempdir' ) % security
V = spm_write_vol(V,Y);
%% Display volume
if isempty(st)
spm_image('Display', V.fname); % Initialize the display
else
if isempty(st.vols{1})
spm_image('Display', V.fname); % Initialize the display
else
pos = spm_orthviews('Pos'); % Get last cursor position
spm_orthviews('Reposition',pos); % Refresh the display @ last cursor position (it will load the freshly written volume)
end
end
end % function