Home > vbmeg > functions > device > vivid > vb_read_vrml_patch.m

vb_read_vrml_patch

PURPOSE ^

Read Patch index frpm XML-file

SYNOPSIS ^

function X = vb_read_vrml_patch(fname)

DESCRIPTION ^

 Read Patch index frpm XML-file
 
 IndexedFaceSet {
    coordIndex [ 
        2484, 2485, 2465, -1,
        2465, 2485, 2486, -1,
            ...
    ]

 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    X = vb_read_vrml_patch(fname)
0002 % Read Patch index frpm XML-file
0003 %
0004 % IndexedFaceSet {
0005 %    coordIndex [
0006 %        2484, 2485, 2465, -1,
0007 %        2465, 2485, 2486, -1,
0008 %            ...
0009 %    ]
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 key.start  = 'IndexedFaceSet';
0015 key.start2 = 'coordIndex';
0016 key.end    = ']';
0017 key.braket = '[';
0018 
0019 
0020 [Nskip, Nline, Mmax] = vb_read_vrml_line(fname,key,'%d,');
0021 
0022 % Read data
0023 % Exclude last number '-1'
0024 %
0025 Mmax = Mmax-1;
0026 X=zeros(Nline,Mmax);
0027 
0028 %%%%% DEBUG %%%%
0029 fprintf('Number of patch= %d\n', Nline)
0030 fprintf('Number of Max points in patch = %d\n', Mmax)
0031 
0032 fid=fopen(fname);
0033 
0034 % Skip lines until data
0035 for n=1:Nskip
0036     next_line = fgetl(fid);
0037 end
0038 
0039 nn = 0;
0040 
0041 % Read data
0042 for n=1:Nline
0043     next_line = fgetl(fid);
0044     x  = sscanf(next_line,'%d,');
0045 
0046     % Exclude last number '-1'
0047     Nx = length(x)-1;
0048     
0049     if Nx > 0,
0050         nn = nn + 1;
0051         id = 1:Nx;
0052         
0053         % Add one to index : First index start from 1 instead of 0
0054         X(n,id) = x(id)' + 1;
0055         
0056         % If points are less than Mmax, duplicate first point index
0057         if Nx < Mmax, 
0058             X(n,(Nx+1):Mmax) = x(1) + 1; 
0059         end;
0060     end
0061 end
0062 
0063 fclose(fid);
0064 
0065 X = X(1:nn,:);

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