0001 function show_3d_slices(img, varargin);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if isstr(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0013
0014 cla;
0015 hold on
0016
0017 [xyz_max, xyz_min, rimg, cimg, ...
0018 x_cuts, y_cuts, z_cuts] = get_slices(img, varargin{:});
0019
0020 for zi= 1:length(z_cuts)
0021 M_trans= [1,0;0,1;0,0];
0022 M_add= [0,0,z_cuts(zi)];
0023 idx= zi;
0024 surf_slice(rimg(:,:,idx), cimg(:,:,idx), xyz_min, xyz_max, ...
0025 M_trans, M_add, 1);
0026 end
0027
0028 for xi= 1:length(x_cuts)
0029 M_trans= [0,0;1,0;0,1];
0030 M_add= [x_cuts(xi),0,0];
0031 idx= length(z_cuts) + xi;
0032 surf_slice(rimg(:,:,idx), cimg(:,:,idx), xyz_min, xyz_max, ...
0033 M_trans, M_add, 1);
0034 end
0035
0036 for yi= 1:length(y_cuts)
0037 M_trans= [1,0;0,0;0,1];
0038 M_add= [0,y_cuts(yi),0];
0039 idx= length(z_cuts) + length(x_cuts) + yi;
0040 surf_slice(rimg(:,:,idx), cimg(:,:,idx), xyz_min, xyz_max, ...
0041 M_trans, M_add, 1);
0042 end
0043
0044 hold off
0045
0046 function [xyz_max, xyz_min, rimg, cimg, ...
0047 x_cuts, y_cuts, z_cuts] = get_slices(img, varargin);
0048 xyz_max= max(img.fwd_model.nodes);
0049 xyz_min= min(img.fwd_model.nodes);
0050 if nargin==1;
0051
0052 x_cuts= linspace(xyz_min(1), xyz_max(1), 3); x_cuts([1,3])=[];
0053 y_cuts= linspace(xyz_min(2), xyz_max(2), 3); y_cuts([1,3])=[];
0054 z_cuts= linspace(xyz_min(3), xyz_max(3), 4); z_cuts([1,4])=[];
0055 elseif nargin==2;
0056 z_cuts= varargin{1};
0057 x_cuts= [];
0058 y_cuts= [];
0059 elseif nargin==3;
0060 z_cuts= varargin{1};
0061 x_cuts= varargin{2};
0062 y_cuts= [];
0063 elseif nargin==4;
0064 z_cuts= varargin{1};
0065 x_cuts= varargin{2};
0066 y_cuts= varargin{3};
0067 else
0068 error('too many inputs');
0069 end
0070
0071 limts= [ z_cuts(:)*[inf,inf,1 ]; ...
0072 x_cuts(:)*[1 ,inf,inf]; ...
0073 y_cuts(:)*[inf,1 ,inf]];
0074
0075 rimg0= calc_slices( img, limts);
0076
0077 rimg= NaN*ones(size(rimg0,1)+4,size(rimg0,2)+4,size(limts,1));
0078 rimg(3:end-2,3:end-2,:)= rimg0;
0079 cimg = calc_colours( rimg, img);
0080
0081 function xyz= linspace_plus4(lim_min, lim_max, np);
0082 ooo= ones(length(lim_min),1);
0083 delta = lim_max(:)-lim_min(:);
0084 delta = max(delta)*ones(size(delta));
0085 middle=(lim_max(:)+lim_min(:))/2;
0086 xyz= middle(:)*ones(1,np+4) + ...
0087 delta/(np-1)*[-(np+3)/2:(np+3)/2];
0088
0089
0090
0091 function surf_slice(rimg, cimg, xyz_min, xyz_max, M_trans, M_add, show_surf);
0092 np= size(rimg,1)-4;
0093 lim_min= xyz_min*M_trans;
0094 lim_max= xyz_max*M_trans;
0095 xyz= linspace_plus4( lim_min, lim_max, np);
0096 [x,y]= meshgrid(xyz(1,:),xyz(2,:));
0097 xyz= reshape( [x(:),y(:)]*M_trans', np+4,np+4,3);
0098
0099 ff=isnan(rimg);
0100 bdr= (conv2(double(~ff),ones(3),'same')>0) & ff;
0101 outbdr = ff & ~bdr;
0102
0103 ver = eidors_obj('interpreter_version');
0104 if ver.isoctave ==0 && ver.is64bit
0105 eidors_msg(['Poor you. You''re using a 64 bit version of matlab. ' ...
0106 'Unfortunately, these versions have serious graphics ' ...
0107 'bugs and we can''t show a nice image. Sorry. ' ...
0108 'Please bug Mathworks for a fix (good luck!).'],0);
0109 else
0110 cimg(outbdr)= NaN;
0111 end
0112
0113 if show_surf
0114 hh=surf(xyz(:,:,1)+M_add(1), ...
0115 xyz(:,:,2)+M_add(2), ...
0116 xyz(:,:,3)+M_add(3), flipud(cimg));
0117
0118 set(hh,'EdgeAlpha',0);
0119
0120
0121
0122
0123 set(hh,'CDataMapping','direct');
0124 end
0125
0126
0127
0128
0129 function draw_line_around(cimg, rimg, x,y, M_trans, M_add);
0130
0131
0132
0133
0134
0135
0136 cimg(isnan(rimg))= -1e50;
0137 [jnk,hh]=contour(x,y,cimg, [-1e49,-1e49]);
0138 Contour_paths = M_trans*[ get(hh,'Xdata'), ...
0139 get(hh,'Ydata') ]';
0140 set(hh,'EdgeColor',[0,0,0], ...
0141 'Xdata', Contour_paths(1,:) + M_add(1), ...
0142 'Ydata', Contour_paths(2,:) + M_add(2), ...
0143 'Zdata', Contour_paths(3,:) + M_add(3));
0144
0145 function do_unit_test
0146 img = mk_image(mk_common_model('n3r2',16),1);
0147 show_3d_slices(img,[1,2],0,0.5);
0148 view(10,18);