pysdic.interpolate_texture#
- interpolate_texture(mesh, integration_points, texture)[source]#
Evaluate the texture of a surface mesh at integration points, through its UV map.
The UV coordinates of a point \(p\) of natural coordinates \(\Xi_p\) in the element \(e\) are interpolated from the UV coordinates of the vertices of the element (see
pysdic.Mesh.uvmap):\[(u_p, v_p) = \sum_{k=1}^{N_{vpe}} N_k(\Xi_p) \, (u_{e,k}, v_{e,k})\]The UV map is defined per element, so the seams of the UV map are respected. The texture is then evaluated (with the interpolation function of the
pysdic.Image) at the image point:\[x = u \, W_t - 0.5, \qquad y = (1 - v) \, H_t - 0.5\]following the OpenGL convention of the UV maps of
pysdic: \((u, v) \in [0, 1]^2\) covers the whole texture of height \(H_t\) and width \(W_t\), with \(v\) pointing upward. The image points are clamped to the centers of the edge pixels of the texture (clamp to edge).The natural coordinates do not depend on the displacement of the mesh: the texture is attached to the material.
- Parameters:
mesh (
pysdic.Mesh) – The surface mesh (\(K = 2\), any dimension \(E\)), with an element type and a UV map.integration_points (
pysdic.IntegrationPoints) – The points, consistent with the mesh. The unlocated points get NaN values.texture (Union[
pysdic.Image, ArrayLike]) – The texture, anpysdic.Imageor an array of shape \((H_t, W_t)\) or \((H_t, W_t, C)\) (converted withpysdic.Image.from_array(), cubic splines). With anpysdic.Image, its interpolation degrees, region of interest and default value are used (points out of the ROI get the default value).
- Returns:
The values of the texture, a float array of shape \((N_p, C)\), with \(C = 1\) for a grayscale texture.
- Return type:
- Raises:
TypeError – If an input has a wrong type.
ValueError – If the mesh is not a surface mesh with a UV map, the points are not consistent with the mesh, or the texture has a wrong shape.
Examples
Gray levels of a speckle texture at the Gauss points of a mesh:
import numpy from pysdic import IntegrationPoints, compute_wave_speckle, interpolate_texture u, v = numpy.meshgrid(numpy.linspace(0, 1, 512), numpy.linspace(0, 1, 512)) texture = compute_wave_speckle(numpy.stack((u, v), axis=-1), wavelength=0.02) values = interpolate_texture(mesh, integration_points, texture) # (N_p, 1)