0001 function [p] = elec_open(p)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 if ~exist('p','var'),[p] = eeg_toolbox_defaults; end
0041 if isempty(p),[p] = eeg_toolbox_defaults; end
0042
0043 eegversion = '$Revision: 1.4 $';
0044 fprintf('ELEC_OPEN [v %s]\n',eegversion(11:15));
0045
0046 [path,name,ext] = fileparts(strcat(p.elec.path,filesep,p.elec.file));
0047 file = fullfile(path,[name ext]);
0048
0049
0050
0051 electype = lower(p.elec.type);
0052
0053 switch electype,
0054
0055 case {'cartesian','spherical1','spherical2'},
0056
0057 [elec,type,X,Y,Z,theta,phi,r] = elec_load(file,p.elec.type,0,0,0,p.elec.n);
0058
0059 index = find(type == 99);
0060 xo = X(index);
0061 yo = Y(index);
0062 zo = Z(index);
0063 p.elec.data.centroid = [xo yo zo];
0064
0065
0066 index = find(type == 69);
0067 elec = elec(index);
0068 x = X(index);
0069 y = Y(index);
0070 z = Z(index);
0071 theta = theta(index);
0072 phi = phi(index);
0073 r = r(index);
0074
0075 p.elec.data.label = elec;
0076 p.elec.data.x = x;
0077 p.elec.data.y = y;
0078 p.elec.data.z = z;
0079 p.elec.data.theta = theta;
0080 p.elec.data.phi = phi;
0081 p.elec.data.r = r;
0082
0083 index = find(type == 110);
0084 p.elec.data.nasion = [X(index) Y(index) Z(index)];
0085 index = find(type == 108);
0086 p.elec.data.lpa = [X(index) Y(index) Z(index)];
0087 index = find(type == 114);
0088 p.elec.data.rpa = [X(index) Y(index) Z(index)];
0089 index = find(type == 120);
0090 p.elec.data.ref = [X(index) Y(index) Z(index)];
0091
0092
0093
0094 case {'emse','elp'},
0095
0096 elp = emse_read_elp(file);
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 p.elec.data.ref(1) = elp.ref(2) * -1;
0120 p.elec.data.ref(2) = elp.ref(1);
0121 p.elec.data.ref(3) = elp.ref(3);
0122
0123 p.elec.data.x = elp.y * -1;
0124 p.elec.data.y = elp.x;
0125 p.elec.data.z = elp.z;
0126
0127 p.elec.data.centroid(1) = elp.origin(2) * -1;
0128 p.elec.data.centroid(2) = elp.origin(1);
0129 p.elec.data.centroid(3) = elp.origin(3);
0130
0131 p.elec.data.nasion = elp.nasion;
0132 p.elec.data.lpa = elp.lpa;
0133 p.elec.data.rpa = elp.rpa;
0134
0135 p.elec.data.label = elp.name;
0136
0137
0138 case 'brainstorm',
0139
0140 [p] = elec_load_brainstorm(p);
0141
0142
0143 case 'scan3ddasc',
0144
0145 scan3dd = elec_load_scan_3ddasc(file);
0146
0147 fprintf('...converting electrode XYZ from cm to meters.\n');
0148
0149 p.elec.data.x = scan3dd.x ./ 100;
0150 p.elec.data.y = scan3dd.y ./ 100;
0151 p.elec.data.z = scan3dd.z ./ 100;
0152
0153 p.elec.data.nasion = scan3dd.nasion ./ 100;
0154 p.elec.data.lpa = scan3dd.lpa ./ 100;
0155 p.elec.data.rpa = scan3dd.rpa ./ 100;
0156
0157 p.elec.data.label = scan3dd.label;
0158
0159 p.elec.data.ref = scan3dd.ref ./ 100;
0160
0161 p.elec.data.centroid = scan3dd.origin ./ 100;
0162
0163
0164 case 'scantri',
0165
0166
0167
0168 tri = elec_load_scan_tri(file);
0169
0170 p.elec.data.label = tri.label;
0171
0172 fprintf('...converting electrode XYZ from cm to meters.\n');
0173 p.elec.data.x = tri.XYZ(:,1) ./ 100;
0174 p.elec.data.y = tri.XYZ(:,2) ./ 100;
0175 p.elec.data.z = tri.XYZ(:,3) ./ 100;
0176
0177 fprintf('...guessing origin is at (0,0,0).\n');
0178 p.elec.data.centroid = [0 0 0];
0179
0180
0181 otherwise,
0182
0183 msg = sprintf('...cannot read file types %s\n',electype);
0184 error(msg);
0185
0186 end
0187
0188
0189
0190
0191
0192 x = p.elec.data.x;
0193 y = p.elec.data.y;
0194 z = p.elec.data.z;
0195
0196 xo = p.elec.data.centroid(1);
0197 yo = p.elec.data.centroid(2);
0198 zo = p.elec.data.centroid(3);
0199
0200 if ~isfield(p.elec.data,'theta'),
0201 [theta,phi,r] = elec_cart2sph(x,y,z,xo,yo,zo);
0202 p.elec.data.theta = theta;
0203 p.elec.data.phi = phi;
0204 p.elec.data.r = r;
0205 end
0206
0207
0208 Xrad = (max(x)-min(x))/2;
0209 Yrad = (max(y)-min(y))/2;
0210 Zrad = (max(z)-min(z));
0211 p.elec.data.R = [Xrad Yrad Zrad];
0212
0213
0214 [r,Xel,Yel,Zel] = elec_ellipse_fit(x,y,z,xo,yo,zo,100,p.elec.plot);
0215 p.elec.data.Xel = Xel;
0216 p.elec.data.Yel = Yel;
0217 p.elec.data.Zel = Zel;
0218 p.elec.data.Rel = r;
0219
0220
0221 [r,Xsp,Ysp,Zsp] = elec_sphere_project(x,y,z,xo,yo,zo,1,p.elec.plot);
0222 p.elec.data.Xsp = Xsp;
0223 p.elec.data.Ysp = Ysp;
0224 p.elec.data.Zsp = Zsp;
0225 p.elec.data.Rsp = [r r r];
0226
0227
0228
0229
0230
0231
0232
0233
0234 p.elec.data.regions = elec_regions;
0235
0236 return