show_slices_move

PURPOSE ^

SHOW_SLICES_MOVE Shows planar slices of a 3D FEM with movement vectors

SYNOPSIS ^

function show_slices_move( img, move, move_scale )

DESCRIPTION ^

 SHOW_SLICES_MOVE   Shows planar slices of a 3D FEM with movement vectors
 if electrodes are visible on the slice.
 Args:     img  - eidors_obj type image
           move - change in  position vectors for nodes [x,y,z] after movement

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function show_slices_move( img, move, move_scale )
0002 % SHOW_SLICES_MOVE   Shows planar slices of a 3D FEM with movement vectors
0003 % if electrodes are visible on the slice.
0004 % Args:     img  - eidors_obj type image
0005 %           move - change in  position vectors for nodes [x,y,z] after movement
0006 
0007 % $Id: show_slices_move.m 5418 2017-04-25 13:09:33Z aadler $
0008 
0009 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0010 
0011 
0012 num_levs = 3;
0013 
0014 mdl = img.fwd_model;
0015 elecs = length(mdl.electrode);
0016 pos = zeros(elecs,3);
0017 if exist('move') && size(move,1) == size(mdl.nodes,1)
0018     move_nodes = move;
0019     move= zeros(elecs,3);
0020 end
0021 for e = 1:elecs;
0022     if isfield(mdl.electrode(e),'pos')
0023        pos(e,:) = mean(mdl.electrode(e).pos);
0024     else
0025        elec_nodes = mdl.electrode(e).nodes;
0026        pos(e,:) = mean(mdl.nodes(elec_nodes,:),1);
0027     end
0028     if exist('move_nodes');
0029         move(e,:) = mean( move_nodes(elec_nodes,:), 1);
0030     end
0031 end
0032 
0033 elec_zmax = max(pos(:,3));
0034 elec_zmin = min(pos(:,3));
0035 
0036 levels = inf*ones(num_levs,3);
0037 levels(:,3) = [elec_zmax; elec_zmax-(elec_zmax - elec_zmin)/2; elec_zmin];
0038 levels(:,4) = ones(num_levs,1);
0039 levels(:,5) = (1:num_levs)';
0040 
0041 show_slices( img, levels );
0042 
0043 isize = calc_colours('npoints');
0044 toplayer = pos(:,3) < levels(2,3); % origin is top-left corner of image
0045 xofs = .5 + isize*(.5);
0046 xscale = (100/104)*isize/2;
0047 yofs = .5 + isize*(.5 + (num_levs-1)*toplayer);
0048 yscale = -(100/104)*isize/2;
0049 vx = pos(:,1) * xscale + xofs;
0050 vy = pos(:,2) * yscale + yofs;
0051 ecolour = [0,.3,0];
0052 hh= line(vx, vy);
0053 set(hh, 'LineStyle','none','Marker','.', ...
0054     'MarkerSize',10,'MarkerEdgeColor',ecolour);
0055 
0056 pp = fwd_model_parameters( mdl );
0057 if nargin == 1;
0058     move = [];
0059 end
0060 if length(img.elem_data) > pp.n_elem
0061     move = reshape( ...
0062         img.elem_data( pp.n_elem+(1:pp.n_elec*pp.n_dims) ), ...
0063         pp.n_elec, pp.n_dims);
0064 end
0065 
0066 if ~isempty( move )
0067     nodes = img.fwd_model.nodes;
0068 
0069     % zero mean movement for each electrode row; this is not quite legit
0070     idx = 1:16;
0071     move(idx,:) = move(idx,:)- ones(16,1)*mean(move(idx,:));
0072     if length(img.fwd_model.electrode) == 32
0073         idx = 17:32;
0074         move(idx,:) = move(idx,:)- ones(16,1)*mean(move(idx,:));
0075     end
0076     hold on;
0077     if nargin < 3
0078         move_scale = 20*isize;
0079     end
0080     hh = working_quiver( vx, vy, move_scale*move(:,1), ...
0081         - move_scale*move(:,2), 0 );
0082     set(hh,'Color', [0,.3,0], 'LineWidth', 2, 'Clipping', 'off');
0083     hold off;
0084 end
0085 
0086 function hh= working_quiver( varargin )
0087 % WORKING_QUIVER   Matlab has made a completely imcompatible
0088 % quiver function which you can't call properly with different
0089 % versions of matlab.
0090 
0091 % Unfortunately, the idea of using 'v6' is now a warning.
0092 % We can't do too many version checks, giving up!
0093 
0094 hh = quiver( varargin{:} );
0095 
0096 %   v = version;
0097 %   octave = exist('OCTAVE_VERSION')
0098 %   if octave
0099 %       hh = quiver( varargin{:} );
0100 %   else
0101 %       hh = quiver('v6', varargin{:} );
0102 %   end
0103 
0104 
0105 function do_unit_test
0106    subplot(221);
0107    img = mk_image( mk_common_model('n3r2',[16,2]) );
0108    show_slices_move(img);
0109 
0110    subplot(222);
0111    for i=1:length(img.fwd_model.electrode)
0112      e_node = img.fwd_model.electrode(i).nodes;
0113      move(i,:) = 0.01*mean( img.fwd_model.nodes(e_node,:),1);
0114    end
0115    show_slices_move(img,move);
0116 
0117    subplot(223);
0118    show_slices_move(img,move, 1000);

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