Home > bioelectromagnetism > elec_load_scan_3ddasc.m

elec_load_scan_3ddasc

PURPOSE ^

elec_load_scan_3ddasc - read ascii export of Neuroscan 3DD file

SYNOPSIS ^

function [scan3dd] = elec_load_scan_3ddasc(filename)

DESCRIPTION ^

 elec_load_scan_3ddasc - read ascii export of Neuroscan 3DD file
 
 Load an ascii electrode file and return 
 the electrode labels and coordinates.  This
 function can read and return Cartesian (x,y,z) 
 and/or spherical (theta,phi,r) coordinates.

 [scan3dd] = elec_load_scan_3ddasc(filename)
 
 where:
 
 file = '<path><filename>' with row format '%s %d %f %f %f'
 
 The file format is that of NeuroScan 3Dspace ascii 
 export files.  Each row of the file comprises an electrode label, 
 an electrode type code (see below), and the x,y,z coordinates (cm).
 Each field is separated by spaces.  For example,
 
 Fz    69  Xcm Ycm Zcm
 
 Example result:

 scan3dd = 
 
      label: {1x128 cell}
          x: [128x1 double]
          y: [128x1 double]
          z: [128x1 double]
        hsp: [1617x3 double]
     nasion: [-0.0333 9.0341 0]
        lpa: [-6.9128 0 0]
        rpa: [6.9128 0 0]
     origin: [0 0 0]
        ref: [0 9.9341 0]

 All coordinates are in centimeters; +X is right, +Y is anterior
 and +Z is superior.
 
 Notes:
 
 i) Type is defined as follows (from Neuroscan 3Dspace ascii export):

           Electrode               Type
           ---------               ----
           Nasion                   110 (or 78)
           Left                     108 (or 76)
           Right                    114 (or 82)
           electrodes                69
           Centroid (origin)         99 (or 67; eg <0,0,0>)
           Ref                      120 (or 88)
           Scalp Points (hsp)        32

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [scan3dd] = elec_load_scan_3ddasc(filename)
0002 
0003 % elec_load_scan_3ddasc - read ascii export of Neuroscan 3DD file
0004 %
0005 % Load an ascii electrode file and return
0006 % the electrode labels and coordinates.  This
0007 % function can read and return Cartesian (x,y,z)
0008 % and/or spherical (theta,phi,r) coordinates.
0009 %
0010 % [scan3dd] = elec_load_scan_3ddasc(filename)
0011 %
0012 % where:
0013 %
0014 % file = '<path><filename>' with row format '%s %d %f %f %f'
0015 %
0016 % The file format is that of NeuroScan 3Dspace ascii
0017 % export files.  Each row of the file comprises an electrode label,
0018 % an electrode type code (see below), and the x,y,z coordinates (cm).
0019 % Each field is separated by spaces.  For example,
0020 %
0021 % Fz    69  Xcm Ycm Zcm
0022 %
0023 % Example result:
0024 %
0025 % scan3dd =
0026 %
0027 %      label: {1x128 cell}
0028 %          x: [128x1 double]
0029 %          y: [128x1 double]
0030 %          z: [128x1 double]
0031 %        hsp: [1617x3 double]
0032 %     nasion: [-0.0333 9.0341 0]
0033 %        lpa: [-6.9128 0 0]
0034 %        rpa: [6.9128 0 0]
0035 %     origin: [0 0 0]
0036 %        ref: [0 9.9341 0]
0037 %
0038 % All coordinates are in centimeters; +X is right, +Y is anterior
0039 % and +Z is superior.
0040 %
0041 % Notes:
0042 %
0043 % i) Type is defined as follows (from Neuroscan 3Dspace ascii export):
0044 %
0045 %           Electrode               Type
0046 %           ---------               ----
0047 %           Nasion                   110 (or 78)
0048 %           Left                     108 (or 76)
0049 %           Right                    114 (or 82)
0050 %           electrodes                69
0051 %           Centroid (origin)         99 (or 67; eg <0,0,0>)
0052 %           Ref                      120 (or 88)
0053 %           Scalp Points (hsp)        32
0054 %
0055 %
0056 
0057 
0058 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0059 
0060 % Licence:  GNU GPL, no express or implied warranties
0061 % History:  08/1999, Darren.Weber_at_radiology.ucsf.edu
0062 %           08/2003, Darren.Weber_at_radiology.ucsf.edu
0063 %                    complete rewrite, replacing elec_load.m
0064 %                    new version of 3Dspace exports different type numbers ;-)
0065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0066 
0067 
0068 ver = '$Revision: 1.1 $';
0069 fprintf('\nELEC_LOAD_SCAN_3DDASC [v %s]\n',ver(11:15));
0070 
0071 tic;
0072 
0073 [path,name,ext] = fileparts(filename);
0074 file = fullfile(path,[name ext]);
0075 
0076 fprintf('...loading electrodes from:\n\t%s\n', file);
0077 
0078 scan3dd = read_3dd(file);
0079 
0080 fprintf('...loaded %d electrodes\n', size(scan3dd.x,1));
0081 
0082 t = toc; fprintf('...done (%6.2f sec).\n\n',t);
0083 
0084 return
0085 
0086 
0087 
0088 
0089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0091 function scan3dd = read_3dd(file),
0092 
0093 
0094 scan3dd.label = [];
0095 scan3dd.x = [];
0096 scan3dd.y = [];
0097 scan3dd.z = [];
0098 scan3dd.hsp = [];
0099 
0100 
0101 
0102 fid = fopen(file);
0103 if fid < 0,
0104   msg = sprintf('cannot open file: %s\n',file);
0105   error(msg);
0106 end
0107 
0108 % 3DD ascii files contain position information for
0109 % fiducial, sensor, and head shape fields.
0110 
0111 % First get the fiducial points by reading the whole file
0112 % (clumsy, but exhaustive search for field indicators).
0113 
0114 % Fiducial points are required for MRI registration. They are
0115 % the nasion, left and right preauricular points, eg:
0116 
0117 %      Nasion    78    -0.033340    9.034104    0.000000
0118 %      Left    76    -6.912818    -0.000000    0.000000
0119 %      Right    82    6.912818    0.000000    -0.000000
0120 
0121 fprintf('...searching for fiducials...');
0122 
0123 n = 0;
0124 while n < 5,
0125   tmp = fgetl(fid);
0126   if tmp < 0, break; end
0127   
0128   tmp = lower(tmp);
0129   
0130   if strfind(tmp,'nasion'),
0131     tmp = sscanf(tmp,'%s %d %f %f %f');
0132     scan3dd.nasion = [tmp(end-2) tmp(end-1) tmp(end)];
0133     n = n + 1;
0134     continue;
0135   end
0136   if strfind(tmp,'left'),
0137     tmp = sscanf(tmp,'%s %d %f %f %f');
0138     scan3dd.lpa = [tmp(end-2) tmp(end-1) tmp(end)];
0139     n = n + 1;
0140     continue;
0141   end
0142   if strfind(tmp,'right'),
0143     tmp = sscanf(tmp,'%s %d %f %f %f');
0144     scan3dd.rpa = [tmp(end-2) tmp(end-1) tmp(end)];
0145     n = n + 1;
0146     continue;
0147   end
0148   if strfind(tmp,'centroid'),
0149     tmp = sscanf(tmp,'%s %d %f %f %f');
0150     scan3dd.origin = [tmp(end-2) tmp(end-1) tmp(end)];
0151     n = n + 1;
0152     continue;
0153   end
0154   if strfind(tmp,'ref'),
0155     tmp = sscanf(tmp,'%s %d %f %f %f');
0156     scan3dd.ref = [tmp(end-2) tmp(end-1) tmp(end)];
0157     n = n + 1;
0158     continue;
0159   end
0160 end
0161 
0162 frewind(fid);
0163 fprintf('done\n');
0164 
0165 
0166 fprintf('...searching for electrodes...');
0167 
0168 ok = 1;
0169 while ok,
0170   tmp = fgetl(fid);
0171   if tmp < 0, break; end
0172   
0173   if strfind(lower(tmp),'nasion'),   continue; end
0174   if strfind(lower(tmp),'left'),     continue; end
0175   if strfind(lower(tmp),'right'),    continue; end
0176   if strfind(lower(tmp),'centroid'), continue; end
0177   if strfind(lower(tmp),'ref'),      continue; end
0178   
0179   tmp = sscanf(tmp,'%s %d %f %f %f');
0180   
0181   if tmp(end-3) == 69,
0182     scan3dd.label{end+1} = char(tmp(1:end-4))';
0183     scan3dd.x(end+1,1) = tmp(end-2);
0184     scan3dd.y(end+1,1) = tmp(end-1);
0185     scan3dd.z(end+1,1) = tmp(end);
0186     continue;
0187   end
0188   if strfind(char(tmp(1:end-4))','32'),
0189     break;
0190     % found a head shape point
0191     scan3dd.hsp(end+1,:) = [tmp(end-2),tmp(end-1),tmp(end)];
0192     continue;
0193   end
0194 end
0195 
0196 
0197 frewind(fid);
0198 fprintf('done\n');
0199 
0200 
0201 
0202 fprintf('...searching for head shape points...');
0203 
0204 ok = 1;
0205 while ok,
0206   tmp = fgetl(fid);
0207   if tmp < 0, break; end
0208   
0209   if strfind(lower(tmp),'nasion'),   continue; end
0210   if strfind(lower(tmp),'left'),     continue; end
0211   if strfind(lower(tmp),'right'),    continue; end
0212   if strfind(lower(tmp),'centroid'), continue; end
0213   if strfind(lower(tmp),'ref'),      continue; end
0214   if strfind(lower(tmp),'69'),       continue; end
0215   
0216   tmp = sscanf(tmp,'%d %f %f %f');
0217   
0218   if tmp(end-3) == 32,
0219     % found a head shape point
0220     scan3dd.hsp(end+1,:) = [tmp(end-2),tmp(end-1),tmp(end)];
0221     continue;
0222   end
0223 end
0224 
0225 frewind(fid);
0226 fprintf('done\n');
0227 
0228 fclose(fid);
0229 
0230 
0231 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003