Home > vbmeg > functions > plotfunc > subdirectory > vb_shrink_cortex_for_plot.m

vb_shrink_cortex_for_plot

PURPOSE ^

MATLAB 2014b and later, patch plot order is strange.

SYNOPSIS ^

function Vshrink = vb_shrink_cortex_for_plot(V, F, inflate)

DESCRIPTION ^

 MATLAB 2014b and later, patch plot order is strange.
 Slightly shrink cortex so that area/act is plotted to top of cortex.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function Vshrink = vb_shrink_cortex_for_plot(V, F, inflate)
0002 % MATLAB 2014b and later, patch plot order is strange.
0003 % Slightly shrink cortex so that area/act is plotted to top of cortex.
0004 
0005 if ~exist('inflate', 'var') || isempty(inflate)
0006     inflate = false;
0007 end
0008 
0009 if vb_matlab_version('>=', '8.4')
0010     % MATLAB 2014b, patch order is strange
0011     % so slightly shrink cortex.
0012 
0013     n = struct;
0014     n.faces = F;
0015     n.vertices = V;
0016 
0017     Vnorm = patchnormals(n);
0018 
0019     for k=1:size(Vnorm, 1)
0020         Vnorm(k, :) = Vnorm(k, :) ./ norm(Vnorm(k, :));
0021     end
0022 
0023     % Shrink standard brain model operation for display
0024     if inflate
0025         % inflated cortex
0026         Vshrink = V + 1*Vnorm;
0027     else
0028         % cortex
0029         Vshrink = V + 0.001*Vnorm;
0030     end
0031 else
0032     Vshrink = V;
0033 end
0034 
0035 
0036 function N = patchnormals(FV)
0037 %Vertex normals of a triangulated mesh, area weighted, left-hand-rule
0038 % N = patchnormals(FV) -struct with fields, faces Nx3 and vertices Mx3
0039 %N: vertex normals as Mx3
0040 
0041 %face corners index
0042 A = FV.faces(:,1);
0043 B = FV.faces(:,2);
0044 C = FV.faces(:,3);
0045 
0046 %face normals
0047 n = cross(FV.vertices(A,:)-FV.vertices(B,:),FV.vertices(C,:)-FV.vertices(A,:)); %area weighted
0048 
0049 %vertice normals
0050 N = zeros(size(FV.vertices)); %init vertix normals
0051 for i = 1:size(FV.faces,1) %step through faces (a vertex can be reference any number of times)
0052 N(A(i),:) = N(A(i),:)+n(i,:); %sum face normals
0053 N(B(i),:) = N(B(i),:)+n(i,:);
0054 N(C(i),:) = N(C(i),:)+n(i,:);
0055 end

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