Skip to content

shore.gui.viewport.pygfx_backend ​

pygfx/wgpu implementation of the GUI viewport (ADR 0006, 0037, 0038).

The only module of SHORE that imports pygfx, wgpu or rendercanvas.

Float precision: positions are kept in float64 on the CPU and uploaded as float32(p - origin); the origin follows the orbit target and moves (re-uploading everything, "rebase") when the target drifts more than rebase_factor view widths from it, or on look_at_point. Coordinates reported by pick come from the float64 arrays (ADR 0006, spike item 3).

Drawn objects: per block its six boundary faces (quads) and twelve edges; per slice plane its quads; per geometry its triangles, curves and points.

create_canvas function ​

python
create_canvas(
    parent: Any = None,
    *,
    offscreen: bool = False,
    size: tuple[int, int] = (800, 600),
) -> Any

source

A rendercanvas canvas: a Qt widget, or an offscreen canvas for tests.

PygfxViewport class ​

python
PygfxViewport(canvas: Any, *, rebase_factor: float = 100.0)

source

pygfx/wgpu implementation of Viewport.

PygfxViewport.set_blocks method ​

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

source

PygfxViewport.set_slices method ​

python
set_slices(slices: Sequence[tuple[SliceKey, np.ndarray]]) -> None

source

Replace the slice planes: (SliceKey, the block's nodes).

PygfxViewport.set_geometries method ​

python
set_geometries(geometries: Sequence[tuple[str, Any]]) -> None

source

Replace the geometries: (name, shore.geometry.base.Display).

PygfxViewport.set_skeleton method ​

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

source

Replace the blocking skeleton (ADR 0042): (key, edge nodes (n, 3)), drawn over the blocks so it stays pickable.

PygfxViewport.set_markers method ​

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

source

Replace the blocking face or block markers (ADR 0044): (key, xyz), points drawn over everything so each stays pickable.

PygfxViewport.marker_keys property ​

python
marker_keys: list[Any]

source

PygfxViewport.skeleton_keys property ​

python
skeleton_keys: list[Any]

source

PygfxViewport.show method ​

python
show(kind: str, visible: bool) -> None

source

Show or hide every "block", "slice", "geometry" or "skeleton" object.

PygfxViewport.visible method ​

python
visible(kind: str) -> bool

source

PygfxViewport.set_face_scalars method ​

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

source

Colour block and slice quads by value (keys: block keys, SliceKey), or clear.

PygfxViewport.face_colours method ​

python
face_colours(key: Any) -> np.ndarray

source

The uploaded per-quad RGBA of a block or slice (for tests).

PygfxViewport.keys property ​

python
keys: list[Any]

source

PygfxViewport.slice_keys property ​

python
slice_keys: list[SliceKey]

source

PygfxViewport.geometry_names property ​

python
geometry_names: list[str]

source

PygfxViewport.uploaded_vertices method ​

python
uploaded_vertices(key: Any) -> int

source

PygfxViewport.uploaded_positions method ​

python
uploaded_positions(key: Any) -> np.ndarray

source

float64 world positions of what was uploaded for key's first object.

PygfxViewport.view_width method ​

python
view_width() -> float

source

PygfxViewport.maybe_rebase method ​

python
maybe_rebase() -> bool

source

PygfxViewport.show_all method ​

python
show_all() -> None

source

PygfxViewport.look_at_point method ​

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

source

PygfxViewport.camera_position method ​

python
camera_position() -> np.ndarray

source

The camera's float64 world position.

PygfxViewport.project method ​

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

source

PygfxViewport.pixel_size method ​

python
pixel_size(xyz: np.ndarray) -> float

source

World size of one pixel at xyz (perspective).

PygfxViewport.pick method ​

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

source

PygfxViewport.highlight_polyline method ​

python
highlight_polyline(points: np.ndarray) -> None

source

Outline points (float64, (n, 3)): a selected edge or vertex.

PygfxViewport.on_pick method ​

python
on_pick(callback: Any) -> None

source

Call callback(pick result or None, shift) on a double click in the view.

PygfxViewport.request_draw method ​

python
request_draw() -> None

source

PygfxViewport.draw_now method ​

python
draw_now() -> np.ndarray

source

Render synchronously and return the image (offscreen canvases).

Released under the MIT License.