Home > bioelectromagnetism > elec_load_scan3ddasc.m

elec_load_scan3ddasc

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.
 
 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.
0039 %
0040 % Notes:
0041 %
0042 % i) Type is defined as follows (from Neuroscan 3Dspace ascii export):
0043 %
0044 %           Electrode               Type
0045 %           ---------               ----
0046 %           Nasion                   110 (or 78)
0047 %           Left                     108 (or 76)
0048 %           Right                    114 (or 82)
0049 %           electrodes                69
0050 %           Centroid (origin)         99 (or 67; eg <0,0,0>)
0051 %           Ref                      120 (or 88)
0052 %           Scalp Points (hsp)        32
0053 %
0054 %
0055 
0056 
0057 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0058 
0059 % Licence:  GNU GPL, no express or implied warranties
0060 % History:  08/1999, Darren.Weber_at_radiology.ucsf.edu
0061 %           08/2003, Darren.Weber_at_radiology.ucsf.edu
0062 %                    complete rewrite, replacing elec_load.m
0063 %                    new version of 3Dspace exports different type numbers ;-)
0064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0065 
0066 
0067 ver = '$Revision: 1.1 $';
0068 fprintf('\nELEC_LOAD_SCAN3DDASC [v %s]\n',ver(11:15));
0069 
0070 tic;
0071 
0072 [path,name,ext] = fileparts(filename);
0073 file = fullfile(path,[name ext]);
0074 
0075 fprintf('...loading electrodes from:\n\t%s\n', file);
0076 
0077 scan3dd = read_3dd(file);
0078 
0079 fprintf('...loaded %d electrodes\n', size(scan3dd.x,1));
0080 
0081 t = toc; fprintf('...done (%6.2f sec).\n\n',t);
0082 
0083 return
0084 
0085 
0086 
0087 
0088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0090 function scan3dd = read_3dd(file),
0091 
0092 
0093 scan3dd.label = [];
0094 scan3dd.x = [];
0095 scan3dd.y = [];
0096 scan3dd.z = [];
0097 scan3dd.hsp = [];
0098 
0099 
0100 
0101 fid = fopen(file);
0102 if fid < 0,
0103   msg = sprintf('cannot open file: %s\n',file);
0104   error(msg);
0105 end
0106 
0107 % 3DD ascii files contain position information for
0108 % fiducial, sensor, and head shape fields.
0109 
0110 % First get the fiducial points by reading the whole file
0111 % (clumsy, but exhaustive search for field indicators).
0112 
0113 % Fiducial points are required for MRI registration. They are
0114 % the nasion, left and right preauricular points, eg:
0115 
0116 %      Nasion    78    -0.033340    9.034104    0.000000
0117 %      Left    76    -6.912818    -0.000000    0.000000
0118 %      Right    82    6.912818    0.000000    -0.000000
0119 
0120 fprintf('...searching for fiducials...');
0121 
0122 n = 0;
0123 while n < 5,
0124   tmp = fgetl(fid);
0125   if tmp < 0, break; end
0126   
0127   tmp = lower(tmp);
0128   
0129   if strfind(tmp,'nasion'),
0130     tmp = sscanf(tmp,'%s %d %f %f %f');
0131     scan3dd.nasion = [tmp(end-2) tmp(end-1) tmp(end)];
0132     n = n + 1;
0133     continue;
0134   end
0135   if strfind(tmp,'left'),
0136     tmp = sscanf(tmp,'%s %d %f %f %f');
0137     scan3dd.lpa = [tmp(end-2) tmp(end-1) tmp(end)];
0138     n = n + 1;
0139     continue;
0140   end
0141   if strfind(tmp,'right'),
0142     tmp = sscanf(tmp,'%s %d %f %f %f');
0143     scan3dd.rpa = [tmp(end-2) tmp(end-1) tmp(end)];
0144     n = n + 1;
0145     continue;
0146   end
0147   if strfind(tmp,'centroid'),
0148     tmp = sscanf(tmp,'%s %d %f %f %f');
0149     scan3dd.origin = [tmp(end-2) tmp(end-1) tmp(end)];
0150     n = n + 1;
0151     continue;
0152   end
0153   if strfind(tmp,'ref'),
0154     tmp = sscanf(tmp,'%s %d %f %f %f');
0155     scan3dd.ref = [tmp(end-2) tmp(end-1) tmp(end)];
0156     n = n + 1;
0157     continue;
0158   end
0159 end
0160 
0161 frewind(fid);
0162 fprintf('done\n');
0163 
0164 
0165 fprintf('...searching for electrodes...');
0166 
0167 ok = 1;
0168 while ok,
0169   tmp = fgetl(fid);
0170   if tmp < 0, break; end
0171   
0172   if strfind(lower(tmp),'nasion'),   continue; end
0173   if strfind(lower(tmp),'left'),     continue; end
0174   if strfind(lower(tmp),'right'),    continue; end
0175   if strfind(lower(tmp),'centroid'), continue; end
0176   if strfind(lower(tmp),'ref'),      continue; end
0177   
0178   tmp = sscanf(tmp,'%s %d %f %f %f');
0179   
0180   if tmp(end-3) == 69,
0181     scan3dd.label{end+1} = char(tmp(1:end-4))';
0182     scan3dd.x(end+1,1) = tmp(end-2);
0183     scan3dd.y(end+1,1) = tmp(end-1);
0184     scan3dd.z(end+1,1) = tmp(end);
0185     continue;
0186   end
0187   if strfind(char(tmp(1:end-4))','32'),
0188     break;
0189     % found a head shape point
0190     scan3dd.hsp(end+1,:) = [tmp(end-2),tmp(end-1),tmp(end)];
0191     continue;
0192   end
0193 end
0194 
0195 
0196 frewind(fid);
0197 fprintf('done\n');
0198 
0199 
0200 
0201 fprintf('...searching for head shape points...');
0202 
0203 ok = 1;
0204 while ok,
0205   tmp = fgetl(fid);
0206   if tmp < 0, break; end
0207   
0208   if strfind(lower(tmp),'nasion'),   continue; end
0209   if strfind(lower(tmp),'left'),     continue; end
0210   if strfind(lower(tmp),'right'),    continue; end
0211   if strfind(lower(tmp),'centroid'), continue; end
0212   if strfind(lower(tmp),'ref'),      continue; end
0213   if strfind(lower(tmp),'69'),       continue; end
0214   
0215   tmp = sscanf(tmp,'%d %f %f %f');
0216   
0217   if tmp(end-3) == 32,
0218     % found a head shape point
0219     scan3dd.hsp(end+1,:) = [tmp(end-2),tmp(end-1),tmp(end)];
0220     continue;
0221   end
0222 end
0223 
0224 frewind(fid);
0225 fprintf('done\n');
0226 
0227 fclose(fid);
0228 
0229 
0230 return

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