Matlab Help Index Technical Documentation Index

read_surf

NAME ^

SYNOPSIS ^

function [vertex_coords, faces] = read_surf(fname)

DESCRIPTION ^

 [vertex_coords, faces] = read_surf(fname)
 reads a the vertex coordinates and face lists from a surface file
 note that reading the faces from a quad file can take a very long
 time due to the goofy format that they are stored in. If the faces
 output variable is not specified, they will not be read so it 
 should execute pretty quickly.

CROSS-REFERENCE INFORMATION ^

This function calls:

This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [vertex_coords, faces] = read_surf(fname)
0002 
0003 %
0004 % [vertex_coords, faces] = read_surf(fname)
0005 % reads a the vertex coordinates and face lists from a surface file
0006 % note that reading the faces from a quad file can take a very long
0007 % time due to the goofy format that they are stored in. If the faces
0008 % output variable is not specified, they will not be read so it
0009 % should execute pretty quickly.
0010 %
0011 
0012 
0013 %fid = fopen(fname, 'r') ;
0014 %nvertices = fscanf(fid, '%d', 1);
0015 %all = fscanf(fid, '%d %f %f %f %f\n', [5, nvertices]) ;
0016 %curv = all(5, :)' ;
0017 
0018 % open it as a big-endian file
0019 
0020 
0021 %QUAD_FILE_MAGIC_NUMBER =  (-1 & 0x00ffffff) ;
0022 %NEW_QUAD_FILE_MAGIC_NUMBER =  (-3 & 0x00ffffff) ;
0023 
0024 TRIANGLE_FILE_MAGIC_NUMBER =  16777214 ;
0025 QUAD_FILE_MAGIC_NUMBER =  16777215 ;
0026 
0027 fid = fopen(fname, 'rb', 'b') ;
0028 if (fid < 0)
0029      %%str = sprintf('could not open curvature file %s.', fname) ;
0030      %%error(str) ;
0031     oops(159);
0032 end
0033 magic = fread3(fid) ;
0034 
0035 if (magic == QUAD_FILE_MAGIC_NUMBER)
0036      vnum = fread3(fid) ;
0037      fnum = fread3(fid) ;
0038      vertex_coords = fread(fid, vnum*3, 'int16') ./ 100 ; 
0039      if (nargout > 1)
0040           for i=1:fnum
0041               for n=1:4
0042                       faces(i,n) = fread3(fid) ;
0043              end
0044          end
0045      end
0046 elseif (magic == TRIANGLE_FILE_MAGIC_NUMBER)
0047    fgets(fid) ;
0048      fgets(fid) ;
0049      vnum = fread(fid, 1, 'int32') ;
0050      fnum = fread(fid, 1, 'int32') ;
0051      vertex_coords = fread(fid, vnum*3, 'float32') ; 
0052      faces = fread(fid, fnum*3, 'int32') ;
0053      faces = reshape(faces, 3, fnum)' ;
0054 end
0055 
0056 vertex_coords = reshape(vertex_coords, 3, vnum)' ;
0057 fclose(fid) ;

Generated at 19:47:41 15-Oct-2003 by m2html © 2003