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@inra.fr
0026 % Created: 2019-01-31,    using Matlab 9.5.0.944444 (R2018b)
0027 % Copyright 2019 INRA - Cepia Software Platform.
0028 
0029 vertices = varargin{1};
0030 faces = varargin{2};
0031 
0032 % compute edge to vertex array
0033 if nargin == 3
0034     edges = faces;
0035     faces = varargin{3};
0036 else
0037     % compute edge to vertex array
0038     edges = meshEdges(faces);
0039 end
0040 
0041 
0042 % compute face to edge indices array
0043 % as a nFaces-by-3 array (each face connected to exactly three edges)
0044 faceEdgeInds = meshFaceEdges(vertices, edges, faces);
0045 
0046 % compute number of faces incident each edge
0047 edgeFaces = trimeshEdgeFaces(faces);
0048 edgeFaceDegrees = sum(edgeFaces > 0, 2);
0049 
0050 % for each face, concatenate the face degree of each edge
0051 faceEdgeDegrees = zeros(size(faces, 1), 3);
0052 for iFace = 1:size(faces, 1)
0053     edgeInds = faceEdgeInds{iFace};
0054     faceEdgeDegrees(iFace, :) = edgeFaceDegrees(edgeInds);
0055 end
0056 
0057 regFaces = sum(ismember(faceEdgeDegrees, [1 2]), 2) == 3;
0058 innerFaces = sum(faceEdgeDegrees == 2, 2) == 3;
0059 borderFaces = regFaces & ~innerFaces;
0060 
0061 % check if mesh is manifold: all faces are either regular or border
0062 b1 = all(regFaces);
0063 
0064 % check if some faces are border
0065 b2 = any(borderFaces);

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