pysdic.compute_projected_mesh_mask#

compute_projected_mesh_mask(mesh, camera, *, warp_by=None, flatten=False)[source]#

Compute the boolean mask of the pixels of a camera covered by the projection of a surface mesh.

The vertices of the (deformed) mesh are projected on the sensor (see pysdic.Camera.project()), and a pixel is selected if its center is inside the contour of at least one projected element. The centers of the pixels are at the integer image points: the pixel (row, column) has its center at \(x = \text{column}\) and \(y = \text{row}\).

The contour of an element is the polygon of its projected corner and edge nodes: for a curved element (e.g. "triangle_6"), the edges are approximated by the segments between these nodes. The elements with a non-finite projected node are skipped.

Note

The occlusions are not taken into account: a pixel is selected if any element covers it, visible or hidden (see compute_visibility() and compute_pixel_integration_points() for the material points actually seen by the pixels). The projection of the points behind the camera is not meaningful: the elements crossing the plane of the camera can give a wrong mask.

Parameters:
  • mesh (pysdic.Mesh) – The surface mesh (with an element type), of dimension \(E\) equal to the input dimension of the camera.

  • camera (Union[pysdic.Camera, pysdic.View]) – The camera (or a view, whose camera is used).

  • warp_by (Optional[Union[str, ArrayLike]], optional) – The displacement of the vertices (name of a vertex property or array of shape \((N_v, E)\)), e.g. the displacement of a frame of an analysis.

  • flatten (bool, optional (default: False)) – If True, the mask is returned with shape \((H \times W,)\) (row-major order of the pixels), as expected by pysdic.Camera.get_camera_rays(). Otherwise, with shape \((H, W)\).

Returns:

A boolean array of shape \((H, W)\) (or \((H \times W,)\) if flatten), True for the pixels whose center is inside the projected mesh.

Return type:

numpy.ndarray

Raises:
  • TypeError – If an input has a wrong type.

  • ValueError – If the mesh is not a surface mesh with an element type, or if its dimension is not the input dimension of the camera.

Examples

1from pysdic import compute_projected_mesh_mask
2
3mask = compute_projected_mesh_mask(mesh, camera)  # (H, W)
4mask_1 = compute_projected_mesh_mask(mesh, camera, warp_by=sdic.get_displacement(1))
5
6# Restrict the integration points to the pixels seen at both frames
7points, pixels = compute_pixel_integration_points(mesh, camera, mask=mask & mask_1)