function[elec,sels] = ng_tank_select_elec(srf,vtx,fc,mshaxs); This function takes the wire frame model and the face data and sequentially requests if each face is an electrode or earth. From this the indices matrices (sels & sgnd) are concatenated so as to map all the selected electrodes and grounded planes into the srf matrix. In addition the cell array (elsrf) is created containing the electrode surfaces and ground plane indices matrices which map directly into vtx. Version 5.0 B.D.Grieve - 13/02/2002 + modyfication by lmazurk WRBL added default as prevous choice 20/1/2004 WRBL deleted ground plane 05/12/2005 srf = The boundary surfaces vtx = The vertices matrix fc = A one column matrix containing the face numbers mshaxs = Axes details for plotting wire frame elsrf = Cell array of indices matrices mapping into vtx each electrode face sels = The indices into the srf matrix of the selected electrode faces elec = The EIDORS-3D electrode matrix of dimensions NxM, where where N: no. of electrodes, M: 3 * max no. of faces per electrode
0001 function[elec,sels] = ng_tank_select_elec(srf,vtx,fc,mshaxs); 0002 %function[elec,sels] = ng_tank_select_elec(srf,vtx,fc,mshaxs); 0003 % 0004 % This function takes the wire frame model and the face 0005 % data and sequentially requests if each face is an 0006 % electrode or earth. From this the indices matrices (sels & sgnd) 0007 % are concatenated so as to map all the selected electrodes and 0008 % grounded planes into the srf matrix. In addition the cell array 0009 % (elsrf) is created containing the electrode surfaces and ground 0010 % plane indices matrices which map directly into vtx. 0011 % 0012 % Version 5.0 0013 % B.D.Grieve - 13/02/2002 + modyfication by lmazurk 0014 % WRBL added default as prevous choice 20/1/2004 0015 % WRBL deleted ground plane 05/12/2005 0016 % 0017 % srf = The boundary surfaces 0018 % vtx = The vertices matrix 0019 % fc = A one column matrix containing the face numbers 0020 % mshaxs = Axes details for plotting wire frame 0021 % elsrf = Cell array of indices matrices mapping into vtx each electrode face 0022 % sels = The indices into the srf matrix of the selected electrode faces 0023 % elec = The EIDORS-3D electrode matrix of dimensions NxM, where 0024 % where N: no. of electrodes, M: 3 * max no. of faces per electrode 0025 % 0026 0027 0028 sels = []; 0029 0030 0031 figure 0032 set(gcf,'Name','Object Faces','Colormap',[0 0 0]) 0033 elfc_prev = 'N'; 0034 max(fc) 0035 0036 for loop1 = 1:max(fc) 0037 % Create a logical array (lgelfc) to determine which faces are electrodes 0038 lgelfc(loop1) = logical(0); 0039 0040 [fcsrf,fci] = ng_extract_face(srf,vtx,fc,loop1); 0041 if ~isempty(fcsrf) 0042 % Add this face's vtx indices matrix to the cell array ttlfcsrf 0043 ttlfcsrf(loop1) = {fcsrf}; 0044 % Plot this face 0045 trimesh(fcsrf,vtx(:,1),vtx(:,2),vtx(:,3)) 0046 title(['Face number: ' num2str(loop1) ' of ' num2str(max(fc))]) 0047 axis equal 0048 axis(mshaxs) 0049 view(45,10) 0050 qstr =sprintf('Is this face an electrode? Y/N [%s] ',elfc_prev); 0051 elfc = input(qstr,'s'); 0052 if isempty(elfc) 0053 elfc = elfc_prev; 0054 else 0055 elfc_prev=elfc; 0056 end 0057 if (elfc=='y' | elfc=='Y') 0058 lgelfc(loop1) = logical(1); 0059 sels = [sels; fci]; % Concatenate indices into sels for this face 0060 end 0061 end 0062 end 0063 0064 0065 % Extract from the total face indices matrix (ttlfcsrf) the 0066 % faces which are electrodes and store them in the cell 0067 % array (elsrf) 0068 elsrf = ttlfcsrf(lgelfc); 0069 0070 close(gcf) 0071 % Display each electrode in turn as a wire mesh 0072 figure 0073 set(gcf,'Name','Wire Mesh Electrode Faces') 0074 for loop1 = 1:size(elsrf,2)-1 0075 trimesh(elsrf{loop1},vtx(:,1),vtx(:,2),vtx(:,3),'EdgeColor','red') 0076 title(['Electrode ' num2str(loop1) ': red']) 0077 axis equal 0078 axis(mshaxs) 0079 view(45,10) 0080 hidden off 0081 hold on 0082 pause(0.75) 0083 end 0084 title('Electrodes: red,') 0085 hidden off 0086 pause(2) 0087 0088 % Convert elsrf into the EIDORS-3D matrix electrode matrix format 0089 0090 nmel = size(elsrf,2); 0091 for loop1 = 1:nmel 0092 nmfc(loop1) = size(elsrf{loop1},1); 0093 end 0094 % Initiate electrode matrix (elec) & pad with zeros 0095 elec = zeros(nmel,3*max(nmfc)); 0096 % Put electrode surface information into elec 0097 for loop1 = 1:nmel 0098 for loop2 = 1:size(elsrf{loop1},1) 0099 elec(loop1,loop2*3-2:loop2*3)=elsrf{loop1}(loop2,:); 0100 end 0101 end