nirfastmesh=readnirfast(v,f,filestub) load a group of mesh files saved in the NIRFAST format author: Qianqian Fang, <q.fang at neu.edu> input: filestub: output file stub, output will include multiple files filestub.node: node file filestub.elem: element file to store the surface or tet mesh filestub.param: parameter file filestub.region: node label file filestub.excoef: extinction coeff list output: nirfastmesh.nodes: node list, 3 columns nirfastmesh.elements: element list, 3 or 4 columns integers nirfastmesh.bndvtx: boundary flag for each node, 1: on the boundary nirfastmesh.region: node segmentation labels nirfastmesh.dimension: dimension of the mesh nirfastmesh.excoef: extinction coeff list nirfastmesh.excoefheader: extinction coeff list field names nirfastmesh.type: the header of the .param file nirfastmesh.prop: optical property list (non-standard, need further processing) format definition see http://www.dartmouth.edu/~nir/nirfast/tutorials/NIRFAST-Intro.pdf example: [node,face,elem]=meshabox([0 0 0],[10 10 10],0.3,1); savenirfast(node,elem,'test', [], ones(size(node)), 'user'); mymesh=readnirfast('test') plotmesh([mymesh.nodes mymesh.bndvtx], mymesh.elements,'x>5') -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function nirfastmesh=readnirfast(filestub) 0002 % 0003 % nirfastmesh=readnirfast(v,f,filestub) 0004 % 0005 % load a group of mesh files saved in the NIRFAST format 0006 % 0007 % author: Qianqian Fang, <q.fang at neu.edu> 0008 % 0009 % input: 0010 % filestub: output file stub, output will include multiple files 0011 % filestub.node: node file 0012 % filestub.elem: element file to store the surface or tet mesh 0013 % filestub.param: parameter file 0014 % filestub.region: node label file 0015 % filestub.excoef: extinction coeff list 0016 % 0017 % output: 0018 % nirfastmesh.nodes: node list, 3 columns 0019 % nirfastmesh.elements: element list, 3 or 4 columns integers 0020 % nirfastmesh.bndvtx: boundary flag for each node, 1: on the boundary 0021 % nirfastmesh.region: node segmentation labels 0022 % nirfastmesh.dimension: dimension of the mesh 0023 % nirfastmesh.excoef: extinction coeff list 0024 % nirfastmesh.excoefheader: extinction coeff list field names 0025 % nirfastmesh.type: the header of the .param file 0026 % nirfastmesh.prop: optical property list (non-standard, need further processing) 0027 % 0028 % format definition see http://www.dartmouth.edu/~nir/nirfast/tutorials/NIRFAST-Intro.pdf 0029 % 0030 % example: 0031 % [node,face,elem]=meshabox([0 0 0],[10 10 10],0.3,1); 0032 % savenirfast(node,elem,'test', [], ones(size(node)), 'user'); 0033 % mymesh=readnirfast('test') 0034 % plotmesh([mymesh.nodes mymesh.bndvtx], mymesh.elements,'x>5') 0035 % 0036 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0037 % 0038 0039 fname=[filestub,'.node']; 0040 if(~exist(fullfile(pwd,fname),'file')) 0041 error([fname ' could not be found']); 0042 end 0043 nirfastmesh.nodes=load(fname); 0044 0045 nirfastmesh.bndvtx=nirfastmesh.nodes(:,1); 0046 nirfastmesh.nodes(:,1)=[]; 0047 0048 fname=[filestub,'.elem']; 0049 if(~exist(fullfile(pwd,fname),'file')) 0050 error([fname ' could not be found']); 0051 end 0052 nirfastmesh.elements=load(fname); 0053 nirfastmesh.dimension=size(nirfastmesh.elements,2)-1; 0054 0055 fname=[filestub,'.region']; 0056 if(exist(fullfile(pwd,fname),'file')) 0057 nirfastmesh.region=load(fname); 0058 end 0059 0060 fname=[filestub,'.excoef']; 0061 fid=fopen(fname,'rt'); 0062 if(fid>=0) 0063 linenum=0; 0064 textheader={}; 0065 while(~feof(fid)) 0066 oneline=fgetl(fid); 0067 linenum=linenum+1; 0068 [data, count]=sscanf(oneline,'%f'); 0069 if(count>1) 0070 params=fscanf(fid,repmat('%f ',1,count),inf); 0071 params=reshape(params,length(params)/count, count); 0072 params(2:end+1,:)=params; 0073 params(1,:)=data(:)'; 0074 nirfastmesh.excoef=params; 0075 nirfastmesh.excoefheader=textheader; 0076 break; 0077 else 0078 textheader{end+1}=oneline; 0079 end 0080 end 0081 fclose(fid); 0082 end 0083 0084 fname=[filestub,'.param']; 0085 fid=fopen(fname,'rt'); 0086 if(fid>=0) 0087 linenum=0; 0088 params=[]; 0089 while(~feof(fid)) 0090 oneline=fgetl(fid); 0091 if(linenum==0) 0092 nirfastmesh.type=oneline; 0093 end 0094 linenum=linenum+1; 0095 [data, count]=sscanf(oneline,'%f'); 0096 if(count>1) 0097 params=fscanf(fid,repmat('%f ',1,count),inf); 0098 params=reshape(params,length(params)/count, count); 0099 params(2:end+1,:)=params; 0100 params(1,:)=data(:)'; 0101 nirfastmesh.prop=params; 0102 break; 0103 end 0104 end 0105 fclose(fid); 0106 end