Skip to content

shore.gui.viewport ​

The GUI's renderer interface (ADR 0006, 0037).

Only :mod:shore.gui.viewport.pygfx_backend imports pygfx, wgpu or rendercanvas. This module holds the interface and the structured-grid arithmetic the backends share: a block is drawn as its six boundary faces (one quad per boundary cell face, in FACES order) and its twelve edges, and a picked quad maps back to its (block, face, i, j, k) in O(1).

Modules

SliceKey dataclass ​

python
SliceKey(block: Any, axis: str, index: int)

source

A constant-index plane of a block: axis in "ijk", node index.

GeometryPick dataclass ​

python
GeometryPick(geometry: str, entity: Any, xyz: np.ndarray)

source

A picked geometry entity and the float64 point on it.

SkeletonPick dataclass ​

python
SkeletonPick(key: Any, node: int, nodes: int, xyz: np.ndarray)

source

A picked blocking edge (ADR 0042): its key, the node nearest the pick (of nodes, counted along the drawn polyline) and that node's point.

MarkerPick dataclass ​

python
MarkerPick(key: Any, xyz: np.ndarray)

source

A picked blocking face or block marker (ADR 0044): its key and centre.

PickResult dataclass ​

python
PickResult(key: Any, face: str, cell: tuple[int, int, int], xyz: np.ndarray)

source

A picked boundary cell face: its block, face and cell, and its centre.

Viewport class ​

python
class Viewport(Protocol)

source

What the GUI needs from a renderer.

Viewport.set_blocks method ​

python
set_blocks(blocks: Sequence[tuple[Any, np.ndarray]]) -> None

source

Replace the scene with these (key, nodes (ni, nj, nk, 3)) blocks.

Viewport.set_face_scalars method ​

python
set_face_scalars(
    values: dict[Any, np.ndarray] | None,
    clim: tuple[float, float],
) -> None

source

Colour each boundary quad by a value (boundary_values order), or clear.

Viewport.show_all method ​

python
show_all() -> None

source

Viewport.look_at_point method ​

python
look_at_point(xyz: np.ndarray, distance: float) -> None

source

Viewport.pick method ​

python
pick(x: float, y: float) -> PickResult | None

source

Viewport.project method ​

python
project(xyz: np.ndarray) -> tuple[float, float]

source

A world point (float64) to logical pixel coordinates.

Viewport.request_draw method ​

python
request_draw() -> None

source

face_grids function ​

python
face_grids(nodes: np.ndarray) -> list[np.ndarray]

source

The six boundary node grids (na, nb, 3) of a block, in FACES order.

quad_indices function ​

python
quad_indices(na: int, nb: int, base: int = 0) -> np.ndarray

source

Quads ((na-1)*(nb-1), 4) of an na x nb node grid, a-major.

quad_offsets function ​

python
quad_offsets(shape: tuple[int, int, int]) -> np.ndarray

source

Index of each face's first quad in a block's quad list, plus the total.

quad_cell function ​

python
quad_cell(shape: tuple[int, int, int], quad: int) -> tuple[str, tuple[int, int, int]]

source

The face and the (i, j, k) cell behind quad number quad of a block.

quad_centre function ​

python
quad_centre(nodes: np.ndarray, face: str, cell: tuple[int, int, int]) -> np.ndarray

source

float64 centre of the boundary quad of cell on face.

boundary_values function ​

python
boundary_values(cell_values: np.ndarray) -> np.ndarray

source

Per boundary quad, the value of the cell behind it ((ni-1, nj-1, nk-1) input).

Quads follow FACES order and, within a face, quad_indices order.

edge_segments function ​

python
edge_segments(nodes: np.ndarray) -> np.ndarray

source

The 12 block edges as line-segment vertex pairs (2m, 3).

colormap function ​

python
colormap(values: np.ndarray, clim: tuple[float, float]) -> np.ndarray

source

RGBA float32 of values on a blue-white-red ramp over clim (NaN: grey).

slice_grid function ​

python
slice_grid(nodes: np.ndarray, axis: str, index: int) -> np.ndarray

source

The node grid (na, nb, 3) of the constant-axis plane index.

slice_cell function ​

python
slice_cell(
    shape: tuple[int, int, int],
    axis: str,
    index: int,
    quad: int,
) -> tuple[int, int, int]

source

The cell of a slice quad: on the plane's + side, or its - side on the last plane.

slice_values function ​

python
slice_values(cell_values: np.ndarray, axis: str, index: int) -> np.ndarray

source

Per slice quad, the value of its cell (slice_cell), in quad order.

edge_nodes function ​

python
edge_nodes(nodes: np.ndarray, name: str) -> np.ndarray

source

The node polyline of block edge name (HexBlock edge naming).

face_edges function ​

python
face_edges(face: str) -> tuple[str, ...]

source

The four edges bounding face.

face_vertices function ​

python
face_vertices(face: str) -> tuple[int, ...]

source

The four corners (vertex indices) of face.

nearest_edge function ​

python
nearest_edge(nodes: np.ndarray, face: str, xyz: np.ndarray) -> str

source

The edge of face closest to the point xyz (an edge pick).

nearest_vertex function ​

python
nearest_vertex(nodes: np.ndarray, face: str, xyz: np.ndarray) -> int

source

The corner of face closest to the point xyz (a vertex pick).

Released under the MIT License.