Home > matGeom > meshes3d > mergeMeshVertices.m

mergeMeshVertices

PURPOSE ^

MERGEMESHVERTICES Merge two vertices and removes eventual degenerated faces.

SYNOPSIS ^

function [vertices, faces] = mergeMeshVertices(vertices, faces, vertexInds, varargin)

DESCRIPTION ^

MERGEMESHVERTICES Merge two vertices and removes eventual degenerated faces.

   output = mergeMeshVertices(input)

   Example
   mergeMeshVertices

   See also

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [vertices, faces] = mergeMeshVertices(vertices, faces, vertexInds, varargin)
0002 %MERGEMESHVERTICES Merge two vertices and removes eventual degenerated faces.
0003 %
0004 %   output = mergeMeshVertices(input)
0005 %
0006 %   Example
0007 %   mergeMeshVertices
0008 %
0009 %   See also
0010 %
0011  
0012 % ------
0013 % Author: David Legland
0014 % e-mail: david.legland@inra.fr
0015 % Created: 2019-01-31,    using Matlab 9.5.0.944444 (R2018b)
0016 % Copyright 2019 INRA - Cepia Software Platform.
0017 
0018 newPos = vertices(vertexInds(1), :);
0019 if nargin > 3
0020     newPos = varargin{1};
0021 end
0022 
0023 vertices(vertexInds(1), :) = newPos;
0024 vertices(vertexInds(2:end), :) = NaN;
0025 
0026 % replace face-vertex indices by index of first vertex
0027 faces(ismember(faces, vertexInds)) = vertexInds(1);
0028 
0029 % need to check existence of degenerated faces with same vertex twice
0030 nFaces = size(faces, 1);
0031 dgnFaces = false(nFaces, 1);
0032 dims = [1 2;1 3;2 3];
0033 for i = 1:3
0034     dgnFaces = dgnFaces | faces(:,dims(i,1)) == faces(:,dims(i,2));
0035 end
0036 
0037 % remove degenerated faces
0038 faces(dgnFaces, :) = [];

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019