Home > bioelectromagnetism > emse_write_wfr.m

emse_write_wfr

PURPOSE ^

emse_write_wfr - write mesh to EMSE wireframe (.wfr)

SYNOPSIS ^

function emse_write_wfr(file,vertex,face,meshtype)

DESCRIPTION ^

 emse_write_wfr - write mesh to EMSE wireframe (.wfr)
 
 emse_write_wfr(file,vertex,face,meshtype)
 
 Write a .wfr file, in minor revision 3 format (ascii).
 See the EMSE website at http://www.sourcesignal.com
 for more information on file formats.
 
 This function assumes the vertex coordinate axes are 
 +X anterior, +Y left, +Z superior

 vertex - Nx3 matrix of XYZ values (in meters)
 face - Nx3 matrix of vertex indices for triangulation
 meshtype - a string, with values of:

     'unknown',     
     'scalp',       
     'outer skull', 
     'inner skull', 
     'cortex',

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function emse_write_wfr(file,vertex,face,meshtype)
0002 
0003 % emse_write_wfr - write mesh to EMSE wireframe (.wfr)
0004 %
0005 % emse_write_wfr(file,vertex,face,meshtype)
0006 %
0007 % Write a .wfr file, in minor revision 3 format (ascii).
0008 % See the EMSE website at http://www.sourcesignal.com
0009 % for more information on file formats.
0010 %
0011 % This function assumes the vertex coordinate axes are
0012 % +X anterior, +Y left, +Z superior
0013 %
0014 % vertex - Nx3 matrix of XYZ values (in meters)
0015 % face - Nx3 matrix of vertex indices for triangulation
0016 % meshtype - a string, with values of:
0017 %
0018 %     'unknown',
0019 %     'scalp',
0020 %     'outer skull',
0021 %     'inner skull',
0022 %     'cortex',
0023 %
0024 
0025 
0026 % $Revision: 1.1 $ $Date: 2005/01/21 04:33:18 $
0027 
0028 
0029 % Copyright (C) 2004  Darren L. Weber
0030 %
0031 % This program is free software; you can redistribute it and/or
0032 % modify it under the terms of the GNU General Public License
0033 % as published by the Free Software Foundation; either version 2
0034 % of the License, or (at your option) any later version.
0035 %
0036 % This program is distributed in the hope that it will be useful,
0037 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0038 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0039 % GNU General Public License for more details.
0040 %
0041 % You should have received a copy of the GNU General Public License
0042 % along with this program; if not, write to the Free Software
0043 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
0044 % USA.
0045 
0046 
0047 % History:  12/2004 Darren.Weber_at_radiology.ucsf.edu
0048 %                 - created function from mesh_emse2matlab
0049 %
0050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0051 
0052 ver = '$Revision: 1.1 $ $Date: 2005/01/21 04:33:18 $';
0053 fprintf('\nEMSE_WRITE_WFR [v%s]\n',ver(11:15));
0054 
0055 [path,name,ext] = fileparts(file);
0056 ext = '.wfr';
0057 file = fullfile(path,[name ext]);
0058 fprintf('...writing to: %s\n',file);
0059 
0060 fid = fopen(file,'w','ieee-le');
0061 
0062 if(fid == -1),
0063   msg = sprintf('...could not open file: %s',file);
0064   error(msg);
0065 else
0066   
0067   % Write prolog
0068   fprintf(fid,'3\t4000\n');
0069   fprintf(fid,'3\n');
0070   
0071   % Write mesh type
0072   type = lower(meshtype);
0073   switch type,
0074     case 'unknown',     fprintf(fid,  '0\n');
0075     case 'scalp',       fprintf(fid, '40\n');
0076     case 'outer skull', fprintf(fid, '80\n');
0077     case 'inner skull', fprintf(fid,'100\n');
0078     case 'cortex',      fprintf(fid,'200\n');
0079     case 'pial',        fprintf(fid,'200\n'); % cortex variant
0080     case 'white',       fprintf(fid,'200\n'); % cortex variant
0081     case 'smoothwm',    fprintf(fid,'200\n'); % cortex variant
0082     otherwise,          fprintf(fid,  '0\n');
0083       fprintf('\n...WARNING, unknown meshtype!\n\n');
0084   end
0085   
0086   
0087   % EMSE Voxel Coordinates
0088   % Voxel coordinates measure location in terms of the voxels inherent in
0089   % the given volumetric set. The origin is the bottom (inferior) axial
0090   % slice, the posterior row and in the rightmost column. This coordinate
0091   % system is right-handed (although, internally, the origin is in the
0092   % anterior row, and thus is left-handed; this representation is not
0093   % available to the user). The order of the displayed coordinates is
0094   % (slice#, row#, column#).
0095   %
0096   % EMSE MRI Coordinates
0097   % MRI coordinates share the same origin as internal voxel coordinates,
0098   % but differ from the latter in two ways: first, the coordinates
0099   % are measured in millimeters, not voxels. Secondly, the origin is that
0100   % of the internal representation; that is, the inferior slice, anterior
0101   % row and rightmost column. As mentioned above, this internal representation
0102   % is left-handed. To correct for this, the row axis is numbered in the
0103   % opposite direction, making the displayed coordinate system right-handed.
0104   % The order of the displayed coordinates is (x, y, z).
0105   
0106   % Given a point P(x,y,z) in head frame (the activation point on the
0107   % cortical mesh) and you want to find the corresponding voxel in the
0108   % vmi file.  Symbolically you have P(head) and you want to find P(voxel).
0109   %
0110   % 1.  The registration file contains the matrix HeadToImage,
0111   %     so P(MRI-mm) = HeadToImage*P(head), where P(MRI-mm) is the
0112   %     point in MRI coordinates.
0113   % 2.  From the voxel size, you can find P(MRI-voxel), which
0114   %     is the MRI coordinates expressed in voxels
0115   % 3.  Use the offset between the MRI coordinate frame and
0116   %     the Image coordinate frame to find P(voxel).
0117   %
0118   %Demetrios Voreades, Ph.D.
0119   %Applications Engineer, Source Signal Imaging
0120   %
0121   
0122   
0123   % Rotate -90 degrees around Z, given that emse coordinates
0124   % have +X through Nasion and +Y through left ear.
0125   fprintf('...assuming coordinate axes are +X anterior, +Y left, +Z superior\n');
0126   %vertex = rz(vertex,-90,'degrees');
0127   
0128   % Write vertex data
0129   for v = 1:size(vertex,1),
0130     fprintf(fid,'v\t%12.8f\t%12.8f\t%12.8f\n',vertex(v,1),vertex(v,2),vertex(v,3));
0131   end
0132   
0133   % matlab vertex indices start at one,
0134   % not zero, so we subtract one from matlab values
0135   fprintf('...subtracting 1 from face indices, so they start at zero\n');
0136   face = face - 1;
0137   for t = 1:size(face,1),
0138     fprintf(fid,'t\t%d\t%d\t%d\t\n',face(t,1),face(t,2),face(t,3));
0139   end
0140   
0141   fclose(fid);
0142   
0143 end
0144 
0145 return

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