# removeDefects

Remove surface mesh defects

Since R2022b

## Syntax

``removeDefects(mesh,"duplicate-vertices")``
``removeDefects(mesh,"duplicate-faces")``
``removeDefects(mesh,"unreferenced-vertices")``
``removeDefects(mesh,"degenerate-faces")``
``removeDefects(mesh,"nonmanifold-edges")``

## Description

````removeDefects(mesh,"duplicate-vertices")` removes duplicate vertices from the surface mesh `mesh`.```
````removeDefects(mesh,"duplicate-faces")` removes duplicate faces from the surface mesh `mesh`.```

example

````removeDefects(mesh,"unreferenced-vertices")` removes unreferenced vertices from the surface mesh `mesh`. Unreferenced vertices are those vertices that are not part of any face.```
````removeDefects(mesh,"degenerate-faces")` removes degenerate faces from the surface mesh `mesh`. Degenerate faces are faces with an area of zero.```

example

````removeDefects(mesh,"nonmanifold-edges")` removes nonmanifold edges from the surface mesh `mesh`.```

## Examples

collapse all

Define mesh vertices and faces for the 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]; 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];```

Create and display the mesh.

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

Add new vertices to the mesh.

```newVertices = [1, 2, 3; 4, 5, 6]; addVertices(mesh, newVertices)```

Remove unreferenced vertices from the surface mesh.

`removeDefects(mesh,"unreferenced-vertices")`

Define mesh vertices and faces for the surface mesh.

```vertices = [0 0 0; 0 0 1; 0 1 1; 0 0 2; 1 0.5 1]; faces = [1 2 3; 2 3 4; 2 3 5];```

Create the surface mesh.

`mesh = surfaceMesh(vertices,faces);`

Check if the mesh is edge-manifold.

```allowBoundaryEdges = true; edgeManifoldBefore = isEdgeManifold(mesh,allowBoundaryEdges)```
```edgeManifoldBefore = logical 0 ```

Remove nonmanifold edges from the surface mesh and check if the mesh is edge-manifold.

```removeDefects(mesh,"nonmanifold-edges") edgeManifoldAfter = isEdgeManifold(mesh,allowBoundaryEdges)```
```edgeManifoldAfter = logical 1 ```

## Input Arguments

collapse all

Surface mesh, specified as a `surfaceMesh` object.

## Version History

Introduced in R2022b