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 |
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 |
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.
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 |
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 ( |
required |
height
|
float or None
|
Height of the view at the orbit point, as |
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 |
required |
rotation
|
NumpyFloat32Array
|
Quaternion [x, y, z, w], shape (4,). |
required |
up_direction
|
NumpyFloat32Array
|
The camera's up vector in the renderer's |
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 |
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.
cellier.scene.orbit_distance ¶
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
|
required |
height
|
float
|
The size of the view at that point, in world units (the camera's
|
required |
Returns:
| Type | Description |
|---|---|
float or None
|
The distance in world units; |
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 |
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 |
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 |
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 |
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. |
required |
fit_up_3d
|
dict[UUID4, float] or None
|
The up direction of a fitted 3D camera, given like
fit_view_direction_3d. |
required |
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 ( |
required |
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_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 |
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 |
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 |
cellier.scene.spatial_axes ¶
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 |
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 |
required |
name
|
str
|
Name for the system when one is built. Ignored when axes is
already a |
'world'
|
Returns:
| Type | Description |
|---|---|
WorldCoordinateSystem
|
The world system. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If an entry is neither an |
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. |
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 |
required |
render_modes
|
set[Literal['2d', '3d']]
|
Which rendering modes visuals added to this scene should support.
Defaults to |
required |
lighting
|
Literal['none', 'default']
|
|
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
|
required |
slider_axes
property
¶
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. |
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 |
required |
mode
|
('uniform', 'vertical_gradient')
|
|
"uniform"
|
color
|
tuple[float, float, float, float]
|
RGBA fill color used when |
required |
bottom_color
|
tuple[float, float, float, float]
|
RGBA color at the bottom of the canvas when |
required |
top_color
|
tuple[float, float, float, float]
|
RGBA color at the top of the canvas when |
required |