0001 function h = show_3d_slices(img, varargin);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0022
0023 ok= 0;
0024 try; if strcmp(img.type, 'image');
0025 ok = 1;
0026 end; end
0027 if ~ok;
0028 error('EIDORS: show_3d_slices requires image as first parameter');
0029 end
0030 if size(img.fwd_model.elems,2) == 3;
0031 img = fake_3d_model( img );
0032 end
0033
0034
0035 img = data_mapper(img);
0036
0037 qfi = warning('query','EIDORS:FirstImageOnly');
0038
0039 elem_data = get_img_data(img);
0040
0041 if size(elem_data,2) > 1
0042 q = warning('query','backtrace');
0043 warning('backtrace','off');
0044 warning('EIDORS:FirstImageOnly','show_3d_slices only shows first image');
0045 warning('backtrace',q.state);
0046 warning('off','EIDORS:FirstImageOnly');
0047 end
0048
0049
0050 img.fwd_model.boundary = find_boundary(img.fwd_model);
0051
0052
0053 [jnk,ref_lev,max_scale] = scale_for_display( elem_data);
0054 try
0055 img.calc_colours.ref_level;
0056 catch
0057 img.calc_colours.ref_level = ref_lev;
0058 end
0059 try
0060 img.calc_colours.clim;
0061 catch
0062 img.calc_colours.clim = max_scale;
0063 end
0064 try
0065 np = img.calc_colours.npoints;
0066 catch
0067 np = calc_colours('npoints');
0068 end
0069
0070 [x_cuts, y_cuts, z_cuts, any_cuts] = get_cuts(img,varargin{:});
0071
0072 hz = []; hy = []; hx = []; ha = [];
0073 for i= 1:length(z_cuts)
0074 hz(i) = show_slice(img,[inf inf z_cuts(i)]);
0075 hold on
0076 end
0077
0078 for i= 1:length(x_cuts)
0079 hx(i) = show_slice(img,[x_cuts(i) inf inf]);
0080 hold on
0081 end
0082
0083 for i= 1:length(y_cuts)
0084 hy(i) = show_slice(img,[inf y_cuts(i) inf]);
0085 hold on
0086 end
0087
0088 for i= 1:size(any_cuts,1)
0089 ha(i) = show_slice(img,any_cuts(i,:));
0090 hold on
0091 end
0092 hold off
0093
0094 if nargout > 0
0095 h = {hz,hx,hy,ha};
0096 end
0097
0098 warning(qfi.state,'EIDORS:FirstImageOnly');
0099
0100 function h = show_slice(img, level)
0101 slc = mdl_slice_mesher(img,level);
0102 try slc.calc_colours = img.calc_colours; end
0103 h = show_fem(slc);
0104
0105
0106 function img = fake_3d_model( img );
0107 fmdl = img.fwd_model;
0108 fnodes = fmdl.nodes;
0109 felems = fmdl.elems;
0110 maxd = max( max(fnodes) - min(fnodes) );
0111 upd = 0.1*maxd;
0112 Nn = num_nodes(fmdl);
0113 Ne = num_elems(fmdl);
0114 fmdn = fmdl;
0115 fmdn.nodes =[[fnodes,-upd+0*fnodes(:,1)];
0116 [fnodes,+upd+0*fnodes(:,1)]];
0117 for i=1:num_elecs(fmdl)
0118 eni = fmdn.electrode(i).nodes;
0119 fmdn.electrode(i).nodes = [eni(:);eni(:)+Nn]';
0120 if isempty(eni) && isfield(fmdn.electrode(i),'faces')
0121 eni = unique(fmdn.electrode(i).faces);
0122 fmdn.electrode(i).nodes = [eni(:);eni(:)+Nn]';
0123 end
0124 end
0125 if isfield(fmdn.electrode,'faces');
0126 fmdn.electrode = rmfield(fmdn.electrode,'faces');
0127 end
0128
0129 fmdn.elems =[[felems(:,[1,2,3]), felems(:,[1 ])+Nn];
0130 [felems(:,[ 2,3]), felems(:,[1,2 ])+Nn];
0131 [felems(:,[ 3]), felems(:,[1,2,3])+Nn]];
0132 ed= img.elem_data;
0133 if isfield(fmdl,'coarse2fine');
0134 c2f = fmdl.coarse2fine;
0135 fmdn.coarse2fine = [c2f;c2f;c2f];
0136 img.fwd_model = fmdn;
0137 else
0138 img = mk_image(fmdn,[ed;ed;ed]);
0139 end
0140
0141
0142 function [x_cuts, y_cuts, z_cuts, any_cuts] = get_cuts(img, varargin)
0143 mdl_max= max(img.fwd_model.nodes);
0144 mdl_min= min(img.fwd_model.nodes);
0145 any_cuts = [];
0146 if nargin==1;
0147
0148 x_cuts= linspace(mdl_min(1), mdl_max(1), 3); x_cuts([1,3])=[];
0149 y_cuts= linspace(mdl_min(2), mdl_max(2), 3); y_cuts([1,3])=[];
0150 z_cuts= linspace(mdl_min(3), mdl_max(3), 4); z_cuts([1,4])=[];
0151 elseif nargin==2;
0152 z_cuts= varargin{1};
0153 x_cuts= [];
0154 y_cuts= [];
0155 elseif nargin==3;
0156 z_cuts= varargin{1};
0157 x_cuts= varargin{2};
0158 y_cuts= [];
0159 elseif nargin==4;
0160 z_cuts= varargin{1};
0161 x_cuts= varargin{2};
0162 y_cuts= varargin{3};
0163 elseif nargin==5;
0164 z_cuts= varargin{1};
0165 x_cuts= varargin{2};
0166 y_cuts= varargin{3};
0167 any_cuts= varargin{4};
0168 else
0169 error('too many inputs');
0170 end
0171
0172
0173
0174 function do_unit_test
0175 imdl = mk_common_model('n3r2',[16,2]);
0176 img = mk_image(imdl,1); vh= fwd_solve(img);
0177 load datacom.mat A B;
0178 img.elem_data(A) = 1.2;
0179 img.elem_data(B) = 0.8;
0180 vi = fwd_solve(img);
0181 imgr = inv_solve(imdl, vh, vi);
0182 imgr.calc_colours.npoints =64;
0183 show_3d_slices(img);
0184 calc_colours('transparency_thresh', 0.25);
0185 show_3d_slices(imgr,[1.5,2],[],[]);
0186
0187 subplot(4,4,1); show_3d_slices(imgr,[1,2],0,0.5);
0188 subplot(4,4,2); show_3d_slices(img ,[1,2],0,0.5);
0189 cuts = [inf, -2.5, 1.5; inf, 10, 1.5];
0190 subplot(4,4,3); show_3d_slices(img ,[],[],[],cuts );
0191
0192 imgr.calc_colours.transparency_thresh = -1;
0193 img.calc_colours.transparency_thresh = -1;
0194 subplot(4,4,4); show_3d_slices(imgr,[1,2],0.3,0.7);
0195 subplot(4,4,5);
0196 show_fem(img.fwd_model);
0197 hold on
0198 show_3d_slices(img ,[1,2],0.3,0.7);
0199 axis off
0200
0201 subplot(4,4,6);
0202 img.elem_data = img.elem_data*[0,1];
0203 img.get_img_data.frame_select = 2;
0204 show_3d_slices(img ,[1],[],[]);
0205
0206 view(10,18);
0207
0208
0209 subplot(4,4,7);
0210 imgs = img; ed = img.elem_data(:,1);
0211 imgs.elem_data= [1;1.2;0.8]*[1];
0212 imgs.fwd_model.coarse2fine = [ed == img.elem_data(1),
0213 ed == img.elem_data(2),
0214 ed == img.elem_data(3)];
0215 show_3d_slices(img,[1,2],0,0.7);
0216
0217 subplot(4,4,8);
0218 show_3d_slices(img,[1],[],[],[1,1,1]);
0219
0220
0221 subplot(4,4,9);
0222 vopt.imgsz = [10,10,10];
0223
0224
0225 [img.fwd_model,tmp] = mk_voxel_volume(imdl.fwd_model,vopt);
0226 img.fwd_model.coarse2fine = (tmp.coarse2fine * ...
0227 img.fwd_model.coarse2fine')';
0228 show_3d_slices(img,[1,2],0,0.5);
0229
0230 subplot(4,4,10);
0231 fmdl = getfield(mk_common_model('a2C2',4),'fwd_model');
0232 fmdl.mat_idx{1} = 1:4;
0233 fmdl = mat_idx_to_electrode(fmdl,{1});
0234 img= mk_image(fmdl,1);
0235 show_3d_slices(img,[0])
0236
0237 subplot(4,4,11);
0238 img.fwd_model.electrode(1).faces=[28,29;29,30;30,31];
0239 show_3d_slices(img,[0])
0240
0241 subplot(4,4,12)
0242
0243 imdl = mk_common_model('a2c0',8); img= mk_image(imdl);
0244 img.elem_data([10,12]) = 1.1;
0245 show_3d_slices(img,[0],[0.2],[0]);
0246
0247
0248 subplot(4,4,13)
0249
0250 ed = img.elem_data;
0251 img.fwd_model.coarse2fine = [ed==1, ed> 1];
0252 img.elem_data= [1;1.1];
0253 show_3d_slices(img,[0],[0.2],[0]);
0254
0255 subplot(4,4,14)
0256
0257 extra={'ball','solid ball = sphere(0.5,0.5,1;0.1);'};
0258 fmdl= ng_mk_cyl_models(2,[4,1],[0.2],extra);
0259 fmdl.mat_idx_to_electrode.nodes_electrode = true;
0260 fmdl= mat_idx_to_electrode(fmdl,{2});
0261 show_3d_slices(mk_image(fmdl,1),[1.0],[0.5],[0.5]);
0262
0263 subplot(4,4,15)
0264
0265 extra={'ball','solid ball = sphere(0.5,0.5,1;0.1);'};
0266 fmdl= ng_mk_cyl_models(2,[4,1],[0.2],extra);
0267 fmdl.mat_idx_to_electrode.nodes_electrode = false;
0268 fmdl= mat_idx_to_electrode(fmdl,{2});
0269 show_3d_slices(mk_image(fmdl,1),[1.0],[0.5],[0.5]);