Home > vbmeg > functions > leadfield > curry > vb_create_curry_patch.m

vb_create_curry_patch

PURPOSE ^

Calculate patch index from Curry vertex format

SYNOPSIS ^

function [V,F,indx,Ninfo] = vb_create_curry_patch(FV)

DESCRIPTION ^

 Calculate patch index from Curry vertex format
  [V,F,indx] = vb_create_curry_patch(FV)
  [V,F,indx,Ninfo] = vb_create_curry_patch(FV)
 --- Input
 FV : curry surface vertex: N  x 3 
 --- Output
 V  : vertex coordinate   : NV x 3 
 F  : surface patch index : NF x 3, NF = N/3
 indx : selected index for 'V'
        V = FV(indx,:) 
 Ninfo : Debug info

 --- Curry coordinate variable
 FV : 3 vertex coordinate in i-th triangle 
 FV(i+1,:)
 FV(i+2,:)
 FV(i+3,:)
 i = ix * 3, 
 ---
 To speed up, slicewise search is done

 2006-10-26 M.Sato

 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,indx,Ninfo] = vb_create_curry_patch(FV)
0002 % Calculate patch index from Curry vertex format
0003 %  [V,F,indx] = vb_create_curry_patch(FV)
0004 %  [V,F,indx,Ninfo] = vb_create_curry_patch(FV)
0005 % --- Input
0006 % FV : curry surface vertex: N  x 3
0007 % --- Output
0008 % V  : vertex coordinate   : NV x 3
0009 % F  : surface patch index : NF x 3, NF = N/3
0010 % indx : selected index for 'V'
0011 %        V = FV(indx,:)
0012 % Ninfo : Debug info
0013 %
0014 % --- Curry coordinate variable
0015 % FV : 3 vertex coordinate in i-th triangle
0016 % FV(i+1,:)
0017 % FV(i+2,:)
0018 % FV(i+3,:)
0019 % i = ix * 3,
0020 % ---
0021 % To speed up, slicewise search is done
0022 %
0023 % 2006-10-26 M.Sato
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 fprintf('--- Create patch data ');
0029 
0030 [V,indx] = unique(FV,'rows');
0031 NF = size(FV,1)/3;
0032 NV = size(V,1);
0033 F = zeros(NF,3);
0034 
0035 %h = waitbar(0,'Create patch data');
0036 
0037 % Slice definition
0038 Nstep = 100;
0039 Zmax  = max(V(:,3));
0040 Zmin  = min(V(:,3));
0041 Zwid  = (Zmax-Zmin)/1000;
0042 Zmax  = Zmax + Zwid;
0043 Zmin  = Zmin - Zwid;
0044 Zstep = max( (Zmax-Zmin)/Nstep , eps);
0045 Zlist = Zmin:Zstep:Zmax;
0046 Nstep = length(Zlist) - 1;
0047 
0048 NVcnt  = 0;
0049 NFcnt  = 0;
0050 NFcnt1 = 0;
0051 
0052 % Loop for slices in z-direction
0053 for n=1:Nstep,
0054     % Find vertex points in this slice
0055     ixV  = find(  V(:,3) >= Zlist(n) &  V(:,3) < Zlist(n+1));
0056     ixF  = find( FV(:,3) >= Zlist(n) & FV(:,3) < Zlist(n+1));
0057     
0058     NVz  = length(ixV);    % # of vertex  'V' in this slice
0059     NFz  = length(ixF);    % # of vertex 'FV' in this slice
0060     NVcnt = NVcnt + NVz;
0061     NFcnt = NFcnt + NFz;
0062     
0063     FVz  = FV(ixF,:);    % 'FV' in this slice
0064 
0065     for k=1:NVz,
0066         i  = ixV(k);
0067         Vz = V(i,:);    % 'V' in this slice
0068         
0069         % Distance between 'FVz' and 'Vz'
0070         dd    = abs(FVz(:,1) - Vz(1)) ...
0071             + abs(FVz(:,2) - Vz(2)) ...
0072             + abs(FVz(:,3) - Vz(3));
0073             
0074         % Find ( FV(ix) = V(i) )
0075         jj  = find(dd < eps);
0076         NFcnt1 = NFcnt1 + length(jj);
0077         
0078         ix  = ixF(jj);
0079         ix0 = ix-1;
0080         
0081         % Translate to patch index
0082         % FV(ix0 + 1,:) = V(i,:)
0083         % ix0 = (ix1-1)*3 + (ix2-1)
0084         %     : 'ix1'-th triangle
0085         %     & 'ix2'-th vertex in 3 triangle vertex
0086         % F(ix1,ix2) = i
0087 
0088         ix1 = floor(ix0/3)+1;
0089         ix2 = mod(ix0,3)+1;
0090         
0091         for j = 1:length(ix1)
0092           F(ix1(j),ix2(j)) = i;
0093         end
0094     end
0095     %waitbar(n/Nstep);
0096 end
0097 %
0098 %close(h);
0099 %drawnow;
0100 
0101 Ninfo.NVcnt  = NVcnt;
0102 Ninfo.NFcnt  = NFcnt;
0103 Ninfo.NFcnt1 = NFcnt1;
0104 
0105 return

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