0001 function [V, F, RGB] = vb_read_mgf_file(fname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 key_start = 'color';
0028
0029
0030 fid=fopen(fname);
0031
0032 if fid == -1, fprintf('[%s] can not be opened\n',fname);return; end;
0033
0034 while 1
0035 next_line = fgetl(fid);
0036 if ~ischar(next_line), break, end;
0037 if ~isempty( strfind(next_line,key_start)), break, end;
0038 end
0039
0040 next_line = fgetl(fid);
0041 Npoint = sscanf(next_line,'%d');
0042
0043 X = zeros(Npoint,6);
0044
0045 for n=1:Npoint
0046 next_line = fgetl(fid);
0047 x = sscanf(next_line,'%f');
0048 X(n,:) = x';
0049 end
0050
0051 next_line = fgetl(fid);
0052 Npatch = sscanf(next_line,'%d');
0053
0054 F = zeros(Npatch,4);
0055
0056 for n=1:Npatch
0057 next_line = fgetl(fid);
0058 num = sscanf(next_line,'%d');
0059
0060 next_line = fgetl(fid);
0061 ix = sscanf(next_line,'%d');
0062 F(n,1:num) = ix';
0063
0064
0065 if num < 4, F(n,num+1:4) = ix(1); end;
0066
0067 end
0068
0069 fclose(fid);
0070
0071 V = X(:,1:3);
0072 RGB = X(:,4:6);