0001 function [bdy_idx, bdy_area] = find_electrode_bdy( bdy, vtx, elec_nodes)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
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
0066
0067
0068
0069
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
0076 used_nodes= reshape( bdy(ffb,:), 1,[]);
0077 unused= setdiff( elec_nodes, used_nodes);
0078
0079
0080
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