Home > vbmeg > functions > common > boundary > vb_close_line.m

vb_close_line

PURPOSE ^

make ordered vertex list for closed loop

SYNOPSIS ^

function [ID, Fnew] = vb_close_line(FL)

DESCRIPTION ^

 make ordered vertex list for closed loop
 [ID, Frest] = vb_close_line(FL)
 FL : edge index list
 FL(n,1:2) : two vertex index for n-th edge
 ID : vertex index list for closed loop
 Frest : remaining edge index list unused for ID

 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    [ID, Fnew] = vb_close_line(FL)
0002 % make ordered vertex list for closed loop
0003 % [ID, Frest] = vb_close_line(FL)
0004 % FL : edge index list
0005 % FL(n,1:2) : two vertex index for n-th edge
0006 % ID : vertex index list for closed loop
0007 % Frest : remaining edge index list unused for ID
0008 %
0009 % Copyright (C) 2011, ATR All Rights Reserved.
0010 % License : New BSD License(see VBMEG_LICENSE.txt)
0011 
0012 NL = size(FL,1);
0013 
0014 % Vertex list
0015 Ix = unique(FL(:));
0016 NV = length(Ix);
0017 NN = max(Ix);
0018 
0019 % edge index table for each vertex
0020 % FL(n,1)  , FL(n,2)   : two vertex index for n-th edge
0021 % Tbl(id,1), Tbl(id,2) : two edge index for id-th vertex
0022 Tbl  = zeros(NN,2);
0023 Vflg = zeros(NN,1);
0024 
0025 for n= 1:NL
0026     id = FL(n,1);
0027     Vflg(id) = Vflg(id) + 1;
0028     
0029     Tbl(id,Vflg(id)) = n;
0030 
0031     id = FL(n,2);
0032     Vflg(id) = Vflg(id) + 1;
0033     
0034     Tbl(id,Vflg(id)) = n;
0035 end
0036 
0037 List = zeros(NV,1);
0038 Vflg = zeros(NN,1);
0039 Fflg = zeros(NL,1);
0040 
0041 id  = Ix(1);    % vertex id
0042 
0043 for n=1:NV
0044     Vflg(id) = 1;
0045     List(n)  = id;
0046     
0047     % edge index for id-th vertex
0048     Fid1 = Tbl(id,1);
0049     Fid2 = Tbl(id,2);
0050     
0051     % check the edge is already used or not
0052     if Fid1 > 0 & Fflg(Fid1) == 0,
0053         Fid = Fid1;
0054     elseif Fid2 > 0 & Fflg(Fid2) == 0,
0055         Fid = Fid2;
0056     else
0057         break;
0058     end
0059     
0060     Fflg(Fid) = 1;
0061     
0062     % vertex index for Fid-th edge
0063     id1 = FL(Fid,1);
0064     id2 = FL(Fid,2);
0065     
0066     % check the vertex is already used or not
0067     if Vflg(id1) == 0,
0068         id = id1;
0069     elseif Vflg(id2) == 0,
0070         id = id2;
0071     else
0072         break;
0073     end
0074     
0075 end
0076 
0077 % ordered vertex list
0078 ID = List(1:n);
0079 
0080 % find unused edge
0081 ix = find( Fflg == 0 );
0082 
0083 Fnew = FL(ix,:);
0084 
0085 return

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