| | function [hc] = read_ctf_hc(filename) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | fb = false; |
| |
|
| | hc.standard.nas = [0 0 0]; |
| | hc.standard.lpa = [0 0 0]; |
| | hc.standard.rpa = [0 0 0]; |
| | hc.dewar.nas = [0 0 0]; |
| | hc.dewar.lpa = [0 0 0]; |
| | hc.dewar.rpa = [0 0 0]; |
| | hc.head.nas = [0 0 0]; |
| | hc.head.lpa = [0 0 0]; |
| | hc.head.rpa = [0 0 0]; |
| |
|
| | fid = fopen(filename, 'r'); |
| | if fid==-1 |
| | error(sprintf('could not open file %s', filename)); |
| | end |
| |
|
| | fseek(fid, 0, 'bof'); |
| | line = []; |
| |
|
| | if fb |
| | fprintf('reading standard coil positions with respect to the dewar\n'); |
| | end |
| | |
| | |
| | |
| | while ~strcmp(line, 'standard nasion coil position relative to dewar (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.nas(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.nas(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.nas(3) = str2num(r(2:end)); |
| | |
| | while ~(strcmp(line, 'stadard left ear coil position relative to dewar (cm):') | ... |
| | strcmp(line, 'standard left ear coil position relative to dewar (cm):')) |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.lpa(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.lpa(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.lpa(3) = str2num(r(2:end)); |
| | while ~strcmp(line, 'standard right ear coil position relative to dewar (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.rpa(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.rpa(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.standard.rpa(3) = str2num(r(2:end)); |
| |
|
| | if fb |
| | fprintf('reading measured coil positions with respect to the dewar\n'); |
| | end |
| | |
| | |
| | |
| | while ~strcmp(line, 'measured nasion coil position relative to dewar (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.nas(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.nas(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.nas(3) = str2num(r(2:end)); |
| | while ~strcmp(line, 'measured left ear coil position relative to dewar (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.lpa(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.lpa(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.lpa(3) = str2num(r(2:end)); |
| | while ~strcmp(line, 'measured right ear coil position relative to dewar (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.rpa(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.rpa(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.dewar.rpa(3) = str2num(r(2:end)); |
| |
|
| | if fb |
| | fprintf('reading measured coil positions with respect to the head\n'); |
| | end |
| | |
| | |
| | |
| | while ~strcmp(line, 'measured nasion coil position relative to head (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.nas(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.nas(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.nas(3) = str2num(r(2:end)); |
| | while ~strcmp(line, 'measured left ear coil position relative to head (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.lpa(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.lpa(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.lpa(3) = str2num(r(2:end)); |
| | while ~strcmp(line, 'measured right ear coil position relative to head (cm):') |
| | line = fgetl(fid); |
| | if ~ischar(line) & line==-1, error('premature end of file'), end |
| | end |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.rpa(1) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.rpa(2) = str2num(r(2:end)); |
| | line = fgetl(fid); [t, r] = strtok(line, '='); hc.head.rpa(3) = str2num(r(2:end)); |
| |
|
| | fclose(fid); |
| |
|
| | if fb |
| | fprintf('computing transformation matrix\n'); |
| | end |
| |
|
| | |
| | d_x = hc.dewar.nas - (hc.dewar.lpa + hc.dewar.rpa)/2; |
| | d_z = cross(d_x, hc.dewar.lpa - hc.dewar.rpa); |
| | d_y = cross(d_z, d_x); |
| | d_x = d_x / norm(d_x); |
| | d_y = d_y / norm(d_y); |
| | d_z = d_z / norm(d_z); |
| |
|
| | |
| | |
| | hc.translation = -(hc.dewar.lpa + hc.dewar.rpa)/2; |
| | hc.rotation = inv([d_x' d_y' d_z']); |
| | |
| | % construct the homogenous coordinate transformation matrix |
| | % from the subsequent translation and rotation |
| | hc.homogenous = eye(4,4); |
| | hc.homogenous(1:3,4) = hc.rotation * hc.translation'; |
| | hc.homogenous(1:3,1:3) = hc.rotation; |
| |
|
| | |
| | hc.affine = hc.homogenous'; |
| | hc.affine = hc.affine(1:12); |
| | |
| | |