Skip to content

Commit

Permalink
allow keeping x/y/z slice when switching between 4th dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 7, 2023
1 parent 9aaba97 commit ac893cd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
9 changes: 7 additions & 2 deletions utils/image3i.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function h = image3i(im,ij2xyz,handle)
function h = image3i(im,ij2xyz,handle, keepxyz)
% Display a 2-D image in Matlab xyz 3-D space
% h = image3i(C, IJ2XYZ, handle)
%
Expand Down Expand Up @@ -109,6 +109,12 @@
error('Only scalar and RGB images supported')
end

if(nargin>=4 && handle~=0 && keepxyz)
set(handle,'CData',im);
h = handle;
set(gcf,'renderer','opengl');
return;
end

% Create the slice
[uu,vv] = ndgrid(0:stepsize:1, 0:stepsize:1);
Expand All @@ -126,7 +132,6 @@
y = ij2xyz(2,1)*iidx + ij2xyz(2,2)*jidx + + ij2xyz(2,3);
z = ij2xyz(3,1)*iidx + ij2xyz(3,2)*jidx + + ij2xyz(3,3);


if nargin<3 || handle == 0
% Make a new surface
h = surface('XData',x,'YData',y,'ZData',z,...
Expand Down
34 changes: 29 additions & 5 deletions utils/islicer.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function h = islicer(vol,T, varargin)
function h = islicer(vol,T, handles, keepxyz, varargin)
%
% h = islicer(vol);
% or
Expand All @@ -25,9 +25,31 @@
T = eye(4);
end

h1 = slice3i(vol,T,1,round(size(vol,1)/2));
h2 = slice3i(vol,T,2,round(size(vol,2)/2));
h3 = slice3i(vol,T,3,round(size(vol,3)/2));
if(nargin < 3)
handles=[0,0,0];
end

if(nargin < 4)
keepxyz=0;
end

if(handles(1)==0)
h1 = slice3i(vol,T,1,round(size(vol,1)/2),handles(1), keepxyz);
else
h1 = slice3i(vol,T,1,round(min(min(get(handles(1),'xdata')))),handles(1), keepxyz);
end

if(handles(2)==0)
h2 = slice3i(vol,T,2,round(size(vol,2)/2),handles(2), keepxyz);
else
h2 = slice3i(vol,T,2,round(min(min(get(handles(2),'ydata')))),handles(2), keepxyz);
end

if(handles(3)==0)
h3 = slice3i(vol,T,3,round(size(vol,3)/2),handles(3), keepxyz);
else
h3 = slice3i(vol,T,3,round(min(min(get(handles(3),'zdata')))),handles(3), keepxyz);
end

if(nargout>=1)
h = [h1,h2,h3];
Expand All @@ -38,7 +60,9 @@
%colormap(jet(64));

view(3);
set(camlight,'Visible','on')
if(all(handles==0))
set(camlight,'Visible','on')
end

axis equal;

Expand Down
3 changes: 1 addition & 2 deletions utils/mcxplotvol.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ function changeframe(src,event)
end

if(newframe>0 && newframe~=guidata.frame)
delete(guidata.handles);
guidata.handles=islicer(guidata.data(:,:,:,newframe));
guidata.handles=islicer(guidata.data(:,:,:,newframe), eye(4), guidata.handles, 1);
xlabel(sprintf('x (frame=%d of %d)',newframe,size(guidata.data,4)));
guidata.frame=newframe;
set(gca,'UserData',guidata);
Expand Down
16 changes: 12 additions & 4 deletions utils/slice3i.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function h = slice3i(vol, I2X, slicedim, sliceidx, handle)
function h = slice3i(vol, I2X, slicedim, sliceidx, handle, keepxyz)
% Display a slice from a volume in 3-D
% h = slice3(vol, I2X, slicedim, sliceidx, handle)
%
Expand Down Expand Up @@ -36,8 +36,12 @@
% 4) support 4-D data (up/down key to change frames)
%

if(nargin<6)
keepxyz=0;
end

try
h = update_slice(vol, I2X, slicedim, sliceidx, h);
h = update_slice(vol, I2X, slicedim, sliceidx, handle, keepxyz);
catch
h = update_slice(vol, I2X, slicedim, sliceidx);
end
Expand Down Expand Up @@ -152,7 +156,11 @@ function stopmovit(src,evnt)
set(gcf,'UserData',[]);
drawnow;

function h = update_slice(vol, I2X, slicedim, sliceidx, handle)
function h = update_slice(vol, I2X, slicedim, sliceidx, handle, keepxyz)

if(nargin<6)
keepxyz=0;
end

if ndims(vol) == 3 %Scalar mode
elseif ndims(vol) == 4 %RGB mode
Expand Down Expand Up @@ -191,6 +199,6 @@ function stopmovit(src,evnt)
if nargin<5 || handle == 0
h = image3i(sliceim,ij2xyz);
else
h = image3i(sliceim,ij2xyz,handle);
h = image3i(sliceim,ij2xyz,handle, keepxyz);
end

0 comments on commit ac893cd

Please sign in to comment.