Home > matGeom > meshes3d > meshAdjacencyMatrix.m

meshAdjacencyMatrix

PURPOSE ^

MESHADJACENCYMATRIX Compute adjacency matrix of a mesh from set of faces.

SYNOPSIS ^

function adj = meshAdjacencyMatrix(faces, varargin)

DESCRIPTION ^

MESHADJACENCYMATRIX Compute adjacency matrix of a mesh from set of faces.

   ADJMAT = meshAdjacencyMatrix(FACES)
   Returns a sparse NV-by-NV matrix (NV being the largest vertex index)
   containing vertex adjacency of the mesh represented by FACES.
   FACES is either a NF-by-3, a NF-by-4 index array, or a Nf-by-1 cell
   array.

   Example
     [v f] = createCube;
     adj = meshAdjacencyMatrix(f);

   See also
     meshes3d, triangulateFaces, smoothMesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function adj = meshAdjacencyMatrix(faces, varargin)
0002 %MESHADJACENCYMATRIX Compute adjacency matrix of a mesh from set of faces.
0003 %
0004 %   ADJMAT = meshAdjacencyMatrix(FACES)
0005 %   Returns a sparse NV-by-NV matrix (NV being the largest vertex index)
0006 %   containing vertex adjacency of the mesh represented by FACES.
0007 %   FACES is either a NF-by-3, a NF-by-4 index array, or a Nf-by-1 cell
0008 %   array.
0009 %
0010 %   Example
0011 %     [v f] = createCube;
0012 %     adj = meshAdjacencyMatrix(f);
0013 %
0014 %   See also
0015 %     meshes3d, triangulateFaces, smoothMesh
0016 
0017 % ------
0018 % Author: David Legland
0019 % e-mail: david.legland@inra.fr
0020 % Created: 2013-04-30,    using Matlab 7.9.0.529 (R2009b)
0021 % Copyright 2013 INRA - Cepia Software Platform.
0022 
0023 % Ensures faces is a N-by-3 or N-by-4 array
0024 if iscell(faces) || (isnumeric(faces) && size(faces, 2) > 4)
0025     faces = triangulateFaces(faces);
0026 end
0027 
0028 % forces faces to be floating point array, for sparse function
0029 if ~isfloat(faces)
0030     faces = double(faces);
0031 end
0032 nv = max(faces(:));
0033     
0034 % populate a sparse matrix
0035 if size(faces, 2) == 3
0036     adj = sparse(...
0037         [faces(:,1); faces(:,1); faces(:,2); faces(:,2); faces(:,3); faces(:,3)], ...
0038         [faces(:,3); faces(:,2); faces(:,1); faces(:,3); faces(:,2); faces(:,1)], ...
0039         1.0, nv, nv);
0040 elseif size(faces, 2) == 4
0041     adj = sparse(...
0042         [faces(:,1); faces(:,1); faces(:,2); faces(:,2); faces(:,3); faces(:,3); faces(:,4); faces(:,4)], ...
0043         [faces(:,4); faces(:,2); faces(:,1); faces(:,3); faces(:,2); faces(:,4); faces(:,3); faces(:,1)], ...
0044         1.0, nv, nv);
0045 end
0046    
0047 % remove double adjacencies
0048 adj = min(adj, 1);

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