Home > vbmeg > external > iso2mesh > readoff.m

readoff

PURPOSE ^

SYNOPSIS ^

function [node,elem]=readoff(fname)

DESCRIPTION ^

 [node,elem]=readoff(fname)

 read Geomview Object File Format (OFF)

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2008/03/28

 input:
    fname: name of the OFF data file

 output:
    node: node coordinates of the mesh
    elem: list of elements of the mesh        

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [node,elem]=readoff(fname)
0002 %
0003 % [node,elem]=readoff(fname)
0004 %
0005 % read Geomview Object File Format (OFF)
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2008/03/28
0009 %
0010 % input:
0011 %    fname: name of the OFF data file
0012 %
0013 % output:
0014 %    node: node coordinates of the mesh
0015 %    elem: list of elements of the mesh
0016 %
0017 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0018 %
0019 
0020 node=[];
0021 elem=[];
0022 fid=fopen(fname,'rt');
0023 line=fgetl(fid);
0024 dim=sscanf(line,'OFF %d %d %d');
0025 line=nonemptyline(fid);
0026 if(size(dim,1)~=3)
0027     dim=sscanf(line,'%d',3);
0028     line=nonemptyline(fid);
0029 end
0030 nodalcount=3;
0031 if(~isempty(line))
0032     [val nodalcount]=sscanf(line,'%f',inf);
0033 else
0034     fclose(fid);
0035     return;
0036 end
0037 node=fscanf(fid,'%f',[nodalcount,dim(1)-1])';
0038 node=[val(:)';node];
0039 
0040 line=nonemptyline(fid);
0041 facetcount=4;
0042 if(~isempty(line))
0043     [val facetcount]=sscanf(line,'%f',inf);
0044 else
0045     fclose(fid);
0046     return;
0047 end
0048 elem=fscanf(fid,'%f',[facetcount,dim(2)-1])';
0049 elem=[val(:)';elem];
0050 fclose(fid);
0051 elem(:,1)=[];
0052 
0053 if(size(elem,2)<=3)
0054     elem(:,1:3)=round(elem(:,1:3))+1;
0055 else
0056     elem(:,1:4)=round(elem(:,1:4))+1;
0057 end
0058 
0059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0060 
0061 function str=nonemptyline(fid)
0062 str='';
0063 if(fid==0) error('invalid file'); end
0064 while((isempty(regexp(str,'\S')) || ~isempty(regexp(str,'^#')))  && ~feof(fid))
0065     str=fgetl(fid);
0066     if(~ischar(str))
0067         str='';
0068         return;
0069     end
0070 end

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