MESHEDGES Computes array of edge vertex indices from face array. EDGES = meshEdges(FACES); Example meshEdges See also meshes3d, meshEdgeFaces, meshFaceEdges
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@grignon.inra.fr 0015 % Created: 2011-06-28, using Matlab 7.9.0.529 (R2009b) 0016 % Copyright 2011 INRA - Cepia Software Platform. 0017 0018 % HISTORY 0019 % 2013-08-22 rename from computeMeshEdges to meshEdges, add more control 0020 % on inputs 0021 0022 %% Process input arguments 0023 0024 if isstruct(faces) && isfield(faces, 'faces') 0025 % if input is a mesh structure, extract the 'faces' field 0026 faces = faces.faces; 0027 elseif nargin > 1 0028 % if two arguments are given, keep the second one 0029 faces = varargin{1}; 0030 end 0031 0032 0033 if ~iscell(faces) 0034 %% Process faces given as numeric array 0035 % all faces have same number of vertices, stored in nVF variable 0036 0037 % compute total number of edges 0038 nFaces = size(faces, 1); 0039 nVF = size(faces, 2); 0040 nEdges = nFaces * nVF; 0041 0042 % create all edges (with double ones) 0043 edges = zeros(nEdges, 2); 0044 for i = 1:nFaces 0045 f = faces(i, :); 0046 edges(((i-1)*nVF+1):i*nVF, :) = [f' f([2:end 1])']; 0047 end 0048 0049 else 0050 %% faces are given as a cell array 0051 % faces may have different number of vertices 0052 0053 % number of faces 0054 nFaces = length(faces); 0055 0056 % compute the number of edges 0057 nEdges = 0; 0058 for i = nFaces 0059 nEdges = nEdges + length(faces{i}); 0060 end 0061 0062 % allocate memory 0063 edges = zeros(nEdges, 2); 0064 ind = 0; 0065 0066 % fillup edge array 0067 for i = 1:nFaces 0068 % get vertex indices, ensuring horizontal array 0069 f = faces{i}(:)'; 0070 nVF = length(f); 0071 edges(ind+1:ind+nVF, :) = [f' f([2:end 1])']; 0072 ind = ind + nVF; 0073 end 0074 0075 end 0076 0077 % keep only unique edges, and return sorted result 0078 edges = sortrows(unique(sort(edges, 2), 'rows'));