SMOOTHMESHFUNCTION 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 %SMOOTHMESHFUNCTION 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 % Created: 2021-09-22, using Matlab 9.10.0.1684407 (R2021a) Update 3 0022 % Copyright 2021-2024 INRAE - BIA Research Unit - BIBS Platform (Nantes) 0023 0024 % determines number of iterations 0025 nIters = 3; 0026 if ~isempty(varargin) 0027 nIters = varargin{1}; 0028 end 0029 0030 % apply smoothing on scalar function 0031 nv = max(faces(:)); 0032 0033 % compute normalized averaging matrix 0034 W = meshAdjacencyMatrix(faces) + speye(nv); 0035 D = spdiags(full(sum(W,2).^(-1)), 0, nv, nv); 0036 W = D * W; 0037 0038 % do averaging to smooth the field 0039 for j = 1:size(f, 2) 0040 for k = 1:nIters 0041 f(:,j) = W * f(:,j); 0042 end 0043 end