Home > vbmeg > external > mne > fiff_write_coord_trans.m

fiff_write_coord_trans

PURPOSE ^

SYNOPSIS ^

function fiff_write_coord_trans(fid,trans)

DESCRIPTION ^

 fiff_write_coord_trans(fid,trans)
 
 Writes a coordinate transformation structure

     fid           An open fif file descriptor
     trans         The coordinate transfomation structure

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fiff_write_coord_trans(fid,trans)
0002 %
0003 % fiff_write_coord_trans(fid,trans)
0004 %
0005 % Writes a coordinate transformation structure
0006 %
0007 %     fid           An open fif file descriptor
0008 %     trans         The coordinate transfomation structure
0009 %
0010 
0011 %
0012 %
0013 %   Author : Matti Hamalainen, MGH Martinos Center
0014 %   License : BSD 3-clause
0015 %
0016 %   Revision 1.4  2006/04/23 15:29:40  msh
0017 %   Added MGH to the copyright
0018 %
0019 %   Revision 1.3  2006/04/12 10:29:02  msh
0020 %   Made evoked data writing compatible with the structures returned in reading.
0021 %
0022 %   Revision 1.2  2006/04/10 23:26:54  msh
0023 %   Added fiff reading routines
0024 %
0025 %   Revision 1.1  2005/12/05 16:01:04  msh
0026 %   Added an initial set of fiff writing routines.
0027 %
0028 %
0029 
0030 me='MNE:fiff_write_coord_trans';
0031 
0032 if nargin ~= 2
0033         error(me,'Incorrect number of arguments');
0034 end
0035 
0036 FIFF_COORD_TRANS=222;
0037 FIFFT_COORD_TRANS_STRUCT=35;
0038 FIFFV_NEXT_SEQ=0;
0039 
0040 
0041 %?typedef struct _fiffCoordTransRec {
0042 %  fiff_int_t   from;                   /*!< Source coordinate system. */
0043 %  fiff_int_t   to;                     /*!< Destination coordinate system. */
0044 %  fiff_float_t rot[3][3];              /*!< The forward transform (rotation part) */
0045 %  fiff_float_t move[3];                /*!< The forward transform (translation part) */
0046 %  fiff_float_t invrot[3][3];           /*!< The inverse transform (rotation part) */
0047 %  fiff_float_t invmove[3];             /*!< The inverse transform (translation part) */
0048 %} *fiffCoordTrans, fiffCoordTransRec;  /*!< Coordinate transformation descriptor */
0049 
0050 datasize=4*2*12 + 4*2;
0051 count = fwrite(fid,int32(FIFF_COORD_TRANS),'int32');
0052 if count ~= 1
0053     error(me,'write failed');
0054 end
0055 count = fwrite(fid,int32(FIFFT_COORD_TRANS_STRUCT),'int32');
0056 if count ~= 1
0057     error(me,'write failed');
0058 end
0059 count = fwrite(fid,int32(datasize),'int32');
0060 if count ~= 1
0061     error(me,'write failed');
0062 end
0063 count = fwrite(fid,int32(FIFFV_NEXT_SEQ),'int32');
0064 if count ~= 1
0065     error(me,'write failed');
0066 end
0067 %
0068 %   Start writing fiffCoordTransRec
0069 %
0070 count = fwrite(fid,int32(trans.from),'int32');
0071 if count ~= 1
0072     error(me,'write failed');
0073 end
0074 count = fwrite(fid,int32(trans.to),'int32');
0075 if count ~= 1
0076     error(me,'write failed');
0077 end
0078 %
0079 %   The transform...
0080 %
0081 rot=trans.trans(1:3,1:3)';
0082 move=trans.trans(1:3,4)';
0083 count = fwrite(fid,single(rot),'single');
0084 if count ~= 9
0085     error(me,'write failed');
0086 end
0087 count = fwrite(fid,single(move),'single');
0088 if count ~= 3
0089     error(me,'write failed');
0090 end
0091 %
0092 %   ...and its inverse
0093 %
0094 trans_inv=inv(trans.trans);
0095 rot=trans_inv(1:3,1:3)';
0096 move=trans_inv(1:3,4)';
0097 count = fwrite(fid,single(rot),'single');
0098 if count ~= 9
0099     error(me,'write failed');
0100 end
0101 count = fwrite(fid,single(move),'single');
0102 if count ~= 3
0103     error(me,'write failed');
0104 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005