remove_elems

PURPOSE ^

REMOVE_ELEMS Remove nodes from a fwd_model.

SYNOPSIS ^

function [fmdl, c2f_idx] = remove_elems(fmdl, idx, elec_opt)

DESCRIPTION ^

REMOVE_ELEMS   Remove nodes from a fwd_model.

  fmdl = REMOVE_ELEMS(fmdl, idx) removes fmdl.elems(idx,:)
     fmdl : EIDORS fwd_model
     idx  : indices (integer or logical) into fmdl.elems

  fmdl = REMOVE_ELEMS(... , elec_opt) specifies treatment of
  electrodes:
   'warn'      - (default) warns about empty electrodes, but keeps them
   'keep'      - quietly keeps empty electrodes
   'remove'    - quietly removes empty electrodes
   'quiet'     - don't warn about changes to electrodes

  [fmdl, c2f_idx] = REMOVE_ELEMS(...) also provides indices of elem_data 
  to keep in an image.

  REMOVE_ELEMS removes affected edges/faces from fmdl.boundary, but does
  not recalculate it.

 See also: REMOVE_NODES, CROP_MODEL, REMOVE_UNUSED_NODES

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [fmdl, c2f_idx] = remove_elems(fmdl, idx, elec_opt)
0002 %REMOVE_ELEMS   Remove nodes from a fwd_model.
0003 %
0004 %  fmdl = REMOVE_ELEMS(fmdl, idx) removes fmdl.elems(idx,:)
0005 %     fmdl : EIDORS fwd_model
0006 %     idx  : indices (integer or logical) into fmdl.elems
0007 %
0008 %  fmdl = REMOVE_ELEMS(... , elec_opt) specifies treatment of
0009 %  electrodes:
0010 %   'warn'      - (default) warns about empty electrodes, but keeps them
0011 %   'keep'      - quietly keeps empty electrodes
0012 %   'remove'    - quietly removes empty electrodes
0013 %   'quiet'     - don't warn about changes to electrodes
0014 %
0015 %  [fmdl, c2f_idx] = REMOVE_ELEMS(...) also provides indices of elem_data
0016 %  to keep in an image.
0017 %
0018 %  REMOVE_ELEMS removes affected edges/faces from fmdl.boundary, but does
0019 %  not recalculate it.
0020 %
0021 % See also: REMOVE_NODES, CROP_MODEL, REMOVE_UNUSED_NODES
0022 
0023 % (C) 2024 Bartek Grychtol. License: GPL version 2 or version 3
0024 % $Id: remove_elems.m 7002 2024-11-24 13:11:35Z aadler $
0025 
0026 if ischar(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test; return; end
0027 
0028 if nargin < 3, elec_opt = ''; end
0029 
0030 remove = false([num_elems(fmdl), 1]);
0031 remove(idx) = true;
0032 c2f_idx = [];
0033 
0034 if ~any(remove), return, end
0035 if all(remove)
0036     error('Cannot remove all elements')
0037 end
0038 
0039 fmdl.elems(remove,:) = [];
0040 
0041 if isfield(fmdl, 'coarse2fine')
0042     fmdl.coarse2fine(remove,:) = [];
0043 end
0044 
0045 % fmdl.boundary = find_boundary(fmdl);
0046 
0047 c2f_idx = find(~remove);
0048 elem_map = zeros(size(remove));
0049 elem_map(~remove) = 1:nnz(~remove);
0050 
0051 if isfield(fmdl, 'mat_idx')
0052     mat_removed = false(size(fmdl.mat_idx));
0053     for i = 1:numel(fmdl.mat_idx)
0054         fmdl.mat_idx{i} = elem_map(fmdl.mat_idx{i});
0055         fmdl.mat_idx{i}(fmdl.mat_idx{i} == 0) = [];
0056         if isempty(fmdl.mat_idx{i})
0057            mat_removed(i) = true;
0058         end
0059     end
0060     fmdl.mat_idx(mat_removed) = [];
0061     if isfield(fmdl, 'mat_names')
0062        fmdl.mat_names(mat_removed) = [];
0063     end
0064 end
0065 
0066 
0067 fmdl = remove_unused_nodes(fmdl, elec_opt);
0068 
0069 
0070 function do_unit_test
0071 f0= mk_common_model('a2c2',8);
0072 f0= f0.fwd_model;
0073 fr= remove_elems(f0, [7,13,14,21,22,32]);
0074 unit_test_cmp('2D- 1a',fr.nodes(11,:), f0.nodes(12,:));
0075 unit_test_cmp('2D- 1b',fr.elems(20,:),[13,14, 6]);
0076 
0077 fr= remove_elems(f0, [38,50,51],'remove');
0078 unit_test_cmp('2D- 2e',num_elecs(fr),7);
0079 unit_test_cmp('2D- 2b',fr.nodes(27,:), f0.nodes(27,:));
0080 unit_test_cmp('2D- 2a',fr.nodes(28,:), f0.nodes(29,:));
0081 unit_test_cmp('2D- 2c',f0.elems(40,:),[20,19,33]);
0082 unit_test_cmp('2D- 2d',fr.elems(40,:),[31,19,18]);
0083 
0084 fr= remove_elems(f0, [38,50,51],'keep');
0085 unit_test_cmp('2D- 2e',num_elecs(fr),8);
0086 unit_test_cmp('2D- 2b',fr.nodes(27,:), f0.nodes(27,:));
0087 unit_test_cmp('2D- 2a',fr.nodes(28,:), f0.nodes(29,:));
0088 unit_test_cmp('2D- 2c',f0.elems(40,:),[20,19,33]);
0089 unit_test_cmp('2D- 2d',fr.elems(40,:),[31,19,18]);
0090

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005