find_electrode_bdy

PURPOSE ^

FIND_ELECTRODE_BDY: find the boundary index area for electrode

SYNOPSIS ^

function [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, elec_nodes)

DESCRIPTION ^

 FIND_ELECTRODE_BDY: find the boundary index area for electrode
 Input:
   bdy => boundary (from fwd_model.boundary) bdy simplices x nodes index 
   vtx => node pts (from fwd_model.nodes)
   elec_nodes => index of nodes in the electrode
 Output:
   bdy_idx  => vector of boundary simplices in this electrode
   bdy_area => boundary area of each simplex in bdy_idx
  if the nodes in the electrode are points, then
   bdy_area is the area corresponding to these point electrodes

 if [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, [])
   calculate bdy_idx=[] and bdy_area for all on bdy

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, elec_nodes)
0002 % FIND_ELECTRODE_BDY: find the boundary index area for electrode
0003 % Input:
0004 %   bdy => boundary (from fwd_model.boundary) bdy simplices x nodes index
0005 %   vtx => node pts (from fwd_model.nodes)
0006 %   elec_nodes => index of nodes in the electrode
0007 % Output:
0008 %   bdy_idx  => vector of boundary simplices in this electrode
0009 %   bdy_area => boundary area of each simplex in bdy_idx
0010 %  if the nodes in the electrode are points, then
0011 %   bdy_area is the area corresponding to these point electrodes
0012 %
0013 % if [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, [])
0014 %   calculate bdy_idx=[] and bdy_area for all on bdy
0015 
0016 % (C) 2008 Andy Adler. License: GPL version 2 or version 3
0017 % $Id: find_electrode_bdy.m 6222 2021-12-16 15:10:27Z bgrychtol $
0018 
0019 % special processing if elec_nodes==[]
0020 if isempty(elec_nodes);
0021    bdy_idx = [];
0022    l_bdy= size(bdy,1);
0023    bdy_area = zeros(l_bdy,1);
0024    for i=1:l_bdy
0025       bdy_area(i) = tria_area( vtx(bdy(i,:),:) );
0026    end
0027    return;  
0028 end
0029 
0030 [bdy_idx, point] = find_bdy_idx( bdy, elec_nodes);
0031 if nargout==1; return;end
0032 
0033 l_bdy_idx= length(bdy_idx);
0034 l_point= length(point);
0035 
0036 if l_bdy_idx > 0 && l_point ==0
0037    bdy_area= zeros(1, l_bdy_idx);
0038 
0039    for i=1:l_bdy_idx
0040       bdy_nodes   = bdy(bdy_idx(i),:);
0041       bdy_area(i) = tria_area( vtx(bdy_nodes,:) );
0042    end
0043 elseif l_bdy_idx == 0 && l_point >0
0044    dims = size(bdy,2); 
0045    l_point= length(point);
0046    bdy_area = zeros(l_point,1);
0047    for i=1:l_point
0048      ff= find( any(bdy== point(i),2) );
0049      this_area= 0;
0050      for ffp=ff(:)'
0051         xyz= vtx( bdy(ffp,:),:);
0052         this_area= this_area + tria_area( xyz );
0053      end
0054      bdy_area(i)= bdy_area(i) + this_area/dims;
0055    end
0056 else
0057 keyboard
0058    error(['Can''t model this electrode. ' ...
0059           'It has %d CEM and %d point nodes (e.g. nodes %d, %d)'], ...
0060             l_bdy_idx, l_point, bdy_idx(1), point(1) )
0061 end
0062    
0063 
0064 
0065 % Find which boundary nodes are part of a
0066 % complete simplex. These nodes can be made
0067 % into complete electrode model elements
0068 %
0069 % Any nodes left will be treated as point electrodes
0070 function [ffb,unused] = find_bdy_idx( bdy, elec_nodes);
0071    elec_nodes = unique(elec_nodes);
0072    bdy_els = sum(ismember(bdy,elec_nodes),2);
0073    ffb = find(bdy_els == size(bdy,2));
0074 
0075 %  find if all nodes are used
0076    used_nodes= reshape( bdy(ffb,:), 1,[]);
0077    unused=     setdiff( elec_nodes, used_nodes);
0078    
0079 
0080 % bdy points is [x1,y1,z1;x2,y2,z2; etc]
0081 function area= tria_area( bdy_pts ); 
0082    vectors= diff(bdy_pts); 
0083    if size(vectors,1)==2
0084       vectors= cross(vectors(1,:),vectors(2,:));
0085    end
0086    d= size(bdy_pts,1);
0087    area= sqrt( sum(vectors.^2) )/( d-1 );
0088

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005