REMOVEMESHFACES Remove faces from a mesh by face indices. [V2, F2] = removeMeshFaces(V, F, FI) removes faces from the mesh by the face indices FI into faces F of the mesh. The mesh is represented by the vertex array V and the face array F. The result is the new set of vertices V2 and faces F2 without the faces indexed by FI. FI can be either a linear or a logical index. [V2, F2] = removeMeshFaces(MESH, FI) with the struct MESH containing the fields "vertices" (V) and "faces" (F) MESH2 = removeMeshFaces(V, F, FI) with the struct MESH2 containing the fields "vertices" (V2) and "faces" (F2) MESH2 = removeMeshFaces(MESH, FI) with the structs MESH and MESH2 containing the fields "vertices" (V, V2) and "faces" (F, F2) Example [v, f] = createSoccerBall; f = triangulateFaces(f); fI = true(length(f),1); fI(1:length(f)/2) = false; [v2, f2] = removeMeshFaces(v, f, fI); drawMesh(v, f, 'faceColor', 'none', 'faceAlpha', .2); drawMesh(v2, f2, 'faceAlpha', .7); view(3); axis equal See also meshes3d, drawMesh
0001 function varargout = removeMeshFaces(v, f, fI) 0002 %REMOVEMESHFACES Remove faces from a mesh by face indices. 0003 % [V2, F2] = removeMeshFaces(V, F, FI) removes faces from the mesh by 0004 % the face indices FI into faces F of the mesh. The mesh is represented 0005 % by the vertex array V and the face array F. The result is the new set 0006 % of vertices V2 and faces F2 without the faces indexed by FI. FI can be 0007 % either a linear or a logical index. 0008 % 0009 % [V2, F2] = removeMeshFaces(MESH, FI) with the struct MESH containing 0010 % the fields "vertices" (V) and "faces" (F) 0011 % 0012 % MESH2 = removeMeshFaces(V, F, FI) with the struct MESH2 containing the 0013 % fields "vertices" (V2) and "faces" (F2) 0014 % 0015 % MESH2 = removeMeshFaces(MESH, FI) with the structs MESH and MESH2 0016 % containing the fields "vertices" (V, V2) and "faces" (F, F2) 0017 % 0018 % Example 0019 % [v, f] = createSoccerBall; 0020 % f = triangulateFaces(f); 0021 % fI = true(length(f),1); 0022 % fI(1:length(f)/2) = false; 0023 % [v2, f2] = removeMeshFaces(v, f, fI); 0024 % drawMesh(v, f, 'faceColor', 'none', 'faceAlpha', .2); 0025 % drawMesh(v2, f2, 'faceAlpha', .7); 0026 % view(3); axis equal 0027 % 0028 % See also 0029 % meshes3d, drawMesh 0030 0031 % ------ 0032 % Authors: oqilipo, David Legland 0033 % E-mail: david.legland@inrae.fr 0034 % Created: 2017-07-04 0035 % Copyright 2017-2024 0036 0037 % parse inputs 0038 narginchk(2,3) 0039 nargoutchk(1,2) 0040 0041 if nargin == 2 0042 fI = f; 0043 [v, f] = parseMeshData(v); 0044 end 0045 0046 p = inputParser; 0047 isIndexToFaces = @(x) ... 0048 (islogical(x) && isequal(length(x), size(f,1))) || ... 0049 (all(floor(x)==x) && min(x)>=1 && max(x)<=size(f,1)); 0050 addRequired(p,'fI',isIndexToFaces) 0051 parse(p, fI); 0052 if ~islogical(p.Results.fI) 0053 fI=false(size(f,1),1); 0054 fI(p.Results.fI)=true; 0055 else 0056 fI=p.Results.fI; 0057 end 0058 0059 0060 % algorithm 0061 f2 = f(~fI,:); 0062 [unqVertIds, ~, newVertIndices] = unique(f2); 0063 v2 = v(unqVertIds,:); 0064 f2 = reshape(newVertIndices,size(f2)); 0065 0066 0067 % parse outputs 0068 if nargout == 1 0069 mesh2.vertices=v2; 0070 mesh2.faces=f2; 0071 varargout{1}=mesh2; 0072 else 0073 varargout{1}=v2; 0074 varargout{2}=f2; 0075 end 0076 0077 end