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 --------- Authors: oqilipo, David Legland Created: 2017-07-04
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 % Created: 2017-07-04 0034 0035 % parse inputs 0036 narginchk(2,3) 0037 nargoutchk(1,2) 0038 0039 if nargin == 2 0040 fI = f; 0041 [v, f] = parseMeshData(v); 0042 end 0043 0044 p = inputParser; 0045 isIndexToFaces = @(x) ... 0046 (islogical(x) && isequal(length(x), size(f,1))) || ... 0047 (all(floor(x)==x) && min(x)>=1 && max(x)<=size(f,1)); 0048 addRequired(p,'fI',isIndexToFaces) 0049 parse(p, fI); 0050 if ~islogical(p.Results.fI) 0051 fI=false(size(f,1),1); 0052 fI(p.Results.fI)=true; 0053 else 0054 fI=p.Results.fI; 0055 end 0056 0057 0058 % algorithm 0059 f2 = f(~fI,:); 0060 [unqVertIds, ~, newVertIndices] = unique(f2); 0061 v2 = v(unqVertIds,:); 0062 f2 = reshape(newVertIndices,size(f2)); 0063 0064 0065 % parse outputs 0066 if nargout == 1 0067 mesh2.vertices=v2; 0068 mesh2.faces=f2; 0069 varargout{1}=mesh2; 0070 else 0071 varargout{1}=v2; 0072 varargout{2}=f2; 0073 end 0074 0075 end