Home > matGeom > meshes3d > trimeshEdgeFaces.m

trimeshEdgeFaces

PURPOSE ^

TRIMESHEDGEFACES Compute index of faces adjacent to each edge of a triangular mesh.

SYNOPSIS ^

function edgeFaces = trimeshEdgeFaces(faces, varargin)

DESCRIPTION ^

TRIMESHEDGEFACES Compute index of faces adjacent to each edge of a triangular mesh.

   EF = trimeshEdgeFaces(FACES)
   EF = trimeshEdgeFaces(VERTICES, FACES)
   EF = trimeshEdgeFaces(VERTICES, EDGES, FACES)
   Compute index array of faces adjacent to each edge of a mesh.
   FACES is a NF-by-3 array containing vertex indices of each face. The
   result EF is a NE-by-2 array containing the indices of the two faces
   incident to each edge. If an edge belongs to only one face, the other
   face index is ZERO.

   The list of edges (as array of source and target vertex indices) can be
   obtained from the function 'meshEdges'.

   Note: faces are listed in increasing order for each edge, and no
   information is kept about relative orientation of edge and face.

   Example
     % compute incidence list of each edge of an octahedron. For example,
     % first edge is incident to faces 1 and 5. Second edge is incident to
     % faces 4 and 8, and so on.
     [v, f] = createOctahedron;
     ef = trimeshEdgeFaces(v, f)
     ef =
          1     5
          4     8
          4     1
          5     8
          2     6
          1     2
          6     5
          3     7
          2     3
          7     6
          3     4
          7     8

   See also
   meshes3d, meshEdgeFaces, trimeshMeanBreadth, meshEdges

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edgeFaces = trimeshEdgeFaces(faces, varargin)
0002 %TRIMESHEDGEFACES Compute index of faces adjacent to each edge of a triangular mesh.
0003 %
0004 %   EF = trimeshEdgeFaces(FACES)
0005 %   EF = trimeshEdgeFaces(VERTICES, FACES)
0006 %   EF = trimeshEdgeFaces(VERTICES, EDGES, FACES)
0007 %   Compute index array of faces adjacent to each edge of a mesh.
0008 %   FACES is a NF-by-3 array containing vertex indices of each face. The
0009 %   result EF is a NE-by-2 array containing the indices of the two faces
0010 %   incident to each edge. If an edge belongs to only one face, the other
0011 %   face index is ZERO.
0012 %
0013 %   The list of edges (as array of source and target vertex indices) can be
0014 %   obtained from the function 'meshEdges'.
0015 %
0016 %   Note: faces are listed in increasing order for each edge, and no
0017 %   information is kept about relative orientation of edge and face.
0018 %
0019 %   Example
0020 %     % compute incidence list of each edge of an octahedron. For example,
0021 %     % first edge is incident to faces 1 and 5. Second edge is incident to
0022 %     % faces 4 and 8, and so on.
0023 %     [v, f] = createOctahedron;
0024 %     ef = trimeshEdgeFaces(v, f)
0025 %     ef =
0026 %          1     5
0027 %          4     8
0028 %          4     1
0029 %          5     8
0030 %          2     6
0031 %          1     2
0032 %          6     5
0033 %          3     7
0034 %          2     3
0035 %          7     6
0036 %          3     4
0037 %          7     8
0038 %
0039 %   See also
0040 %   meshes3d, meshEdgeFaces, trimeshMeanBreadth, meshEdges
0041  
0042 % ------
0043 % Author: David Legland
0044 % e-mail: david.legland@nantes.inra.fr
0045 % Created: 2015-08-19,    using Matlab 8.5.0.197613 (R2015a)
0046 % Copyright 2015 INRA - Cepia Software Platform.
0047 
0048 if nargin == 2
0049     faces = varargin{1};
0050 elseif nargin == 3
0051     faces = varargin{2};
0052 end
0053 
0054 % compute vertex indices of each edge (in increasing index order)
0055 edges = sort([faces(:,[1 2]) ; faces(:,[2 3]) ; faces(:,[3 1])], 2);
0056 
0057 % create an array to keep indices of faces "creating" each edge
0058 nFaces = size(faces, 1);
0059 edgeFaceInds = repmat( (1:nFaces)', 3, 1);
0060 
0061 % sort edges, keeping indices
0062 [edges, ia, ib] = unique(edges, 'rows'); %#ok<ASGLU>
0063 nEdges = size(edges, 1);
0064 
0065 % allocate memory for result
0066 edgeFaces = zeros(nEdges, 2);
0067 
0068 % iterate over edges, to identify incident faces
0069 for iEdge = 1:nEdges
0070     inds = find(ib == iEdge);
0071     edgeFaces(iEdge, 1:length(inds)) = edgeFaceInds(inds);
0072 end
0073

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