Home > matGeom > meshes3d > meshEdges.m

meshEdges

PURPOSE ^

MESHEDGES Computes array of edge vertex indices from face array.

SYNOPSIS ^

function edges = meshEdges(faces, varargin)

DESCRIPTION ^

MESHEDGES Computes array of edge vertex indices from face array.

   EDGES = meshEdges(FACES);

   Example
     meshEdges

   See also
     meshes3d, meshEdgeFaces, meshFaceEdges

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edges = meshEdges(faces, varargin)
0002 %MESHEDGES Computes array of edge vertex indices from face array.
0003 %
0004 %   EDGES = meshEdges(FACES);
0005 %
0006 %   Example
0007 %     meshEdges
0008 %
0009 %   See also
0010 %     meshes3d, meshEdgeFaces, meshFaceEdges
0011 
0012 % ------
0013 % Author: David Legland
0014 % E-mail: david.legland@inrae.fr
0015 % Created: 2011-06-28, using Matlab 7.9.0.529 (R2009b)
0016 % Copyright 2011-2024 INRA - Cepia Software Platform
0017 
0018 %% Process input arguments
0019 
0020 if isstruct(faces) && isfield(faces, 'faces')
0021     % if input is a mesh structure, extract the 'faces' field
0022     faces = faces.faces;
0023 elseif nargin > 1
0024     % if two arguments are given, keep the second one
0025     faces = varargin{1};
0026 end
0027 
0028 
0029 if ~iscell(faces)
0030     %% Process faces given as numeric array
0031     % all faces have same number of vertices
0032     nVF = size(faces,2);
0033     e = nchoosek(1:nVF,2);
0034     A = sparse(faces(:,e(:,1)),faces(:,e(:,2)),1,max(faces(:)),max(faces(:)));
0035     [EI,EJ] = find(tril(A+A'));
0036     edges = [EJ EI];
0037     
0038 else
0039     %% faces are given as a cell array
0040     % faces may have different number of vertices
0041     
0042     % number of faces
0043     nFaces  = length(faces);
0044     
0045     % compute the number of edges
0046     nEdges = 0;
0047     for i = nFaces
0048         nEdges = nEdges + length(faces{i});
0049     end
0050     
0051     % allocate memory
0052     edges = zeros(nEdges, 2);
0053     ind = 0;
0054     
0055     % fillup edge array
0056     for i = 1:nFaces
0057         % get vertex indices, ensuring horizontal array
0058         f = faces{i}(:)';
0059         nVF = length(f);
0060         edges(ind+1:ind+nVF, :) = [f' f([2:end 1])'];
0061         ind = ind + nVF;
0062     end
0063 
0064     % keep only unique edges, and return sorted result
0065     edges = sortrows(unique(sort(edges, 2), 'rows'));
0066 end

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