Home > matGeom > meshes3d > isManifoldMesh.m

isManifoldMesh

PURPOSE ^

ISMANIFOLDMESH Check whether the input mesh may be considered as manifold.

SYNOPSIS ^

function [b1, b2] = isManifoldMesh(varargin)

DESCRIPTION ^

ISMANIFOLDMESH Check whether the input mesh may be considered as manifold.

   B = isManifoldMesh(V, F)
   B = isManifoldMesh(V, E, F)
   Checks if the specified mesh is a manifold. When mesh is a manifold,
   all edges are connected to either 2 or 1 faces.

   [B, HASBORDER] = isManifoldMesh(V, E, F)
   Also checks whether the mesh contains border faces. Border faces
   contains at least one edge which is ajacent to only one face.

   Example
     [V, F] = createOctahedron;
     isManifoldMesh(V, F)
     ans =
       logical
        1

   See also
     meshes3d, ensureManifoldMesh, trimMesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [b1, b2] = isManifoldMesh(varargin)
0002 %ISMANIFOLDMESH Check whether the input mesh may be considered as manifold.
0003 %
0004 %   B = isManifoldMesh(V, F)
0005 %   B = isManifoldMesh(V, E, F)
0006 %   Checks if the specified mesh is a manifold. When mesh is a manifold,
0007 %   all edges are connected to either 2 or 1 faces.
0008 %
0009 %   [B, HASBORDER] = isManifoldMesh(V, E, F)
0010 %   Also checks whether the mesh contains border faces. Border faces
0011 %   contains at least one edge which is ajacent to only one face.
0012 %
0013 %   Example
0014 %     [V, F] = createOctahedron;
0015 %     isManifoldMesh(V, F)
0016 %     ans =
0017 %       logical
0018 %        1
0019 %
0020 %   See also
0021 %     meshes3d, ensureManifoldMesh, trimMesh
0022 
0023 % ------
0024 % Author: David Legland
0025 % E-mail: david.legland@inrae.fr
0026 % Created: 2019-01-31, using Matlab 9.5.0.944444 (R2018b)
0027 % Copyright 2019-2024 INRA - Cepia Software Platform
0028 
0029 [vertices, edges, faces] = parseMeshData(varargin{:});
0030 
0031 % ensure edge to vertex data is computed
0032 if isempty(edges)
0033     edges = meshEdges(faces);
0034 end    
0035 
0036 % compute face to edge indices array
0037 % as a nFaces-by-3 array (each face connected to exactly three edges)
0038 faceEdgeInds = meshFaceEdges(vertices, edges, faces);
0039 
0040 % compute number of faces incident each edge
0041 edgeFaces = trimeshEdgeFaces(faces);
0042 edgeFaceDegrees = sum(edgeFaces > 0, 2);
0043 
0044 % for each face, concatenate the face degree of each edge
0045 faceEdgeDegrees = zeros(size(faces, 1), 3);
0046 for iFace = 1:size(faces, 1)
0047     edgeInds = faceEdgeInds{iFace};
0048     faceEdgeDegrees(iFace, :) = edgeFaceDegrees(edgeInds);
0049 end
0050 
0051 regFaces = sum(ismember(faceEdgeDegrees, [1 2]), 2) == 3;
0052 innerFaces = sum(faceEdgeDegrees == 2, 2) == 3;
0053 borderFaces = regFaces & ~innerFaces;
0054 
0055 % check if mesh is manifold: all faces are either regular or border
0056 b1 = all(regFaces);
0057 
0058 % check if some faces are border
0059 b2 = any(borderFaces);

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022