Main Content

removeVertices

Remove vertices from surface mesh

Since R2022b

    Description

    removeVertices(mesh,vertexIDs) removes the vertices specified by the vertex IDs vertexIDs from the surfaceMesh object mesh. The function also removes the corresponding normal vectors and colors from the mesh.

    example

    removeVertices(mesh,vertexMask) removes the vertices specified by the binary vertex mask vertexMask from the surfaceMesh object mesh. The function also removes the corresponding normal vectors and colors from the mesh.

    example

    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 9th and 10th vertices of the surface mesh. Display the updated mesh.

    vertexIDs = [9 10];
    removeVertices(mesh,vertexIDs)
    surfaceMeshShow(mesh,Title="Mesh After Removing Vertices")

    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")

    Generate a binary mask by marking the 9th and 10th vertices as true and remaining vertices as false.

    vertexMask = false(1,mesh.NumVertices);
    vertexMask([9 10]) = true;

    Remove vertices 9 and 10 by using the removeVertices function, and display the results.

    removeVertices(mesh,vertexMask)
    surfaceMeshShow(mesh,Title="Mesh After Removing Vertices")

    Input Arguments

    collapse all

    Surface mesh, specified as a surfaceMesh object.

    Vertex IDs, specified as an m-element vector. Each vertex ID is a unique identifier for a vertex in the mesh and is equal to the row number of the vertex in the Vertices property of the surfaceMesh object. m is the number of vertices to remove from the mesh.

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

    Binary mask with mesh vertices, specified as an M-element logical vector. M is the total number of mesh vertices in the mesh. If the value of an element is true, the function removes the vertex with the corresponding vertex ID from the mesh. If an element is false, the function does not remove the corresponding vertex from the mesh.

    Version History

    Introduced in R2022b