show_fem_move

PURPOSE ^

SHOW_FEM_MOVE Plot EIT finite element model (FEM) and movement

SYNOPSIS ^

function [hf,hh] = show_fem_move( img, move, scale, options )

DESCRIPTION ^

 SHOW_FEM_MOVE   Plot EIT finite element model (FEM) and movement 
    vectors.
 Args: img     - eidors_obj of type 'image'
       move    - FEM node coordinate matrix of movement vectors (optional)
       scale   - factor to scale movement arrows (optional)
       options - options array passed on to show_fem()

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [hf,hh] = show_fem_move( img, move, scale, options )
0002 % SHOW_FEM_MOVE   Plot EIT finite element model (FEM) and movement
0003 %    vectors.
0004 % Args: img     - eidors_obj of type 'image'
0005 %       move    - FEM node coordinate matrix of movement vectors (optional)
0006 %       scale   - factor to scale movement arrows (optional)
0007 %       options - options array passed on to show_fem()
0008 
0009 % (C) 2005 Andy Adler. License GPL v2 or v3
0010 % $Id: show_fem_move.m 5513 2017-06-06 15:03:43Z aadler $
0011 
0012 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0013 
0014 % Check for single argument call
0015 if nargin == 1
0016     move = [];
0017     scale = 20;
0018     options = [0,0,[]];
0019 elseif nargin == 2
0020     scale = 20;
0021     options = [0,0,[]];
0022 elseif nargin == 3
0023     options = [0,0,[]];
0024 end
0025 
0026 % Extract forward model parameters
0027 fwdp = fwd_model_parameters( img.fwd_model );
0028 try
0029     fwdp.n_elem = size(img.fwd_model.coarse2fine,2);
0030 end
0031 % Verify if img is partitioned by conductivity and move submatrices
0032 if isfield(img,'elem_data') % pre-parametrization
0033    if length(img.elem_data) > fwdp.n_elem
0034       move = reshape( ...
0035          img.elem_data( fwdp.n_elem+(1:fwdp.n_elec*fwdp.n_dims) ), ...
0036          fwdp.n_elec, fwdp.n_dims);
0037       img.elem_data = img.elem_data(1:fwdp.n_elem);
0038    end
0039 else
0040    img = data_mapper(img);
0041    move = reshape( img.movement.electrode_data, ...
0042                      fwdp.n_elec, fwdp.n_dims); 
0043 end
0044 % Plot FEM with conductivity elements with or without colourbars
0045 hf = show_fem(img, options); % Show colourbar
0046 
0047 % Plot movement vectors on electrodes
0048 if ~isempty(move)
0049     % e_nodes is the average position of each electrodes nodes
0050     e_nodes = [];
0051     electr= img.fwd_model.electrode;
0052     nodes = img.fwd_model.nodes;
0053     switch size(move,1)
0054       case length(electr)
0055         for i=1:length(electr)
0056            if isfield(electr(i), 'pos')
0057               e_nodes(i,:) = mean(electr(i).pos);
0058            else
0059               e_nodes(i,:) = mean(nodes(electr(i).nodes,:),1);
0060            end
0061         end
0062     
0063       case num_nodes(img)
0064         % Keep only electrode node movement coordinates
0065         e_nodes = [electr(:).nodes];
0066         if size(move,1) == fwdp.n_node;
0067             move = move(e_nodes,:);
0068         end
0069         e_nodes = nodes(e_nodes,:);
0070 
0071       otherwise;
0072         error('movement vector doesn''t match model');
0073     end
0074     move = move- ones(size(move,1),1)*mean(move);
0075     
0076     % Render movement arrows for each electrode
0077     hold on;
0078     if nargin < 3
0079         scale = 20;
0080     end
0081     hh = working_quiver(e_nodes, scale*move);
0082     set(hh,'Color', [0,.3,0], 'LineWidth', 2, 'Clipping', 'off');
0083     hold off;
0084 end
0085 % Format output figure
0086 axis('off'); 
0087 axis('image'); 
0088 %axis(1.3*[-1,1,-1,1]); % let it take it's own space
0089 
0090 function hh= working_quiver( nn,mm )
0091 % WORKING_QUIVER   Matlab has made a completely imcompatible
0092 % quiver function which you can't call properly with different
0093 % versions of matlab.
0094 %
0095 % Last I checked, the V7 version of quiver was horrible, so
0096 %  we use the v6 one. But now (v8) that option is gone, too.
0097 
0098 % TODO: Write a new, fixed quiver function that can do 3D
0099 
0100 hh = quiver( nn(:,1),nn(:,2), mm(:,1),mm(:,2),0);
0101 
0102 function do_unit_test;
0103    subplot(231);
0104    img = mk_image(mk_common_model('a2c2',8));
0105    img.elem_data = [img.elem_data;.01*randn(16,1)];
0106    show_fem_move(img);
0107    title('move at electrodes');
0108 
0109    subplot(232);
0110    img = mk_image(mk_common_model('a2c2',8));
0111    show_fem_move( img, img.fwd_model.nodes*[-1,0;0,1], .2);
0112    title('move at electrodes (via all move)');
0113 
0114    subplot(233);
0115    img = mk_image(mk_common_model('a2C2',8));
0116    img.elem_data = [img.elem_data;.01*randn(16,1)];
0117    show_fem_move(img);
0118    title('move at electrodes ctrs');
0119 
0120    subplot(234);
0121    img = mk_image(mk_common_model('a2C0',8));
0122    img.elem_data(1:2) = 1.1;
0123    show_fem_move( img, img.fwd_model.nodes*[-1,0;0,1], .2);
0124    title('move at electrodes nodes');
0125 
0126    subplot(235);
0127    img = mk_image(mk_common_model('n3r2',[16,2]));
0128    img.elem_data(400)= 0.9;
0129    img.elem_data = [img.elem_data;.01*randn(3*32,1)];
0130    show_fem_move(img); view([-14,62]);
0131    title('BUG:move at electrodes ctrs');
0132 
0133    subplot(236);
0134    img = mk_image(mk_common_model('n3r2',[16,2]));
0135    move = img.fwd_model.nodes*diag([-1,1,1]);
0136    show_fem_move( img, move, .2); view([-14,62]);
0137    title('BUG:move at electrodes ctrs');

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