function volume_visualization_gui(volume)
if nargin<1
volume = load('fluidtemp.mat','temp');
volume = volume.temp;
end
fmar = [0.2 0.2];
amar = [0.05 0.1];
menw = 0.045;
div = 0.005;
adim = 0.5*(1-3*amar-2*[menw+div 0]);
menh = adim(2)/7;
axepos = [2*amar+adim+[menw+div,0];...
2*amar(1)+adim(1)+menw+div,amar(2);...
amar];
menpos = [2*(amar(1)+adim(1)+div)+menw,2*amar(2)+adim(2);...
2*(amar(1)+adim(1)+div)+menw,amar(2);...
amar+[adim(1)+div,0]];
dim = size(volume);
clim = [min(volume(:)),max(volume(:))];
POINT = round(0.5*(dim+1));
COLORS = set_colors(false);
[box,FRAMES] = make_patches(dim);
xyz = 'xyz';
linewidth = 2;
fig = figure('Units','Normalized','Position',[fmar,1-2*fmar],...
'KeyPressFcn',@key_press);
menustr = {'end','+10','+1','mid','-1','-10','1'};
xyz_axes = cell(3,1);
for i=1:3
xyz_axes{i} = axes('Units','Normalized','Position',[axepos(i,:),adim]);
show_XYZ(i), axis image xy off, colormap gray, hold on
for j=1:7
uicontrol('Style','pushbutton','String',menustr{j},...
'UserData',[i,j],'Units','Normalized',...
'Position',[menpos(i,:)+[0,(j-1)*menh],menw,menh],...
'Callback',@button_click);
end
end
frames_axes = axes('Units','Normalized','Projection','perspective',...
'Position',[amar(1),2*amar(2)+adim(2),adim]);
show_frames, axis vis3d equal off, view(20,15)
set(zoom(fig),'ActionPostCallback',@adjust_limits)
set(pan(fig),'ActionPostCallback',@adjust_limits)
function key_press(~,object)
if any(strcmp(object.Modifier,'shift'))
minus_move = 7;
plus_move = 1;
else
minus_move = 5;
plus_move = 3;
end
switch object.Key
case 'leftarrow'
move_slice(1,minus_move)
case 'rightarrow'
move_slice(1,plus_move)
case 'pageup'
move_slice(2,minus_move)
case 'pagedown'
move_slice(2,plus_move)
case 'downarrow'
move_slice(3,minus_move)
case 'uparrow'
move_slice(3,plus_move)
case 'space'
COLORS = set_colors(~COLORS.color_axes);
for k=1:3
show_XYZ(k);
end
show_frames
end
end
function button_click(source,~)
ij = get(source,'UserData');
move_slice(ij(1),ij(2));
end
function adjust_limits(~,~)
cw = [1,2,4,3];
ccw = [1,3,2,4];
FRAMES{1}.vertices(ccw,2) = repmat(get(xyz_axes{1},'XLim'),[1,2]);
FRAMES{1}.vertices(cw,3) = repmat(get(xyz_axes{1},'YLim'),[1,2]);
FRAMES{2}.vertices(cw,1) = repmat(get(xyz_axes{2},'XLim'),[1,2]);
FRAMES{2}.vertices(ccw,3) = repmat(get(xyz_axes{2},'YLim'),[1,2]);
FRAMES{3}.vertices(ccw,1) = repmat(get(xyz_axes{3},'XLim'),[1,2]);
FRAMES{3}.vertices(cw,2) = repmat(get(xyz_axes{3},'YLim'),[1,2]);
for k=1:3
show_XYZ(k);
end
show_frames
end
function move_slice(k,d)
switch d
case 1
POINT(k) = dim(k);
case 2
POINT(k) = min(POINT(k)+10,dim(k));
case 3
POINT(k) = min(POINT(k)+1,dim(k));
case 4
POINT(k) = round(0.5*(dim(k)+1));
case 5
POINT(k) = max(POINT(k)-1,1);
case 6
POINT(k) = max(POINT(k)-10,1);
case 7
POINT(k) = 1;
end
FRAMES{k}.vertices(:,k) = POINT(k);
show_XYZ(k);
show_frames
end
function show_XYZ(k)
axes(xyz_axes{k}), cla
switch k
case 1
imagesc(permute(volume(POINT(k),:,:),[3,2,1]),clim)
case 2
imagesc(permute(volume(:,POINT(k),:),[3,1,2]),clim);
case 3
imagesc(permute(volume(:,:,POINT(k)),[2,1,3]),clim);
end
patch('Faces',1:4,'Vertices',...
FRAMES{k}.vertices(:,setdiff(1:3,k)),...
'FaceColor','none','EdgeColor',COLORS.edge_color{k},...
'FaceVertexCData',COLORS.cdata{k},'LineWidth',linewidth)
title([xyz(k),'=',num2str(POINT(k))])
end
function show_frames
axes(frames_axes), cla
patch(box,'FaceColor','none','EdgeColor',[0.3,0.3,0.3]);
for k=1:3
patch(FRAMES{k},...
'FaceColor','none','EdgeColor',COLORS.edge_color{k},...
'FaceVertexCData',COLORS.cdata{k},'LineWidth',linewidth);
end
end
function [box,patch_xyz] = make_patches(dim)
box.vertices = [0 0 0; 0 0 1; 0 1 0; 0 1 1; 1 0 0; 1 0 1;...
1 1 0; 1 1 1]*diag(dim)+0.5;
box.faces = [1 2 4 3; 3 4 8 7; 1 3 7 5; 2 6 8 4; 1 5 6 2; 5 7 8 6];
patch_xyz = cell(3,1);
for l=1:3
patch_xyz{l}.vertices = box.vertices(box.faces(l,:),:);
patch_xyz{l}.faces = [1 2 3 4];
patch_xyz{l}.vertices(:,l) = (dim(l)+1)/2;
end
end
function colors = set_colors(color_flag)
colors.color_axes = color_flag;
if color_flag
col = repmat([0;0;0.5;0.5],[1,3]);
colors.cdata = {col,col,col};
for k=1:3
colors.cdata{k}(:,k) = [1;0.5;0.5;1];
colors.edge_color{k} = 'interp';
end
else
col = [0,0,0];
colors.edge_color = {col,col,col};
for k=1:3
colors.edge_color{k}(k) = 1;
colors.cdata{k} = [];
end
end
end
end