Skip to content

Scene

The scene groups the cameras, canvas, and dimension management that together define what is rendered and how it is viewed.

Cameras

cellier.scene.CameraType module-attribute

CameraType = Annotated[Union[PerspectiveCamera, OrthographicCamera], Field(discriminator='camera_type')]

A camera model (perspective or orthographic), told apart by camera_type.

cellier.scene.OrthographicCamera

Bases: BaseCamera

A canvas's 2D orthographic camera; see BaseCamera.

Parameters:

Name Type Description Default
camera_type Literal['orthographic']

Discriminator field. Always "orthographic".

required
width float

Width of the view volume. Default 10.0.

required
height float

Height of the view volume. Default 10.0.

required
near_clipping_plane float

Near clipping distance. Default -500.0.

required
far_clipping_plane float

Far clipping distance. Default 500.0.

required
position NumpyFloat32Array

Camera position in the renderer's (x, y, z) frame, shape (3,).

required
rotation NumpyFloat32Array

Quaternion [x, y, z, w], shape (4,).

required
controller PanZoomCameraController

Must be a pan/zoom controller.

required

has_pose property

has_pose: bool

Whether the pose differs from the default one of an unplaced camera.

False when position is all zeros and rotation the identity quaternion. A canvas created from the model starts such a camera unplaced (it is fitted to the data); any other pose is applied.

model_post_init

model_post_init(__context: Any) -> None

Wire controller event relay after model initialization.

__setattr__

__setattr__(name: str, value: Any) -> None

Refuse derived fields; keep the controller relay on a new controller.

cellier.scene.PerspectiveCamera

Bases: BaseCamera

A canvas's 3D perspective camera; see BaseCamera.

Parameters:

Name Type Description Default
camera_type Literal['perspective']

Discriminator field. Always "perspective".

required
fov float

Field of view in degrees. Default 70.0. 0 is an orthographic projection.

required
width float or None

Width in world units of the view at the point the orbit controller turns the camera about (orbit_distance ahead of the camera). At a fov of 0 the camera turns about itself and every plane is this size, so it is the width of the view. A wheel zoom changes it (and moves the camera); the live camera writes it, as CameraState.extent. Assigning it moves the orbit point, or at a fov of 0 resizes the view. None (the default) until the live camera first writes it, and in files saved before the field existed; a camera placed from such a model keeps its own size.

required
height float or None

Height of the view at the orbit point, as width. Default None.

required
near_clipping_plane float

Near clipping distance. Default 1.0.

required
far_clipping_plane float

Far clipping distance. Default 8000.0. A camera fit raises it when the scene's data needs more (never lowers it), and the controller writes the raised value here.

required
position NumpyFloat32Array

Camera position in the renderer's (x, y, z) frame, shape (3,).

required
rotation NumpyFloat32Array

Quaternion [x, y, z, w], shape (4,).

required
up_direction NumpyFloat32Array

The camera's up vector in the renderer's (x, y, z) frame, shape (3,); the live camera writes the one its rotation gives. Assigning it turns the camera about its view direction to bring its up as close to the vector as it goes, and makes it the up the orbit controller keeps. All zeros until the camera is first written.

required
frustum NumpyFloat32Array

Corners of the view frustum in the renderer's frame, shape (2, 4, 3): the near plane's four corners, then the far plane's. Written by the live camera; assigning it raises AttributeError. All zeros until the camera is first written.

required
controller OrbitCameraController

Must be an orbit controller.

required

has_pose property

has_pose: bool

Whether the pose differs from the default one of an unplaced camera.

False when position is all zeros and rotation the identity quaternion. A canvas created from the model starts such a camera unplaced (it is fitted to the data); any other pose is applied.

orbit_distance property

orbit_distance: float | None

How far ahead of the camera the orbit controller turns it.

Worked out from fov, width and height by orbit_distance; None at a fov of 0 (the camera turns about itself) and while width or height is None.

model_post_init

model_post_init(__context: Any) -> None

Wire controller event relay after model initialization.

__setattr__

__setattr__(name: str, value: Any) -> None

Refuse derived fields; keep the controller relay on a new controller.

cellier.scene.orbit_distance

orbit_distance(fov: float, width: float, height: float) -> float | None

The distance ahead of a 3D camera of the point its orbit controller turns about.

pygfx's orbit controller turns the camera about the point where the view is width by height: 0.5 / tan(fov / 2) times the mean of the two. The field of view is clamped as pygfx clamps it: below 0.5 degrees it is 0, below 1 it is 1, above 179 it is 179.

Parameters:

Name Type Description Default
fov float

Vertical field of view in degrees.

required
width float

The size of the view at that point, in world units (the camera's width and height, or a CameraState.extent).

required
height float

The size of the view at that point, in world units (the camera's width and height, or a CameraState.extent).

required

Returns:

Type Description
float or None

The distance in world units; None at a field of view of 0, where the camera turns about itself.

Camera controllers

cellier.scene.CameraControllerType module-attribute

CameraControllerType = Annotated[Union[OrbitCameraController, PanZoomCameraController], Field(discriminator='controller_type')]

A camera controller (orbit or pan/zoom), told apart by controller_type.

cellier.scene.OrbitCameraController

Bases: BaseCameraController

Orbit controller of a 3D perspective camera.

See BaseCameraController.

Parameters:

Name Type Description Default
controller_type Literal['orbit']

Discriminator field. Always "orbit".

required
Notes

The controller turns the camera about a point straight ahead of it, at the distance orbit_distance gives for the camera's field of view, width and height: the camera's width and height are the size of the view at that point. The point is not stored anywhere else.

cellier.scene.PanZoomCameraController

Bases: BaseCameraController

Pan/zoom controller of a 2D orthographic camera.

See BaseCameraController.

Parameters:

Name Type Description Default
controller_type Literal['pan_zoom']

Discriminator field. Always "pan_zoom".

required

Canvas

cellier.scene.Canvas

Bases: CellierEventedModel

One rendered canvas, holding one or more cameras.

Parameters:

Name Type Description Default
id UUID4

Unique identifier. Auto-generated.

required
cameras dict[str, CameraType]

Mapping of "2d" and/or "3d" to camera models. At least one entry is required, and no other keys are accepted.

required
overlays list[CanvasOverlayType]

Screen-space overlays attached to this canvas. Rendered as post-passes on top of the main scene. Default empty list.

required
size tuple[int, int] or None

The canvas size as (width, height) in logical pixels. Written by the controller whenever the canvas widget is resized; assigning it does not resize the widget. None (default) until the first resize is reported.

required
fit_view_direction_3d dict[UUID4, float] or None

The direction the 3D camera looks along when it is fitted to the scene, as the component along each world axis, by axis id. An axis left out has component 0. None (default) looks along minus all three displayed axes. Used only while every axis it has a component on is displayed; otherwise the default is used (the direction is never projected onto the displayed axes). When the view direction and the up direction come out parallel, both fall back to the defaults.

required
fit_up_3d dict[UUID4, float] or None

The up direction of a fitted 3D camera, given like fit_view_direction_3d. None (default) is the first displayed axis.

required

model_post_init

model_post_init(__context: Any) -> None

Wire camera event relays after model initialization.

Dims

cellier.scene.DimsManager

Bases: CellierEventedModel

Tracks which axes are displayed and the world position of every axis.

Single source of truth for render dimensionality, and the owner of the scene's world coordinate system. One DimsManager per Scene, so there is no second claimant for the world to arbitrate against.

Parameters:

Name Type Description Default
id UUID4

Unique identifier. Auto-generated.

required
world_coordinate_system WorldCoordinateSystem

The scene's world axes. Frozen: changing the axes means assigning a replacement, which is why there is no event relay onto it.

required
selection AxisAlignedSelection

The current axis selection.

required
slider_overrides dict[int, bool]

Per world axis, whether to force its slider shown (True) or hidden (False). An axis absent from the mapping is automatic: it gets a slider when a visual slices it. Only the overrides are stored; the effective set is Scene.slider_axes, which is derived from the visuals and never serialized.

required

axis_labels property

axis_labels: tuple[str, ...]

The world axis names, in order.

ndim property

ndim: int

The number of world axes.

model_post_init

model_post_init(__context: Any) -> None

Wire event relays after model initialization.

Only the selection needs one. world_coordinate_system is a frozen BaseModel with no events group: it cannot change in place, and assigning a replacement already emits this model's own field signal.

to_state

to_state() -> DimsState

Return an immutable snapshot of the current dims state.

to_selection

to_selection(rendered_coordinate_system: RenderedCoordinateSystem, rendered_to_world: AffineTransform) -> RegionSelection

Emit the region one canvas is showing, as the artifact the slicer takes.

This model is the editor -- it holds an index and a thickness, the thing a GUI binds to -- and the slicer consumes one type regardless of which editor produced it. An oblique editor would hold a plane and emit the same type.

The rendered system arrives as an argument rather than being reached for: it is per canvas and is not model state, and this way the model layer never reaches into the render layer.

Thickness comes from the stored mapping, and an axis without an entry is a plane. The region says exactly what the user asked for, and nothing when they asked for nothing. Each visual family then draws what its kind draws from that region: an image or labels visual one plane within it, a geometry visual what lies in it.

Displayed axes are left unbounded, although they keep a stored position. The region type can express a bound on one (a viewport crop); nothing sets it.

Parameters:

Name Type Description Default
rendered_coordinate_system RenderedCoordinateSystem

The system the canvas draws in, in cellier displayed order.

required
rendered_to_world AffineTransform

The rendered -> world embedding. Its constant column carries the slice positions.

required

Returns:

Type Description
RegionSelection

The transform and the region, in world coordinates.

cellier.scene.AxisAlignedSelection

Bases: CellierEventedModel

Mutable selection model for axis-aligned slicing.

Parameters:

Name Type Description Default
selector_type Literal['axis_aligned']

Always "axis_aligned". Kept so saved viewer files, which carry it, still load.

required
displayed_axes tuple[int, ...]

Indices into the coordinate system that are rendered. Length 2 -> 2D; length 3 -> 3D.

required
slice_indices dict[int, float]

Mapping of axis index -> world-space slice position, for every world axis, displayed or not. A displayed axis keeps the position it slices at once it stops being displayed, so a 3D -> 2D switch needs no bookkeeping. A world position, not a voxel index: an integer-valued slider on a 0.5 world-unit-per-voxel axis cannot address the odd-numbered planes.

required
thickness dict[int, float]

Mapping of axis index -> half-thickness in world units. An axis absent from the mapping has thickness 0: a plane. This is the only thickness in the slicing path; no visual family adds one. Per axis rather than scalar because one number means three frames on a 0.5 s/frame time axis and a quarter of a voxel on a 2 um/voxel spatial one.

required

to_state

Return an immutable snapshot of this selection.

cellier.scene.spatial_axes

spatial_axes(*names: str) -> tuple[Axis, ...]

Build spatial axes from their names.

The shorthand for the common all-spatial world -- spatial_axes("z", "y", "x") -- where writing ("z", "space") three times says nothing extra. Mixed worlds spell the non-spatial axes out:

axes = [("t", "time"), ("c", "channel"), *spatial_axes("z", "y", "x")]

Parameters:

Name Type Description Default
*names str

The axis names, in order.

()

Returns:

Type Description
tuple[Axis, ...]

One axis_type="space" axis per name, each with a fresh id.

cellier.scene.world_coordinate_system

world_coordinate_system(axes: WorldAxesLike, name: str = 'world') -> WorldCoordinateSystem

Coerce an axis specification into a world coordinate system.

A WorldCoordinateSystem passes through unchanged, so its axis ids survive -- which matters, because every stored transform names its endpoints by id. Anything else builds a new system with fresh ids.

Parameters:

Name Type Description Default
axes WorldAxesLike

A WorldCoordinateSystem, or a sequence of Axis objects and/or (name, axis_type) pairs.

required
name str

Name for the system when one is built. Ignored when axes is already a WorldCoordinateSystem.

'world'

Returns:

Type Description
WorldCoordinateSystem

The world system.

Raises:

Type Description
TypeError

If an entry is neither an Axis nor a (name, axis_type) pair. A bare string raises here, naming spatial_axes as the fix.

Scene

cellier.scene.Scene

Bases: CellierEventedModel

One rendered scene.

Parameters:

Name Type Description Default
id UUID4

Unique identifier. Auto-generated.

required
name str

Human-readable name, e.g. "main".

required
dims DimsManager

Dimension manager; single source of truth for render dimensionality.

required
visuals list[VisualType]

Discriminated union of visual model types.

required
canvases dict[UUID4, Canvas]

Keyed by canvas.id.

required
render_modes set[Literal['2d', '3d']]

Which rendering modes visuals added to this scene should support. Defaults to {"2d", "3d"}.

required
lighting Literal['none', 'default']

"none" (default) or "default". Pass "default" to add ambient and directional lights — required for MeshPhongAppearance.

required
background BackgroundAppearance

Appearance of the background drawn behind this scene's visuals. Mutating its fields updates the render layer at runtime.

required
overlays list[SceneOverlayType]

World-space overlays attached to this scene, such as a SceneBoundingBox. Drawn by the scene camera in the main pass. Add and remove them through the controller (add_scene_overlay / remove_overlay) so the render layer follows; appending here directly only takes effect when the scene is registered.

required

slider_axes property

slider_axes: tuple[int, ...]

World axes that get a slider when they are not displayed.

Derived from the visuals -- hidden ones included -- and adjusted by dims.slider_overrides: True forces an axis in, False forces it out. A plain property rather than a field, so it is never serialized; the overrides are the only stored state.

Returns:

Type Description
tuple[int, ...]

Sorted world axis indices.

Raises:

Type Description
ValueError

If a visual's transform has no axis correspondence.

model_post_init

model_post_init(__context: Any) -> None

Wire dims, background and visual event relays after initialization.

cellier.scene.BackgroundAppearance

Bases: CellierEventedModel

Appearance of the background drawn behind a scene's visuals.

The background belongs to the scene rather than the canvas: pygfx draws it as a member of the scene graph, so every canvas viewing a scene shares it. Use one Scene per panel when panels need different backgrounds (this is what OrthoViewer already does).

Which color fields are used depends on mode; the others stay set but inert, so switching modes back and forth does not lose a color.

Parameters:

Name Type Description Default
visible bool

Whether the background is drawn at all. When False the canvas shows the renderer's clear color. Default True.

required
mode ('uniform', 'vertical_gradient')

"uniform" fills the canvas with color. "vertical_gradient" (default) blends bottom_color into top_color from the bottom of the canvas to the top.

"uniform"
color tuple[float, float, float, float]

RGBA fill color used when mode is "uniform".

required
bottom_color tuple[float, float, float, float]

RGBA color at the bottom of the canvas when mode is "vertical_gradient".

required
top_color tuple[float, float, float, float]

RGBA color at the top of the canvas when mode is "vertical_gradient".

required

to_colors

to_colors() -> tuple[RGBA, ...]

Return the colors to pass to pygfx.BackgroundMaterial.set_colors.

One color for "uniform", two (bottom, top) for "vertical_gradient" -- the argument order pygfx expects.