ENSUREMANIFOLDMESH Apply several simplification to obtain a manifold mesh. Try to transform an input mesh into a manifold mesh. Not all cases of "non-manifoldity" are checked, so please use with care. [V2, F2] = ensureManifoldMesh(V, F); [V2, F2] = ensureManifoldMesh(MESH); MESH2 = ensureManifoldMesh(...); Example ensureManifoldMesh See also meshes3d, isManifoldMesh
0001 function varargout = ensureManifoldMesh(varargin) 0002 %ENSUREMANIFOLDMESH Apply several simplification to obtain a manifold mesh. 0003 % 0004 % Try to transform an input mesh into a manifold mesh. 0005 % 0006 % Not all cases of "non-manifoldity" are checked, so please use with 0007 % care. 0008 % 0009 % [V2, F2] = ensureManifoldMesh(V, F); 0010 % [V2, F2] = ensureManifoldMesh(MESH); 0011 % MESH2 = ensureManifoldMesh(...); 0012 % 0013 % Example 0014 % ensureManifoldMesh 0015 % 0016 % See also 0017 % meshes3d, isManifoldMesh 0018 0019 % ------ 0020 % Author: David Legland 0021 % E-mail: david.legland@inrae.fr 0022 % Created: 2019-02-01, using Matlab 9.5.0.944444 (R2018b) 0023 % Copyright 2019-2024 INRA - Cepia Software Platform 0024 0025 %% Parse input arguments 0026 0027 [vertices, faces] = parseMeshData(varargin{:}); 0028 verbose = true; 0029 0030 0031 %% Pre-processing 0032 0033 % remove duplicate faces if any 0034 if verbose 0035 disp('remove duplicate faces'); 0036 end 0037 faces = removeDuplicateFaces(faces); 0038 0039 0040 %% Iterative processing of multiple edges 0041 % Reduces all edges connected to more than two faces, by collapsing second 0042 % vertex onto the first one. 0043 0044 % iter = 0; 0045 % while ~isManifoldMesh(vertices, faces) && iter < 10 0046 % iter = iter + 1; 0047 if verbose 0048 disp('collapse edges with many faces'); 0049 end 0050 0051 [vertices, faces] = collapseEdgesWithManyFaces(vertices, faces); 0052 % end 0053 0054 0055 0056 %% Format output 0057 0058 varargout = formatMeshOutput(nargout, vertices, faces); 0059