0001 function out_img= show_slices( img, levels )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0049
0050 sep = 0;
0051 try sep = img(1).show_slices.sep;
0052 end
0053
0054
0055
0056
0057
0058 do_calc_slices = 0;
0059 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end
0060
0061 if nargin<=1;
0062 try
0063 levels = img(1).show_slices.levels;
0064 catch
0065 levels = [];
0066 end
0067 end
0068
0069 if isempty(levels) && do_calc_slices
0070 levels= [Inf,Inf,0];
0071 end
0072
0073 vh = [];
0074 if size(levels,2) == 5
0075 vh = levels(:,4:5);
0076 levels = levels(:,1:3);
0077 elseif size(levels)== [1,1]
0078 if size(img(1).fwd_model.nodes,2) == 2
0079 eidors_msg('Can''t do horizontal slices for 2D model. Showing 2D slice');
0080 levels= [Inf,Inf,0];
0081 else
0082 zmax= max(img(1).fwd_model.nodes(:,3));
0083 zmin= min(img(1).fwd_model.nodes(:,3));
0084 levels = linspace(zmax,zmin, levels+2);
0085 levels = levels(2:end-1)';
0086 levels = [(1+0*levels)*[Inf,Inf], levels];
0087 end
0088 end
0089
0090 if do_calc_slices
0091 rimg= calc_slices( img, levels(:,1:3) );
0092 else
0093 rimg= img;
0094 end
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 n_col = 0;
0106 try n_col = img(1).show_slices.img_cols;
0107 end
0108
0109 r_img = mk_mosaic(rimg, sep, vh, n_col);
0110
0111 c_img = calc_colours( r_img, img);
0112 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0113
0114
0115 axes_msm = false;
0116 try axes_msm = img.show_slices.axes_msm; end
0117
0118 if ~axes_msm
0119 image(out_img);
0120 axis image
0121 axis off
0122 axis equal
0123 axis tight
0124 else
0125 msm = img.fwd_model.mdl_slice_mapper;
0126 image(msm.x_pts, msm.y_pts, out_img);
0127 set(gca,'Ydir','normal');
0128 end
0129
0130
0131 if isfield(img(1),'show_slices') && isfield(img(1).show_slices,'contour_levels');
0132 clevs = img.show_slices.contour_levels;
0133 if isfield(img.show_slices,'contour_properties');
0134 contour_properties = img.show_slices.contour_properties;
0135 else
0136 contour_properties = {'Color',[0.2,0.2,0.3]};
0137 end
0138
0139 if ~axes_msm;
0140 msm.x_pts = 1:size(rimg,2);
0141 msm.y_pts = 1:size(rimg,1);
0142 end
0143 ish= ishold;
0144 if isnumeric(clevs)
0145 if ~ish; hold on; end
0146 contour(msm.x_pts, msm.y_pts, rimg, clevs, contour_properties{:});
0147 if ~ish; hold off; end
0148 elseif clevs
0149 if ~ish; hold on; end
0150 contour(msm.x_pts, msm.y_pts, rimg, contour_properties{:});
0151 if ~ish; hold off; end
0152 else
0153 error('img.show_slices.contour_levels parameter not understood');
0154 end
0155 end
0156
0157 if nargout==0; clear('out_img'); end
0158
0159 function do_unit_test
0160 clf; sp=0;
0161
0162 img=calc_jacobian_bkgnd(mk_common_model('a2t3',8));
0163 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0164 sp=sp+1;subplot(4,5,sp); show_slices(img)
0165
0166 img.calc_colours.npoints= 128;
0167 sp=sp+1;subplot(4,5,sp); show_slices(img)
0168
0169 img.calc_colours.npoints= 32;
0170 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1:3);
0171 sp=sp+1;subplot(4,5,sp); show_slices(img)
0172
0173
0174 img.show_slices.img_cols= 1;
0175 sp=sp+1;subplot(4,5,sp); show_slices(img)
0176
0177 imgn = rmfield(img,'elem_data');
0178 imgn.node_data=toeplitz(1:size(img.fwd_model.nodes,1),1);
0179
0180 img.elem_data = img.elem_data(:,1);
0181 img.fwd_model.mdl_slice_mapper.npx = 10;
0182 img.fwd_model.mdl_slice_mapper.npy = 20;
0183 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0184 sp=sp+1;subplot(4,5,sp); show_slices(img);
0185
0186 img.elem_data = img.elem_data(:,1);
0187 img.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0188 img.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0189 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0190 sp=sp+1;subplot(4,5,sp); show_slices(img);
0191
0192 sp=sp+1;subplot(4,5,sp); show_slices(imgn)
0193
0194 imgn.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0195 imgn.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0196 imgn.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0197 sp=sp+1;subplot(4,5,sp); show_slices(imgn)
0198
0199
0200
0201 img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2]));
0202 img.calc_colours.npoints= 16;
0203 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0204 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0205
0206
0207 img.elem_data=img.elem_data*[1:3];
0208 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0209
0210 img.elem_data=img.elem_data(:,1:2);
0211 sp=sp+1;subplot(4,5,sp); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);
0212
0213 img.show_slices.sep = 5;
0214 img.fwd_model.mdl_slice_mapper.x_pts = linspace(-1,1,20);
0215 img.fwd_model.mdl_slice_mapper.y_pts = linspace(-1,1,30);
0216 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0217
0218 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0219
0220
0221 img.elem_data = img.elem_data(:,1);
0222 levels=[inf,inf,1,1,1;
0223 0,inf,inf,2,1;
0224 0,1,inf,3,1];
0225 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0226
0227 levels=[inf,inf,1,1,1;
0228 0,inf,inf,2,2;
0229 0,1,inf, 1,3];
0230 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0231
0232 img.elem_data = img.elem_data(:,[1,1]);
0233 levels=[inf,inf,1,1,1;
0234 0,inf,inf,2,1;
0235 0,1,inf, 3,1];
0236 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0237
0238 m = calc_slices(img,levels);
0239 sp=sp+1;subplot(4,5,sp); show_slices(m)
0240
0241 img.elem_data = img.elem_data(:,1);
0242 img.show_slices.contour_levels = true;
0243 sp=sp+1;subplot(4,5,sp); show_slices(img)
0244
0245 img.fwd_model.mdl_slice_mapper = struct('level',[inf,inf,1], ...
0246 'x_pts', linspace(-1,1,50), 'y_pts',linspace(-2,2,100));
0247 img.show_slices.axes_msm = true;
0248 img.show_slices.contour_properties = {'LineWidth',2};
0249 img.show_slices.contour_levels = 1:300;
0250 sp=sp+1;subplot(4,5,sp); show_slices(img)
0251