multigrid.utils.rendering module#

multigrid.utils.rendering.downsample(img: ndarray[Any, dtype[uint8]], factor: int) ndarray[Any, dtype[uint8]][source]#

Downsample an image along both dimensions by some factor.

Parameters:
imgndarray[uint8] of shape (height, width, 3)

The image to downsample

factorint

The factor by which to downsample the image

Returns:
imgndarray[uint8] of shape (height/factor, width/factor, 3)

The downsampled image

multigrid.utils.rendering.fill_coords(img: ndarray[Any, dtype[uint8]], fn: Callable[[float, float], bool], color: ndarray[Any, dtype[uint8]]) ndarray[Any, dtype[uint8]][source]#

Fill pixels of an image with coordinates matching a filter function.

Parameters:
imgndarray[uint8] of shape (height, width, 3)

The image to fill

fnCallable(float, float) -> bool

The filter function to use for coordinates

colorndarray[uint8] of shape (3,)

RGB color to fill matching coordinates

Returns:
imgndarray[np.uint8] of shape (height, width, 3)

The updated image

multigrid.utils.rendering.rotate_fn(fin: Callable[[float, float], bool], cx: float, cy: float, theta: float) Callable[[float, float], bool][source]#

Rotate a coordinate filter function around a center point by some angle.

Parameters:
finCallable(float, float) -> bool

The filter function to rotate

cxfloat

The x-coordinate of the center of rotation

cyfloat

The y-coordinate of the center of rotation

thetafloat

The angle by which to rotate the filter function (in radians)

Returns:
foutCallable(float, float) -> bool

The rotated filter function

multigrid.utils.rendering.point_in_line(x0: float, y0: float, x1: float, y1: float, r: float) Callable[[float, float], bool][source]#

Return a filter function that returns True for points within distance r from the line between (x0, y0) and (x1, y1).

Parameters:
x0float

The x-coordinate of the line start point

y0float

The y-coordinate of the line start point

x1float

The x-coordinate of the line end point

y1float

The y-coordinate of the line end point

rfloat

Maximum distance from the line

Returns:
fnCallable(float, float) -> bool

Filter function

multigrid.utils.rendering.point_in_circle(cx: float, cy: float, r: float) Callable[[float, float], bool][source]#

Return a filter function that returns True for points within radius r from a given point.

Parameters:
cxfloat

The x-coordinate of the circle center

cyfloat

The y-coordinate of the circle center

rfloat

The radius of the circle

Returns:
fnCallable(float, float) -> bool

Filter function

multigrid.utils.rendering.point_in_rect(xmin: float, xmax: float, ymin: float, ymax: float) Callable[[float, float], bool][source]#

Return a filter function that returns True for points within a rectangle.

Parameters:
xminfloat

The minimum x-coordinate of the rectangle

xmaxfloat

The maximum x-coordinate of the rectangle

yminfloat

The minimum y-coordinate of the rectangle

ymaxfloat

The maximum y-coordinate of the rectangle

Returns:
fnCallable(float, float) -> bool

Filter function

multigrid.utils.rendering.point_in_triangle(a: tuple[float, float], b: tuple[float, float], c: tuple[float, float]) Callable[[float, float], bool][source]#

Return a filter function that returns True for points within a triangle.

Parameters:
atuple[float, float]

The first vertex of the triangle

btuple[float, float]

The second vertex of the triangle

ctuple[float, float]

The third vertex of the triangle

Returns:
fnCallable(float, float) -> bool

Filter function

multigrid.utils.rendering.highlight_img(img: ndarray[Any, dtype[uint8]], color: ndarray[Any, dtype[uint8]] = array([255, 255, 255]), alpha=0.3) ndarray[Any, dtype[uint8]][source]#

Add highlighting to an image.

Parameters:
imgndarray[uint8] of shape (height, width, 3)

The image to highlight

colorndarray[uint8] of shape (3,)

RGB color to use for highlighting

alphafloat

The alpha value to use for blending

Returns:
imgndarray[uint8] of shape (height, width, 3)

The highlighted image