Home > vbmeg > functions > brain > vb_find_no_overlap_divide.m

vb_find_no_overlap_divide

PURPOSE ^

SYNOPSIS ^

function [Indx ,ddmin, Vref2, Fref2] =vb_find_no_overlap_divide(Vref,Vnew,Fref,Rmax)

DESCRIPTION ^

 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    [Indx ,ddmin, Vref2, Fref2] = ...
0002     vb_find_no_overlap_divide(Vref,Vnew,Fref,Rmax)
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 if nargin < 3 ||  isempty(Fref),
0008     error('Fref is necessary input') ;
0009 end;
0010 
0011 fprintf('Ver2 vb_find_no_overlap_divide start\n\n')
0012 
0013 % sparse inverse distance matrix between Vref and Vnew
0014 d = vb_sparse_inv_distance(Vref,Vnew, Rmax);
0015 
0016 % find overlap vertex in Vref
0017 [overlap0,ddmin0,Indx0] = vb_find_overlap(d);
0018 
0019 % max distance of ddmin
0020 dmin0 = max(ddmin0(:));
0021 fprintf('max distance of ddmin at 1st stage = %g\n',dmin0)
0022 
0023 if overlap0.Noverlap == 0, 
0024     ddmin = ddmin0;
0025     Indx = Indx0;
0026     Vref2 = Vref;
0027     Fref2 = Fref;
0028     fprintf('No overlap at 1st stage\n')
0029     clear d
0030     %pack;
0031     return; 
0032 else
0033     fprintf('Noverlap at 1st stage = %d , Mean Multiplicity = %g\n', ...
0034     overlap0.Noverlap, mean(overlap0.Nmulti)), 
0035 end;
0036 
0037 Ntry = 20;
0038 overlap = overlap0;
0039 
0040 for jj = 1:Ntry
0041     % add reference vertex by dividing triangle of overlap point
0042     [Vadd, Iadd, Vref2, Fref2] = vb_add_patch_vertex(overlap,Vref,Fref);
0043     
0044     fprintf('Add reference vertex: %d\n',size(Vadd,1))
0045     
0046     dadd = vb_sparse_inv_distance(Vadd,Vnew, Rmax);
0047     
0048     dd = [d; dadd];
0049 
0050     % find overlap vertex in Vref with Vadd
0051     [overlap1,ddmin1,Indx1] = vb_find_overlap(dd);
0052     
0053     % max distance of ddmin
0054     dmin1 = max(ddmin1(:));
0055     fprintf('max distance of ddmin at %d-th stage = %g\n',jj,dmin1)
0056     
0057     if overlap1.Noverlap == 0, 
0058         ddmin = ddmin1;
0059         Indx  = Indx1;
0060         fprintf('No overlap at %d-th stage with added vertex \n',jj)
0061         clear d dd dadd
0062         %pack;
0063         return; 
0064     else
0065         fprintf('Noverlap at %d-th stage = %d , Mean Multiplicity = %g\n', ...
0066         jj, overlap1.Noverlap, mean(overlap1.Nmulti)), 
0067     end;
0068     
0069     %% try to find no overlap mapping
0070     [dd, overlap2, ddmin2, Indx2, iter] = ...
0071         vb_find_no_overlap(dd,overlap1,Rmax);
0072     
0073     % max distance of ddmin
0074     dmin2 = max(ddmin2(:));
0075     fprintf('max distance of ddmin after no overlap try')
0076     fprintf(' at %d-th stage = %g\n',jj,dmin2)
0077     
0078     if overlap2.Noverlap==0,
0079         ddmin = ddmin2;
0080         Indx  = Indx2;
0081     
0082         fprintf('No overlap at %d-th stage\n',jj)
0083         
0084         clear d dd dadd
0085         %pack;
0086         return
0087     else
0088         fprintf('Noverlap (after iter = %d) = %d at %d-th stage\n',...
0089         iter, overlap2.Noverlap,jj), 
0090         
0091         overlap = overlap2;
0092         
0093         if jj < Ntry
0094             Vref = Vref2;
0095             Fref = Fref2;
0096         else
0097             ddmin = ddmin2;
0098             Indx  = Indx2;
0099         end
0100     end
0101 end
0102 
0103 clear d dd dadd
0104 %pack;
0105

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