pysdic.Mesh.filter_vertices#

Mesh.filter_vertices(mask, force_inplace=False)[source]#

Filter the vertices of the mesh by keeping only the vertices corresponding to the True values in the mask, remove all the elements that are connected to the removed vertices and remap the vertices indices accordingly.

This method must be used instead of the vertices.filter_points method because it allows filtering the vertices of the mesh while ensuring that the connectivity structure is maintained and validated. This method will ensure that the mask is compatible with the existing mesh structure and will update the mesh’s vertices accordingly.

Note

The new vertices will be stored in a new vertices object (Copy of the original vertices object with only the filtered vertices). The new connectivity will be stored in a new connectivity object (Copy of the original connectivity object with only the remaining elements that are not connected to the removed vertices and with remapped vertex indices). The properties of the filtered vertices will be updated to keep only the properties of the kept vertices and stored in the new vertices object.

See also

Parameters:
  • mask (ArrayLike) – A boolean array of shape (\(N_v\),) where \(N_v\) is the number of vertices in the mesh, indicating which vertices to keep (True) or remove (False) from the mesh.

  • force_inplace (bool, optional) – If True, the vertices will be updated in place, modifying the original vertices object and the connectivity object will be updated in place as well. If False, new vertices and connectivity objects will be created to store the updated vertices and connectivity, leaving the original vertices and connectivity objects unchanged. By default False.

Raises:
  • TypeError – If mask is not an array-like object or is not a boolean array. If force_inplace is not a boolean.

  • ValueError – If mask does not have the correct shape or is not a boolean array.

Return type:

None

Examples

Create a simple Mesh instance.

1import numpy as np
2from pysdic import Mesh, PointCloud
3
4points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
5connectivity = np.array([[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]])
6mesh3d = Mesh(points, connectivity, element_type="triangle_3")

Filter the vertices of the mesh to remove the first vertex and all the elements connected to it.

1mask = np.array([False, True, True, True])
2mesh3d.filter_vertices(mask)
3
4print(mesh3d.vertices)
5# Output: PointCloud with 3 points [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
6print(mesh3d.connectivity)
7# Output: Connectivity with 1 element [[0, 1, 2]]