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 5373 2017-03-22 13:53:21Z bgrychtol $
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 %multi-parametrization
0029 img = data_mapper(img);
0030 
0031 qfi = warning('query','EIDORS:FirstImageOnly');
0032 % check size
0033 if size(img.elem_data,2) > 1
0034    q = warning('query','backtrace');
0035    warning('backtrace','off');
0036    warning('EIDORS:FirstImageOnly','show_3d_slices only shows first image');
0037    warning('backtrace',q.state);
0038    warning('off','EIDORS:FirstImageOnly');
0039 end
0040 
0041 % need to make sure boundary is just the outside
0042 img.fwd_model.boundary = find_boundary(img.fwd_model);
0043 
0044 % Check if we need to map from coarse2fine
0045 if isfield(img.fwd_model,'coarse2fine');
0046    c2f = img.fwd_model.coarse2fine;
0047    if size(c2f,2) == size(img.elem_data,1)
0048       img.elem_data = c2f*img.elem_data;
0049    elseif size(c2f,1) == size(img.elem_data,1)
0050       % OK, nothing required
0051    else
0052       error('image elem_data does not match coarse2fine size');
0053    end
0054 end
0055 
0056 
0057 [jnk,ref_lev,max_scale] = scale_for_display( img.elem_data);
0058 try 
0059     img.calc_colours.ref_level; 
0060 catch
0061     img.calc_colours.ref_level = ref_lev;
0062 end
0063 try
0064     img.calc_colours.clim;
0065 catch
0066     img.calc_colours.clim = max_scale;
0067 end
0068 try 
0069     np = img.calc_colours.npoints;
0070 catch
0071     np = calc_colours('npoints');
0072 end
0073 %  show_fem(img.fwd_model);
0074 mdl_min = min(img.fwd_model.nodes);
0075 mdl_max = max(img.fwd_model.nodes);
0076 mdl_rng = mdl_max - mdl_min;
0077 np = round(mdl_rng/min(mdl_rng) * np);
0078 [x_cuts, y_cuts, z_cuts, any_cuts] = get_cuts(img,varargin{:});
0079 xvec = linspace(mdl_min(1), mdl_max(1),np(1)+1);
0080 yvec = linspace(mdl_min(2), mdl_max(2),np(2)+1);
0081 zvec = linspace(mdl_min(3), mdl_max(3),np(3)+1);
0082 
0083 hz = []; hy = []; hx = []; ha = [];
0084 for i= 1:length(z_cuts)
0085     hz(i) = show_slice(img,[inf inf z_cuts(i)]);
0086     hold on
0087 end
0088 
0089 for i= 1:length(x_cuts)
0090     hx(i) = show_slice(img,[x_cuts(i) inf inf]);
0091     hold on
0092 end
0093 
0094 for i= 1:length(y_cuts)
0095     hy(i) = show_slice(img,[inf y_cuts(i) inf]);
0096     hold on
0097 end
0098 
0099 for i= 1:size(any_cuts,1)
0100     ha(i) = show_slice(img,any_cuts(i,:));
0101     hold on
0102 end
0103 hold off
0104 
0105 if nargout > 0
0106    h = {hz,hx,hy,ha};
0107 end
0108 
0109 warning(qfi.state,'EIDORS:FirstImageOnly');
0110 
0111 function h = show_slice(img, level)
0112     slc = mdl_slice_mesher(img,level);
0113     try slc.calc_colours = img.calc_colours; end
0114     h = show_fem(slc);
0115 
0116     
0117 function [x_cuts, y_cuts, z_cuts, any_cuts] =  get_cuts(img, varargin)
0118    mdl_max= max(img.fwd_model.nodes);
0119    mdl_min= min(img.fwd_model.nodes);
0120    any_cuts = [];
0121    if nargin==1;
0122       % Default show 2 z_cuts and 1 x and 1 y cut
0123        x_cuts= linspace(mdl_min(1), mdl_max(1), 3); x_cuts([1,3])=[];
0124        y_cuts= linspace(mdl_min(2), mdl_max(2), 3); y_cuts([1,3])=[];
0125        z_cuts= linspace(mdl_min(3), mdl_max(3), 4); z_cuts([1,4])=[];
0126    elseif nargin==2;
0127        z_cuts= varargin{1};
0128        x_cuts= [];
0129        y_cuts= [];
0130    elseif nargin==3;
0131        z_cuts= varargin{1};
0132        x_cuts= varargin{2};
0133        y_cuts= [];
0134    elseif nargin==4;
0135        z_cuts= varargin{1};
0136        x_cuts= varargin{2};
0137        y_cuts= varargin{3};
0138    elseif nargin==5;
0139        z_cuts= varargin{1};
0140        x_cuts= varargin{2};
0141        y_cuts= varargin{3};
0142        any_cuts= varargin{4};
0143    else 
0144        error('too many inputs');
0145    end
0146    
0147 
0148 
0149 function do_unit_test
0150    imdl = mk_common_model('n3r2',[16,2]);
0151    img = mk_image(imdl,1); vh= fwd_solve(img);
0152    load datacom.mat A B;
0153    img.elem_data(A) = 1.2;
0154    img.elem_data(B) = 0.8;
0155    vi = fwd_solve(img);
0156    imgr = inv_solve(imdl, vh, vi);
0157    imgr.calc_colours.npoints =64;
0158    show_3d_slices(img);
0159    calc_colours('transparency_thresh', 0.25);
0160    show_3d_slices(imgr,[1.5,2],[],[]);
0161 
0162    subplot(231);  show_3d_slices(imgr,[1,2],0,0.5);
0163    subplot(232);  show_3d_slices(img ,[1,2],0,0.5);
0164    cuts = [inf, -2.5, 1.5; inf, 10, 1.5];
0165    subplot(233);  show_3d_slices(img ,[],[],[],cuts );
0166    
0167    imgr.calc_colours.transparency_thresh = -1;
0168    img.calc_colours.transparency_thresh = -1;
0169    subplot(234);  show_3d_slices(imgr,[1,2],0.3,0.7);
0170    subplot(235);  
0171    show_fem(img.fwd_model);
0172    hold on
0173    show_3d_slices(img ,[1,2],0.3,0.7);
0174    axis off
0175 
0176    subplot(236);  
0177    show_3d_slices(img ,[1],[],[]);
0178    
0179    view(10,18);

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005