Home > functions > common > boundary > vb_surf_smooth_out.m

vb_surf_smooth_out

PURPOSE ^

Fit surface to the boundary of the mask

SYNOPSIS ^

function [V, F, xxn] = vb_surf_smooth_out(V,F,xx,Para)

DESCRIPTION ^

 Fit surface to the boundary of the mask
  [V, F, xx] = vb_surf_smooth_out(V,F,xx,Para)
 --- Input
  V(n, 1:3)  : vertex
  F(j, 1:3)  : patch index
 xx(n, 1:3)  : normal vector
 Para.Nloop  : iteration number
 Para.tangent_rate  : spring constant
 Para.out_ratio     : outward force constant

 --- Output
  V(n, 1:3)  : vertex
  F(j, 1:3)  : patch index
 xx(n, 1:3)  : normal vector
 --- Mehod
 ポリゴンモデルを法線方向に膨張 + バネ力による平滑化

  V(n, 1:3)  : 頂点の位置
  F(j, 1:3)  : 三角面3頂点のインデックス
 xx(n, 1:3)  : 頂点の初期法線方向(nx,ny,nz)
 xxn(n, 1:3) : 頂点の最終法線方向(nx,ny,nz)

 Para.Nloop  : 繰り返し回数

 Para.tangent_rate  : バネ強度
 Para.out_ratio     : 法線力係数 ( 外向き)

 合力 =  tangent_rate * (平滑化バネ力)
       +  out_ratio   * (外向き法線方向)
 
 Ver 1.0  by M. Sato  2004-2-5
 Ver 2.0  by M. Sato  2006-11-11
 M. Sato 2007-3-16

 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, xxn] = vb_surf_smooth_out(V,F,xx,Para)
0002 % Fit surface to the boundary of the mask
0003 %  [V, F, xx] = vb_surf_smooth_out(V,F,xx,Para)
0004 % --- Input
0005 %  V(n, 1:3)  : vertex
0006 %  F(j, 1:3)  : patch index
0007 % xx(n, 1:3)  : normal vector
0008 % Para.Nloop  : iteration number
0009 % Para.tangent_rate  : spring constant
0010 % Para.out_ratio     : outward force constant
0011 %
0012 % --- Output
0013 %  V(n, 1:3)  : vertex
0014 %  F(j, 1:3)  : patch index
0015 % xx(n, 1:3)  : normal vector
0016 % --- Mehod
0017 % ポリゴンモデルを法線方向に膨張 + バネ力による平滑化
0018 %
0019 %  V(n, 1:3)  : 頂点の位置
0020 %  F(j, 1:3)  : 三角面3頂点のインデックス
0021 % xx(n, 1:3)  : 頂点の初期法線方向(nx,ny,nz)
0022 % xxn(n, 1:3) : 頂点の最終法線方向(nx,ny,nz)
0023 %
0024 % Para.Nloop  : 繰り返し回数
0025 %
0026 % Para.tangent_rate  : バネ強度
0027 % Para.out_ratio     : 法線力係数 ( 外向き)
0028 %
0029 % 合力 =  tangent_rate * (平滑化バネ力)
0030 %       +  out_ratio   * (外向き法線方向)
0031 %
0032 % Ver 1.0  by M. Sato  2004-2-5
0033 % Ver 2.0  by M. Sato  2006-11-11
0034 % M. Sato 2007-3-16
0035 %
0036 % Copyright (C) 2011, ATR All Rights Reserved.
0037 % License : New BSD License(see VBMEG_LICENSE.txt)
0038 
0039 if ~exist('Para','var'), Para = []; end
0040 if ~isfield(Para,'Nloop'), Para.Nloop = 200; end
0041 if ~isfield(Para,'Ndisp'), Para.Ndisp = Para.Nloop+1; end
0042 if ~isfield(Para,'tangent_rate'),  Para.tangent_rate  = 0.3; end
0043 if ~isfield(Para,'out_ratio'),     Para.out_ratio     = 0.5; end
0044 
0045 tangent_rate = Para.tangent_rate;
0046 out_rate   = Para.out_ratio;
0047 
0048 Nloop         = Para.Nloop;
0049 Npoint         = size(V,1);      % number of vertex
0050 Npatch         = size(F,1);      % number of patch
0051 
0052 % Plot parameter
0053 Ndisp = Para.Ndisp;
0054 Nfig  = fix(Nloop/Ndisp);
0055 
0056 if Nfig < 2,
0057     NYfig = 1;
0058 else
0059     NYfig = 2;
0060 end
0061 NXfig = max(ceil(Nfig/NYfig), 1);
0062 nfig  = NXfig*NYfig + 1;
0063 
0064 fclr = [];
0065 eclr = [];
0066 light_mode = 1;
0067 vangle = [-70 20];
0068 
0069 % 3角面の法線ベクトル
0070 xxf  = zeros(Npatch,3);
0071 % 3角面面積
0072 nns  = zeros(Npatch,1);
0073 % 3角面頂点の差分ベクトル
0074 VV1  = zeros(Npatch,3);
0075 VV2  = zeros(Npatch,3);
0076 VV3  = zeros(Npatch,3);
0077 
0078 % 頂点法線 = 頂点に隣接する三角面法線の平均
0079 xxn  = zeros(Npoint,3);    
0080 xxs  = zeros(Npoint,1);
0081 % 頂点差分ベクトル
0082 fd   = zeros(Npoint,3);
0083 % 各頂点の近傍点数
0084 Nv   = zeros(Npoint,1);
0085 % 頂点差分ベクトルと法線の内積
0086 nnf  = zeros(Npoint,1);
0087 
0088 % 三角面3頂点のインデックス
0089 F1     = F(:,1);
0090 F2     = F(:,2);
0091 F3     = F(:,3);
0092 
0093 % 3角面の法線ベクトル
0094 xxf  = vb_cross2( V(F2,:)-V(F1,:) , V(F3,:)-V(F1,:) );
0095 
0096 % 三角面3頂点の法線ベクトル平均
0097 xxk  = xx(F1,:)+xx(F2,:)+xx(F3,:);
0098 
0099 xdot = sum( xxk .* xxf ,2);
0100 ix     = find(sign(xdot) < 0 );
0101 
0102 % 3角面の法線ベクトルと
0103 % 頂点の法線ベクトル 'xx' (外向き)の向きをそろえる
0104 F(ix,2) = F3(ix);
0105 F(ix,3) = F2(ix);
0106 
0107 F2        = F(:,2);
0108 F3        = F(:,3);
0109 
0110 % 各頂点の近傍点数
0111 for n=1:Npatch,
0112     inx = F(n,:)';
0113     Nv(inx) = Nv(inx) + 2; 
0114 end;
0115 
0116 % バネ力平滑化+外向き力(内側)+内向き力(外側)
0117 
0118 for i=1:Nloop,
0119 
0120     % 三角面3頂点
0121     V1=V(F1,:);
0122     V2=V(F2,:);
0123     V3=V(F3,:);
0124     
0125     % 3角面の法線ベクトル
0126     xxf   = vb_cross2( V2 - V1, V3 - V1 );
0127 
0128     % Normalization
0129     nns   = sqrt(sum(xxf.^2,2));
0130     xxf   = xxf./nns(:,ones(1,3));        
0131     
0132     % 三角面各頂点の差分ベクトル
0133     VV1   = V2 + V3 - 2*V1;
0134     VV2   = V3 + V1 - 2*V2;
0135     VV3   = V1 + V2 - 2*V3;
0136 
0137     % 頂点法線 = 頂点に隣接する三角面法線の平均
0138     xxn   = zeros(Npoint,3);    
0139     % 頂点差分ベクトル(近傍和)
0140     fd      = zeros(Npoint,3);
0141     
0142     for n=1:Npatch,
0143         % 三角面3頂点インデックス
0144         j1=F1(n);
0145         j2=F2(n);
0146         j3=F3(n);
0147         
0148         xxn(j1,:) = xxn(j1,:) + xxf(n,:);
0149         xxn(j2,:) = xxn(j2,:) + xxf(n,:);
0150         xxn(j3,:) = xxn(j3,:) + xxf(n,:);
0151         
0152         % 頂点差分ベクトル(近傍和)
0153         fd(j1,:) = fd(j1,:) + VV1(n,:); 
0154         fd(j2,:) = fd(j2,:) + VV2(n,:); 
0155         fd(j3,:) = fd(j3,:) + VV3(n,:); 
0156     end;
0157     
0158     % 法線の正規化
0159     xxs   = sqrt(sum(xxn.^2,2));
0160     xxn   = xxn./xxs(:,ones(1,3));
0161 
0162     % 頂点差分ベクトルを近傍点数で正規化
0163     fd     = fd./Nv(:,ones(1,3));
0164     
0165     V    = V + tangent_rate*fd + out_rate*xxn;
0166 
0167     if rem(i,Ndisp)==0,
0168         if nfig > NYfig*NXfig
0169             figure;
0170             nfig=1;
0171         else
0172             nfig=nfig+1;
0173         end
0174         subplot(NYfig,NXfig,nfig); 
0175         vb_plot_surf(V,F,fclr,eclr,light_mode);
0176         view(vangle);
0177         tlabel = sprintf('Iteration = %d',i);
0178         title(tlabel);
0179     end;
0180 end
0181

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