Main Content

removeFaces

Remove faces from surface mesh

Since R2022b

    Description

    example

    removeFaces(mesh,faceIDs) removes the faces specified by the face IDs faceIDs from the surfaceMesh object mesh. The function also removes the corresponding normal vectors and colors from the mesh.

    example

    removeFaces(mesh,faceMask) remove the faces specified by the binary face mask faceMask from the surfaceMesh object mesh.

    Examples

    collapse all

    Define mesh vertices for a surface mesh.

    vertices = [1 -1  1; 1 1 1; -1 1 1; -1 -1 1; ...
                1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 -1; ...
                0 0 2; 0 0 -2];

    Define the mesh faces using the vertices.

    faces = [6 2 1; 1 5 6; 8 4 3; 3 7 8; 6 7 3; 3 2 6; ...
             5 1 4; 4 8 5; 4 1 2; 2 3 4; 7 6 5; 5 8 7; ...
             1 4 9; 2 3 9; 5 8 10; 6 7 10];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);
    surfaceMeshShow(mesh,Title="Original Mesh")

    Remove the faces 13th and 14th from the mesh by specifying their face IDs, remove the resulting unreferenced vertices from the mesh. Visualize the output.

    faceIDs = [13 14];
    removeFaces(mesh,faceIDs)
    removeDefects(mesh,"unreferenced-vertices")
    surfaceMeshShow(mesh,Title="Mesh After Removing Faces")

    Define mesh vertices for a surface mesh.

    vertices = [1 -1  1; 1 1 1; -1 1 1; -1 -1 1; ...
                1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 -1; ...
                0 0 2; 0 0 -2];

    Define the mesh faces using the vertices.

    faces = [6 2 1; 1 5 6; 8 4 3; 3 7 8; 6 7 3; 3 2 6; ...
             5 1 4; 4 8 5; 4 1 2; 2 3 4; 7 6 5; 5 8 7; ...
             1 4 9; 2 3 9; 5 8 10; 6 7 10];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);
    surfaceMeshShow(mesh,Title="Original Mesh")

    Mark 13,14 vertices as true and remaining vertices as false to generate a binary mask.

    faceMask = false(1,mesh.NumFaces);
    faceMask([13 14]) = true;

    Remove faces 13 and 14 face from the mesh by using the removeFaces function, and remove the resulting unreferenced vertices. Visualize the output.

    removeFaces(mesh,faceMask);
    removeDefects(mesh,"unreferenced-vertices")
    surfaceMeshShow(mesh,Title="Mesh After Removing Faces")

    Input Arguments

    collapse all

    Surface mesh, specified as a surfaceMesh object.

    Face IDs, specified as an n-element vector. Each face ID is a unique identifier for a face in the mesh and is equal to the row number of the face in the Faces property of the surfaceMesh object. n is the number of faces to remove from the mesh.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Binary mask with mesh faces, specified as an N-element logical vector. N is the total number of mesh faces. If the value of an element is true, the function removes the corresponding face from the mesh. If an element is false, the function does not remove the corresponding face from the mesh.

    Version History

    Introduced in R2022b