Home > functions > device > vivid > vb_read_mgf_file.m

vb_read_mgf_file

PURPOSE ^

Read MGF polyhedron data file

SYNOPSIS ^

function [V, F, RGB] = vb_read_mgf_file(fname)

DESCRIPTION ^

 Read MGF polyhedron data file
  [V, F, RGB] = vb_read_mgf_file(fname)
 V   : polyhedron vertex coordinate [Npoint 3]
 F   : polyhedron patch index       [Npatch 4]
 RGB : RGB color at each vertex     [Npoint 3]

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [V, F, RGB] = vb_read_mgf_file(fname)
0002 % Read MGF polyhedron data file
0003 %  [V, F, RGB] = vb_read_mgf_file(fname)
0004 % V   : polyhedron vertex coordinate [Npoint 3]
0005 % F   : polyhedron patch index       [Npatch 4]
0006 % RGB : RGB color at each vertex     [Npoint 3]
0007 %
0008 % Copyright (C) 2011, ATR All Rights Reserved.
0009 % License : New BSD License(see VBMEG_LICENSE.txt)
0010 
0011 %  ---- MGF file format
0012 %  # Micro AVS Geom:2.00
0013 %  polyhedron
0014 %  UnNamed-1
0015 %  facet
0016 %  color
0017 %  5820  % 頂点数
0018 %    -90.678841 89.391457 -985.069824 0.360784 0.274510 0.188235
0019 %    ... 各頂点の座標値(X,Y,Z)、色(R,G,B)
0020 %  5699  % ポリゴン数
0021 %    4
0022 %    1 79 80 2
0023 %    ... 頂点数 n\ ポリゴン頂点番号
0024 
0025 % 2006/2/2  M. Sato
0026 
0027 key_start  = 'color';
0028 
0029 % Find keyward line
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     % If points are less than 4, duplicate first point index
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);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005