CHECKMESHADJACENTFACES Check if adjacent faces of a mesh have similar orientation. checkMeshAdjacentFaces(VERTICES, EDGES, FACES) The functions returns no output, but if two faces share a common edge with the same direction (meaning that adjacent faces have normals in opposite direction), a warning is displayed. Example [v e f] = createCube(); checkMeshAdjacentFaces(v, e, f); % no output -> all faces have normal outwards of the cube v = [0 0 0; 10 0 0; 0 10 0; 10 10 0]; e = [1 2;1 3;2 3;2 4;3 4]; f = [1 2 3; 2 3 4]; checkMeshAdjacentFaces(v, e, f); Warning: Faces 1 and 2 run through the edge 3 (2-3) in the same direction See also meshes3d, trimeshMeanBreadth
0001 function checkMeshAdjacentFaces(vertices, edges, faces) 0002 %CHECKMESHADJACENTFACES Check if adjacent faces of a mesh have similar orientation. 0003 % 0004 % checkMeshAdjacentFaces(VERTICES, EDGES, FACES) 0005 % The functions returns no output, but if two faces share a common edge 0006 % with the same direction (meaning that adjacent faces have normals in 0007 % opposite direction), a warning is displayed. 0008 % 0009 % Example 0010 % [v e f] = createCube(); 0011 % checkMeshAdjacentFaces(v, e, f); 0012 % % no output -> all faces have normal outwards of the cube 0013 % 0014 % v = [0 0 0; 10 0 0; 0 10 0; 10 10 0]; 0015 % e = [1 2;1 3;2 3;2 4;3 4]; 0016 % f = [1 2 3; 2 3 4]; 0017 % checkMeshAdjacentFaces(v, e, f); 0018 % Warning: Faces 1 and 2 run through the edge 3 (2-3) in the same direction 0019 % 0020 % See also 0021 % meshes3d, trimeshMeanBreadth 0022 % 0023 0024 % ------ 0025 % Author: David Legland 0026 % e-mail: david.legland@inra.fr 0027 % Created: 2010-10-06, using Matlab 7.9.0.529 (R2009b) 0028 % Copyright 2010 INRA - Cepia Software Platform. 0029 0030 % the message pattern that is displayed when an inconsistency is encountered 0031 pattern = 'Faces %d and %d run through the edge %d (%d-%d) in the same direction'; 0032 0033 % If edges are not specified, compute them 0034 if nargin == 2 0035 faces = edges; 0036 edges = meshEdges(vertices, faces); 0037 end 0038 0039 % compute edges to faces map 0040 edgeFaces = meshEdgeFaces(vertices, edges, faces); 0041 Ne = size(edgeFaces, 1); 0042 0043 for i = 1:Ne 0044 % indices of extreimty vertices 0045 v1 = edges(i, 1); 0046 v2 = edges(i, 2); 0047 0048 % index of adjacent faces 0049 indF1 = edgeFaces(i, 1); 0050 indF2 = edgeFaces(i, 2); 0051 0052 % if one of the faces has index 0, then the edge is at the boundary 0053 if indF1 == 0 || indF2 == 0 0054 continue; 0055 end 0056 % vertices of adjacent faces 0057 face1 = meshFace(faces, indF1); 0058 face2 = meshFace(faces, indF2); 0059 0060 % position of vertices in face vertex array 0061 ind11 = find(face1 == v1); 0062 ind12 = find(face1 == v2); 0063 ind21 = find(face2 == v1); 0064 ind22 = find(face2 == v2); 0065 0066 % check if edge is traveled forward or backard 0067 direct1 = (ind12 == ind11+1) | (ind12 == 1 & ind11 == length(face1)); 0068 direct2 = (ind22 == ind21+1) | (ind22 == 1 & ind21 == length(face2)); 0069 0070 % adjacent faces should travel the edge in opposite direction 0071 if direct1 == direct2 0072 warning(pattern, indF1, indF2, i, v1, v2); %#ok<WNTAG> 0073 end 0074 end