Home > vbmeg > external > iso2mesh > saveinr.m

saveinr

PURPOSE ^

SYNOPSIS ^

function saveinr(vol,fname)

DESCRIPTION ^

 saveinr(vol,fname)

 save a surface mesh to INR Format

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2009/01/04

 input:
      vol: input, a binary volume
      fname: output file name

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function saveinr(vol,fname)
0002 %
0003 % saveinr(vol,fname)
0004 %
0005 % save a surface mesh to INR Format
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2009/01/04
0009 %
0010 % input:
0011 %      vol: input, a binary volume
0012 %      fname: output file name
0013 %
0014 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0015 %
0016 
0017 fid=fopen(fname,'wb');
0018 if(fid==-1)
0019     error('You do not have permission to save mesh files.');
0020 end
0021 dtype=class(vol);
0022 if(islogical(vol) | strcmp(dtype,'uint8'))
0023    btype='unsigned fixed';
0024    dtype='uint8';
0025    bitlen=8;
0026 elseif(strcmp(dtype,'uint16'))
0027    btype='unsigned fixed';
0028    dtype='uint16';
0029    bitlen=16;    
0030 elseif(strcmp(dtype,'float'))
0031    btype='float';
0032    dtype='float';
0033    bitlen=32;
0034 elseif(strcmp(dtype,'double'))
0035    btype='float';
0036    dtype='double';
0037    bitlen=64;
0038 else
0039    error('volume format not supported');
0040 end
0041 header=sprintf(['#INRIMAGE-4#{\nXDIM=%d\nYDIM=%d\nZDIM=%d\nVDIM=1\nTYPE=%s\n' ...
0042   'PIXSIZE=%d bits\nCPU=decm\nVX=1\nVY=1\nVZ=1\n'],size(vol),btype,bitlen);
0043 header=[header char(10*ones(1,256-4-length(header))) '##}' char(10)];
0044 fwrite(fid,header,'char');
0045 fwrite(fid,vol,dtype);
0046 fclose(fid);

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