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 if isstr(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0035
0036 np = calc_colours('npoints');
0037 try np = img(1).calc_colours.npoints;
0038 end
0039
0040 sep = 0;
0041 try sep = img(1).show_slices.sep;
0042 end
0043
0044
0045 do_calc_slices = 0;
0046 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end
0047
0048 if nargin<=1;
0049 try levels = img(1).show_slices.levels
0050 catch levels = [];
0051 end
0052 end
0053
0054 if isempty(levels) && do_calc_slices && size(img(1).fwd_model.nodes,2)==2
0055 levels= [Inf,Inf,0];
0056 end
0057
0058 if size(levels,2) == 5
0059 spec_position= 1;
0060 elseif size(levels)== [1,1]
0061 if size(img(1).fwd_model.nodes,2) == 2
0062 eidors_msg('Can''t do horizontal slices for 2D model. Showing 2D slice');
0063 levels= [Inf,Inf,0];
0064 spec_position= 0;
0065 else
0066 zmax= max(img(1).fwd_model.nodes(:,3));
0067 zmin= min(img(1).fwd_model.nodes(:,3));
0068 levels = linspace(zmax,zmin, levels+2);
0069 levels = levels(2:end-1)';
0070 levels = [(1+0*levels)*[Inf,Inf], levels];
0071 spec_position= 0;
0072 end
0073 else
0074 spec_position= 0;
0075 end
0076
0077 if do_calc_slices
0078 rimg= calc_slices( img, levels(:,1:3) );
0079 else
0080 rimg= img;
0081 np = size(rimg,1);
0082 end
0083
0084
0085 n_frames = size(rimg,3);
0086 n_levels = size(rimg,4);
0087 if spec_position
0088 img_cols = max( levels(:,4) );
0089 img_rows = max( levels(:,5) );
0090 else
0091
0092
0093
0094
0095 vert_rows = ceil( sqrt(n_frames / n_levels) );
0096 try img_cols = img(1).show_slices.img_cols;
0097 catch img_cols = ceil( n_frames/vert_rows );
0098 end
0099 img_rows = ceil(n_frames*n_levels/img_cols);
0100 img_rows = ceil(img_rows/n_levels)*n_levels;
0101 end
0102
0103 r_img = NaN*ones(img_rows*np + (img_rows-1)*sep, ...
0104 img_cols*np + (img_cols-1)*sep );
0105
0106 idx= (-np:-1)+1;
0107 imno= 1;
0108 for img_no = 1:n_frames
0109 for lev_no = 1:n_levels
0110 if spec_position
0111 i_col= levels( lev_no, 4) + img_no -1;
0112 i_row= levels( lev_no, 5);
0113 else
0114 i_col= rem( img_no-1, img_cols) + 1;
0115 i_row= (ceil( img_no / img_cols) -1) * n_levels + lev_no ;
0116 end
0117
0118 r_img(i_row*np + idx + sep*(i_row-1), i_col*np + idx +sep*(i_col-1)) = rimg(:,:,img_no,lev_no);
0119 imno= imno + 1;
0120 end
0121 end
0122
0123 c_img = calc_colours( r_img, img);
0124 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0125
0126
0127 image(out_img);
0128 axis('image');axis('off');axis('equal');
0129
0130 if nargout==0; clear('out_img'); end
0131
0132
0133 function do_unit_test
0134 clf
0135
0136 img=calc_jacobian_bkgnd(mk_common_model('a2c0',8));
0137 img.elem_data=rand(size(img.fwd_model.elems,1),1);
0138 subplot(3,4,1); show_slices(img)
0139
0140 img.calc_colours.npoints= 128;
0141 subplot(3,4,2); show_slices(img)
0142
0143 img.calc_colours.npoints= 32;
0144 img.elem_data=rand(size(img.fwd_model.elems,1),3);
0145 subplot(3,4,3); show_slices(img)
0146
0147 img.show_slices.img_cols= 1;
0148 subplot(3,4,4); show_slices(img)
0149
0150 imgn = rmfield(img,'elem_data');
0151 imgn.node_data=rand(size(img.fwd_model.nodes,1),1);
0152 subplot(3,4,5); show_slices(imgn)
0153
0154 img=calc_jacobian_bkgnd(mk_common_model('n3r2',32));
0155 img.calc_colours.npoints= 16;
0156 img.elem_data=rand(size(img.fwd_model.elems,1),1);
0157 subplot(3,4,6); show_slices(img,2)
0158
0159 img.elem_data=img.elem_data*[1:3];
0160 subplot(3,4,7); show_slices(img,2)
0161
0162 img.elem_data=img.elem_data(:,1:2);
0163 subplot(3,4,8); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);