Home > eidors > graphics > matlab > show_3d_slices.m

show_3d_slices

PURPOSE ^

show_3d_slices(img, z_cuts, x_cuts, y_cuts, any_cuts)

SYNOPSIS ^

function h = show_3d_slices(img, varargin);

DESCRIPTION ^

 show_3d_slices(img, z_cuts, x_cuts, y_cuts, any_cuts)
 Show a 3d view of an object with many slices through it
  z_cuts = planes in z to do a cut
  x_cuts = planes in x to do a cut
  y_cuts = planes in y to do a cut
  any_cuts = cut planes intercepts as Nx3 matrix (see mdl_slice_mapper)
 Default show 2 z_cuts and 1 x and 1 y cut

 h = show_3d_slices(...) returns a cell array of handles to the individual
 slices { z_slices, x_slices, y_slices, any_slices }

 See also: mdl_slices_mesher

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function h = show_3d_slices(img, varargin);
0002 % show_3d_slices(img, z_cuts, x_cuts, y_cuts, any_cuts)
0003 % Show a 3d view of an object with many slices through it
0004 %  z_cuts = planes in z to do a cut
0005 %  x_cuts = planes in x to do a cut
0006 %  y_cuts = planes in y to do a cut
0007 %  any_cuts = cut planes intercepts as Nx3 matrix (see mdl_slice_mapper)
0008 % Default show 2 z_cuts and 1 x and 1 y cut
0009 %
0010 % h = show_3d_slices(...) returns a cell array of handles to the individual
0011 % slices { z_slices, x_slices, y_slices, any_slices }
0012 %
0013 % See also: mdl_slices_mesher
0014 
0015 % (C) 2007-2012 Andy Adler & Bartlomiej Grychtol.
0016 % License: GPL version 2 or version 3
0017 % $Id: show_3d_slices.m 5783 2018-05-20 23:18:32Z aadler $
0018 
0019 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0020 
0021 ok= 0;
0022 try; if strcmp(img.type, 'image');
0023    ok = 1;
0024 end; end
0025 if ~ok; 
0026    error('EIDORS: show_3d_slices requires image as first parameter');
0027 end
0028 if size(img.fwd_model.elems,2) == 3; %show_3d_slices requires volume model
0029    img = fake_3d_model( img );
0030 end
0031 
0032 %multi-parametrization
0033 img = data_mapper(img);
0034 
0035 qfi = warning('query','EIDORS:FirstImageOnly');
0036 % Get data and to c2f mapping if required
0037 elem_data = get_img_data(img);
0038 % check size
0039 if size(elem_data,2) > 1
0040    q = warning('query','backtrace');
0041    warning('backtrace','off');
0042    warning('EIDORS:FirstImageOnly','show_3d_slices only shows first image');
0043    warning('backtrace',q.state);
0044    warning('off','EIDORS:FirstImageOnly');
0045 end
0046 
0047 % need to make sure boundary is just the outside
0048 img.fwd_model.boundary = find_boundary(img.fwd_model);
0049 
0050 
0051 [jnk,ref_lev,max_scale] = scale_for_display( elem_data);
0052 try 
0053     img.calc_colours.ref_level; 
0054 catch
0055     img.calc_colours.ref_level = ref_lev;
0056 end
0057 try
0058     img.calc_colours.clim;
0059 catch
0060     img.calc_colours.clim = max_scale;
0061 end
0062 try 
0063     np = img.calc_colours.npoints;
0064 catch
0065     np = calc_colours('npoints');
0066 end
0067 %  show_fem(img.fwd_model);
0068 [x_cuts, y_cuts, z_cuts, any_cuts] = get_cuts(img,varargin{:});
0069 
0070 hz = []; hy = []; hx = []; ha = [];
0071 for i= 1:length(z_cuts)
0072     hz(i) = show_slice(img,[inf inf z_cuts(i)]);
0073     hold on
0074 end
0075 
0076 for i= 1:length(x_cuts)
0077     hx(i) = show_slice(img,[x_cuts(i) inf inf]);
0078     hold on
0079 end
0080 
0081 for i= 1:length(y_cuts)
0082     hy(i) = show_slice(img,[inf y_cuts(i) inf]);
0083     hold on
0084 end
0085 
0086 for i= 1:size(any_cuts,1)
0087     ha(i) = show_slice(img,any_cuts(i,:));
0088     hold on
0089 end
0090 hold off
0091 
0092 if nargout > 0
0093    h = {hz,hx,hy,ha};
0094 end
0095 
0096 warning(qfi.state,'EIDORS:FirstImageOnly');
0097 
0098 function h = show_slice(img, level)
0099     slc = mdl_slice_mesher(img,level);
0100     try slc.calc_colours = img.calc_colours; end
0101     h = show_fem(slc);
0102 
0103 % create an extruded 3D model of height
0104 function img = fake_3d_model( img );
0105   fmdl = img.fwd_model;
0106   fnodes = fmdl.nodes;
0107   felems = fmdl.elems;
0108   maxd = max( max(fnodes) - min(fnodes) );
0109   upd = 0.1*maxd; % up and down from zero
0110   Nn = num_nodes(fmdl);
0111   Ne = num_elems(fmdl);
0112   fmdn = fmdl;
0113   fmdn.nodes =[[fnodes,-upd+0*fnodes(:,1)];
0114                [fnodes,+upd+0*fnodes(:,1)]];
0115   for i=1:num_elecs(fmdl)
0116      eni = fmdn.electrode(i).nodes;
0117      fmdn.electrode(i).nodes = [eni(:);eni(:)+Nn]';
0118   end
0119   % Doesn't need to be a conformal model, don't worry about adjacency
0120   fmdn.elems =[[felems(:,[1,2,3]), felems(:,[1    ])+Nn];
0121                [felems(:,[  2,3]), felems(:,[1,2  ])+Nn];
0122                [felems(:,[    3]), felems(:,[1,2,3])+Nn]];
0123   ed= img.elem_data;
0124   if isfield(fmdl,'coarse2fine');
0125      c2f = fmdl.coarse2fine;
0126      fmdn.coarse2fine = [c2f;c2f;c2f]; 
0127      img.fwd_model = fmdn;
0128   else
0129      img = mk_image(fmdn,[ed;ed;ed]);
0130   end
0131 
0132     
0133 function [x_cuts, y_cuts, z_cuts, any_cuts] =  get_cuts(img, varargin)
0134    mdl_max= max(img.fwd_model.nodes);
0135    mdl_min= min(img.fwd_model.nodes);
0136    any_cuts = [];
0137    if nargin==1;
0138       % Default show 2 z_cuts and 1 x and 1 y cut
0139        x_cuts= linspace(mdl_min(1), mdl_max(1), 3); x_cuts([1,3])=[];
0140        y_cuts= linspace(mdl_min(2), mdl_max(2), 3); y_cuts([1,3])=[];
0141        z_cuts= linspace(mdl_min(3), mdl_max(3), 4); z_cuts([1,4])=[];
0142    elseif nargin==2;
0143        z_cuts= varargin{1};
0144        x_cuts= [];
0145        y_cuts= [];
0146    elseif nargin==3;
0147        z_cuts= varargin{1};
0148        x_cuts= varargin{2};
0149        y_cuts= [];
0150    elseif nargin==4;
0151        z_cuts= varargin{1};
0152        x_cuts= varargin{2};
0153        y_cuts= varargin{3};
0154    elseif nargin==5;
0155        z_cuts= varargin{1};
0156        x_cuts= varargin{2};
0157        y_cuts= varargin{3};
0158        any_cuts= varargin{4};
0159    else 
0160        error('too many inputs');
0161    end
0162    
0163 
0164 
0165 function do_unit_test
0166    imdl = mk_common_model('n3r2',[16,2]);
0167    img = mk_image(imdl,1); vh= fwd_solve(img);
0168    load datacom.mat A B;
0169    img.elem_data(A) = 1.2;
0170    img.elem_data(B) = 0.8;
0171    vi = fwd_solve(img);
0172    imgr = inv_solve(imdl, vh, vi);
0173    imgr.calc_colours.npoints =64;
0174    show_3d_slices(img);
0175    calc_colours('transparency_thresh', 0.25);
0176    show_3d_slices(imgr,[1.5,2],[],[]);
0177 
0178    subplot(331);  show_3d_slices(imgr,[1,2],0,0.5);
0179    subplot(332);  show_3d_slices(img ,[1,2],0,0.5);
0180    cuts = [inf, -2.5, 1.5; inf, 10, 1.5];
0181    subplot(333);  show_3d_slices(img ,[],[],[],cuts );
0182    
0183    imgr.calc_colours.transparency_thresh = -1;
0184    img.calc_colours.transparency_thresh = -1;
0185    subplot(334);  show_3d_slices(imgr,[1,2],0.3,0.7);
0186    subplot(335);  
0187    show_fem(img.fwd_model);
0188    hold on
0189    show_3d_slices(img ,[1,2],0.3,0.7);
0190    axis off
0191 
0192    subplot(336);  
0193    img.elem_data = img.elem_data*[0,1];
0194    img.get_img_data.frame_select = 2;
0195    show_3d_slices(img ,[1],[],[]);
0196    
0197    view(10,18);
0198 
0199 
0200    subplot(337);
0201    imgs = img;        ed = img.elem_data(:,1);
0202    imgs.elem_data= [1;1.2;0.8]*[1];
0203    imgs.fwd_model.coarse2fine = [ed == img.elem_data(1),
0204                                  ed == img.elem_data(2),
0205                                  ed == img.elem_data(3)];
0206    show_3d_slices(img,[1,2],0,0.7);
0207   
0208 
0209 
0210    subplot(338);  
0211    vopt.imgsz = [10,10,10];
0212    % Build a model that has a c2f. This one isn't very good,
0213    % because of transpose, but that's OK for the test
0214    [img.fwd_model,tmp] = mk_voxel_volume(imdl.fwd_model,vopt);
0215    img.fwd_model.coarse2fine = (tmp.coarse2fine * ...
0216                       img.fwd_model.coarse2fine')';
0217    show_3d_slices(img,[1,2],0,0.5);
0218 
0219    subplot(339)
0220 % Without C2f
0221    imdl = mk_common_model('a2c0',8); img= mk_image(imdl);
0222    img.elem_data([10,12]) = 1.1;
0223    show_3d_slices(img,[0],[0.2],[0]);
0224 
0225 
0226 % With C2f
0227    ed = img.elem_data;
0228    img.fwd_model.coarse2fine = [ed==1, ed> 1];
0229    img.elem_data= [1;1.1];
0230    show_3d_slices(img,[0],[0.2],[0]);

Generated on Fri 01-Jun-2018 15:59:55 by m2html © 2005