function [elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,elec_face,sels,cnts,VV); This function must be called recursively to sellect boundary faces building up the elec_face. You will need to reshape this matrix appropriately to get the elec matrix, depending on how many faces there are in each electrode. vtx = The vertices matrix srf = The boundary surfaces elec_face = A 3 column matrix holding the boundary faces to be used for constructing the electrodes sels = The indices in srf matrix of the sellected surfaces cnts = The coordinates of the center of each triangular boundary surface. VV = The last viewing angle. Call this function as follows [elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,[],[],[],[30 60]); ONLY FOR THE FIRST TIME, for the first row of elec_face. and then ... [elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,elec_face,sels,cnts,VV); Once you have gathered the faces to be assigned as electrodes, provided that you have (the same) N number of faces per electrode and these are indexed in sequence inside "elec_face", then use something like "elec = reshape(elec_face',(N*3),number of electrodes)';" In this case note that "elec_face = srf(sels,:);" should be valid.
0001 function [elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,elec_face,sels,cnts,VV); 0002 %function [elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,elec_face,sels,cnts,VV); 0003 % 0004 %This function must be called recursively to sellect boundary faces building up 0005 %the elec_face. You will need to reshape this matrix appropriately to get the elec 0006 %matrix, depending on how many faces there are in each electrode. 0007 % 0008 % 0009 % 0010 %vtx = The vertices matrix 0011 %srf = The boundary surfaces 0012 %elec_face = A 3 column matrix holding the boundary faces to be used for constructing 0013 % the electrodes 0014 %sels = The indices in srf matrix of the sellected surfaces 0015 %cnts = The coordinates of the center of each triangular boundary surface. 0016 %VV = The last viewing angle. 0017 % 0018 %Call this function as follows 0019 % 0020 %[elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,[],[],[],[30 60]); 0021 %ONLY FOR THE FIRST TIME, for the first row of elec_face. 0022 %and then ... 0023 %[elec_face,sels,cnts,VV] = set_electrodes(vtx,srf,elec_face,sels,cnts,VV); 0024 %Once you have gathered the faces to be assigned as electrodes, 0025 %provided that you have (the same) N number of faces per electrode and these are indexed in 0026 %sequence inside "elec_face", then use something like 0027 %"elec = reshape(elec_face',(N*3),number of electrodes)';" 0028 %In this case note that "elec_face = srf(sels,:);" should be valid. 0029 0030 0031 if size(cnts,1) == 0 0032 0033 0034 cnts = []; % Vector containing the geometric center of each triangular 0035 % surface in x,y,z coordinates. 0036 0037 for i=1:size(srf,1) 0038 0039 a = srf(i,1); 0040 b = srf(i,2); 0041 c = srf(i,3); 0042 0043 ccnx = (vtx(a,1) + vtx(b,1) + vtx(c,1))/3; 0044 ccny = (vtx(a,2) + vtx(b,2) + vtx(c,2))/3; 0045 ccnz = (vtx(a,3) + vtx(b,3) + vtx(c,3))/3; 0046 0047 ccn = [ccnx,ccny,ccnz]; 0048 0049 cnts = [cnts; ccn]; 0050 end 0051 end 0052 0053 %Plot the surface 0054 0055 trimesh(srf,vtx(:,1),vtx(:,2),vtx(:,3)); 0056 axis image; 0057 set(gcf,'Colormap',[0 0 0]); 0058 grid off 0059 hidden off %%%% If you have viewing problems comment this line 0060 view(VV); 0061 0062 0063 %and any previous patches 0064 if ~isempty(sels) == 1 0065 for y=1:size(sels) 0066 paint_electrodes(sels(y),srf,vtx); 0067 end 0068 end 0069 0070 disp('Rotate and click on the figure to locate electrode and then press ENTER'); 0071 disp('Try to aim near the centre of the triangular face from a small angle'); 0072 0073 pause; 0074 0075 VV = get(gca,'View'); 0076 0077 [sel] = laserbeam(vtx,srf,cnts); 0078 0079 paint_electrodes(sel,srf,vtx); 0080 0081 0082 %Now confirmation about sel is required. 0083 0084 button = questdlg('Was the positioning OK?','Electrode confirmation','Yes','No','Help','No'); 0085 if strcmp(button,'Yes') 0086 disp('Creating electrode'); 0087 elseif strcmp(button,'No') 0088 disp('Canceling electrode'); 0089 elseif strcmp(button,'Help') 0090 disp('Sorry, no help available') 0091 end 0092 0093 0094 if strcmp(button,'Yes') 0095 elec_face = [elec_face; srf(sel,:)]; 0096 sels = [sels;sel]; 0097 end 0098 0099 0100 if strcmp(button,'No') 0101 0102 elec_face = elec_face; 0103 0104 %Plot the surface 0105 trimesh(srf,vtx(:,1),vtx(:,2),vtx(:,3)); 0106 axis image; 0107 set(gcf,'Colormap',[0 0 0]); 0108 grid off 0109 hidden off %%%% If you have viewing problems, comment this line 0110 0111 for u=1:size(sels) 0112 paint_electrodes(sels(u),srf,vtx); 0113 end 0114 0115 end 0116 0117 view(VV); 0118 0119 0120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0121 % This is part of the EIDORS suite. 0122 % Copyright (c) N. Polydorides 2003 0123 % Copying permitted under terms of GNU GPL 0124 % See enclosed file gpl.html for details. 0125 % EIDORS 3D version 2.0 0126 % MATLAB version 5.3 R11 0127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%