Home > matGeom > meshes3d > collapseEdgesWithManyFaces.m

collapseEdgesWithManyFaces

PURPOSE ^

removes mesh edges adjacent to more than two faces

SYNOPSIS ^

function [vertices, faces] = collapseEdgesWithManyFaces(vertices, faces, varargin)

DESCRIPTION ^

 removes mesh edges adjacent to more than two faces

   [V2, F2] = collapseEdgesWithManyFaces(V, F)
   Count the number of faces adjacent to each edge, and collapse the edges
   adjacent to more than two faces. 


   Example
   collapseEdgesWithManyFaces

   See also
       trimMesh, isManifoldMesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [vertices, faces] = collapseEdgesWithManyFaces(vertices, faces, varargin)
0002 % removes mesh edges adjacent to more than two faces
0003 %
0004 %   [V2, F2] = collapseEdgesWithManyFaces(V, F)
0005 %   Count the number of faces adjacent to each edge, and collapse the edges
0006 %   adjacent to more than two faces.
0007 %
0008 %
0009 %   Example
0010 %   collapseEdgesWithManyFaces
0011 %
0012 %   See also
0013 %       trimMesh, isManifoldMesh
0014  
0015 % ------
0016 % Author: David Legland
0017 % e-mail: david.legland@inra.fr
0018 % Created: 2019-01-31,    using Matlab 9.5.0.944444 (R2018b)
0019 % Copyright 2019 INRA - Cepia Software Platform.
0020 
0021 verbose = false;
0022 while length(varargin) > 1 && ischar(varargin{1})
0023     name = varargin{1};
0024     if strcmpi(name, 'verbose')
0025         verbose = varargin{2};
0026     else
0027         error(['Unknown optional argument: ' name]);
0028     end
0029     varargin(1:2) = [];
0030 end
0031 
0032 while true
0033     % compute edge to vertex mapping
0034     edges = meshEdges(faces);
0035     
0036     % compute number of faces incident to each edge
0037     edgeFaces = trimeshEdgeFaces(faces);
0038     edgeFaceDegrees = sum(edgeFaces > 0, 2);
0039     
0040     inds = find(edgeFaceDegrees > 2);
0041     
0042     if isempty(inds)
0043         break;
0044     end
0045     
0046     edge = edges(inds(1), :);
0047     if verbose
0048         fprintf('remove edge with index %d: (%d, %d)\n', inds(1), edge);
0049     end
0050     [vertices, faces] = mergeMeshVertices(vertices, faces, edge);
0051 end
0052 
0053 % trim
0054 [vertices, faces] = trimMesh(vertices, faces);

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