Apply smoothing on a functions defines on mesh vertices. FS = smoothMeshFunction(VERTICES, FACES, F, NITERS) Performs smoothing on the function F defined on vertices of the mesh. The mesh is specified by VERTICES and FACES array. At each iteration, the value for each vertex is obtained as the average of values obtained from neighbor vertices. NITERS is the number of times the iteration must be repeated. By default it equals 3. Example smoothMeshFunction See also meshes3d, meshCurvatures
0001 function f = smoothMeshFunction(vertices, faces, f, varargin) %#ok<INUSL> 0002 % Apply smoothing on a functions defines on mesh vertices. 0003 % 0004 % FS = smoothMeshFunction(VERTICES, FACES, F, NITERS) 0005 % Performs smoothing on the function F defined on vertices of the mesh. 0006 % The mesh is specified by VERTICES and FACES array. At each iteration, 0007 % the value for each vertex is obtained as the average of values obtained 0008 % from neighbor vertices. 0009 % NITERS is the number of times the iteration must be repeated. By 0010 % default it equals 3. 0011 % 0012 % Example 0013 % smoothMeshFunction 0014 % 0015 % See also 0016 % meshes3d, meshCurvatures 0017 0018 % ------ 0019 % Author: David Legland 0020 % e-mail: david.legland@inrae.fr 0021 % INRAE - BIA Research Unit - BIBS Platform (Nantes) 0022 % Created: 2021-09-22, using Matlab 9.10.0.1684407 (R2021a) Update 3 0023 % Copyright 2021 INRAE. 0024 0025 % determines number of iterations 0026 nIters = 3; 0027 if ~isempty(varargin) 0028 nIters = varargin{1}; 0029 end 0030 0031 % apply smoothing on scalar function 0032 nv = max(faces(:)); 0033 0034 % compute normalized averaging matrix 0035 W = meshAdjacencyMatrix(faces) + speye(nv); 0036 D = spdiags(full(sum(W,2).^(-1)), 0, nv, nv); 0037 W = D * W; 0038 0039 % do averaging to smooth the field 0040 for j = 1:size(f, 2) 0041 for k = 1:nIters 0042 f(:,j) = W * f(:,j); 0043 end 0044 end