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_pointsmethod 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
keep_vertices()to keep only specified vertices in the mesh.remove_vertices()to remove specified vertices from the mesh.PointCloudfor more information on the vertices structure.Connectivityfor more information on the connectivity structure and element types.
- 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) – IfTrue, the vertices will be updated in place, modifying the original vertices object and the connectivity object will be updated in place as well. IfFalse, new vertices and connectivity objects will be created to store the updated vertices and connectivity, leaving the original vertices and connectivity objects unchanged. By defaultFalse.
- Raises:
TypeError – If
maskis not an array-like object or is not a boolean array. Ifforce_inplaceis not a boolean.ValueError – If
maskdoes not have the correct shape or is not a boolean array.
- Return type:
None
Examples
Create a simple
Meshinstance.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]]