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
shore.gui.viewport.pygfx_backend— pygfx/wgpu implementation of the GUI viewport
SliceKey dataclass
SliceKey(block: Any, axis: str, index: int)A constant-index plane of a block: axis in "ijk", node index.
GeometryPick dataclass
GeometryPick(geometry: str, entity: Any, xyz: np.ndarray)A picked geometry entity and the float64 point on it.
SkeletonPick dataclass
SkeletonPick(key: Any, node: int, nodes: int, xyz: np.ndarray)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
MarkerPick(key: Any, xyz: np.ndarray)A picked blocking face or block marker (ADR 0044): its key and centre.
PickResult dataclass
PickResult(key: Any, face: str, cell: tuple[int, int, int], xyz: np.ndarray)A picked boundary cell face: its block, face and cell, and its centre.
Viewport class
class Viewport(Protocol)What the GUI needs from a renderer.
Viewport.set_blocks method
set_blocks(blocks: Sequence[tuple[Any, np.ndarray]]) -> NoneReplace the scene with these (key, nodes (ni, nj, nk, 3)) blocks.
Viewport.set_face_scalars method
set_face_scalars(
values: dict[Any, np.ndarray] | None,
clim: tuple[float, float],
) -> NoneColour each boundary quad by a value (boundary_values order), or clear.
Viewport.show_all method
show_all() -> NoneViewport.look_at_point method
look_at_point(xyz: np.ndarray, distance: float) -> NoneViewport.pick method
pick(x: float, y: float) -> PickResult | NoneViewport.project method
project(xyz: np.ndarray) -> tuple[float, float]A world point (float64) to logical pixel coordinates.
Viewport.request_draw method
request_draw() -> Noneface_grids function
face_grids(nodes: np.ndarray) -> list[np.ndarray]The six boundary node grids (na, nb, 3) of a block, in FACES order.
quad_indices function
quad_indices(na: int, nb: int, base: int = 0) -> np.ndarrayQuads ((na-1)*(nb-1), 4) of an na x nb node grid, a-major.
quad_offsets function
quad_offsets(shape: tuple[int, int, int]) -> np.ndarrayIndex of each face's first quad in a block's quad list, plus the total.
quad_cell function
quad_cell(shape: tuple[int, int, int], quad: int) -> tuple[str, tuple[int, int, int]]The face and the (i, j, k) cell behind quad number quad of a block.
quad_centre function
quad_centre(nodes: np.ndarray, face: str, cell: tuple[int, int, int]) -> np.ndarrayfloat64 centre of the boundary quad of cell on face.
boundary_values function
boundary_values(cell_values: np.ndarray) -> np.ndarrayPer 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
edge_segments(nodes: np.ndarray) -> np.ndarrayThe 12 block edges as line-segment vertex pairs (2m, 3).
colormap function
colormap(values: np.ndarray, clim: tuple[float, float]) -> np.ndarrayRGBA float32 of values on a blue-white-red ramp over clim (NaN: grey).
slice_grid function
slice_grid(nodes: np.ndarray, axis: str, index: int) -> np.ndarrayThe node grid (na, nb, 3) of the constant-axis plane index.
slice_cell function
slice_cell(
shape: tuple[int, int, int],
axis: str,
index: int,
quad: int,
) -> tuple[int, int, int]The cell of a slice quad: on the plane's + side, or its - side on the last plane.
slice_values function
slice_values(cell_values: np.ndarray, axis: str, index: int) -> np.ndarrayPer slice quad, the value of its cell (slice_cell), in quad order.
edge_nodes function
edge_nodes(nodes: np.ndarray, name: str) -> np.ndarrayThe node polyline of block edge name (HexBlock edge naming).
face_edges function
face_edges(face: str) -> tuple[str, ...]The four edges bounding face.
face_vertices function
face_vertices(face: str) -> tuple[int, ...]The four corners (vertex indices) of face.
nearest_edge function
nearest_edge(nodes: np.ndarray, face: str, xyz: np.ndarray) -> strThe edge of face closest to the point xyz (an edge pick).
nearest_vertex function
nearest_vertex(nodes: np.ndarray, face: str, xyz: np.ndarray) -> intThe corner of face closest to the point xyz (a vertex pick).