Paint¶
Paint controllers apply label edits to data stores, with undo/redo history and write buffering for multiscale data.
Controllers¶
cellier.paint.AbstractPaintController ¶
Bases: ABC
Minimal shared base for paint controllers.
Owns: EventBus subscriptions, CommandHistory,
ActiveStroke accumulation, and camera-controller locking on
the bound canvas.
A press starts a stroke and every move and the release extend it with
a ball of brush_radius_voxels round the pointer. A press is ignored
when it falls outside the data, and refused, with a UserWarning,
when the visual cannot be painted faithfully in the current view (for
example a tilted 2D view of the data). The brush skips voxels the
visual's clipping planes cut away.
Subclassing
A storage backend subclasses this and supplies:
_data_shape(tuple of int, the shape of the painted array),_displayed_axes(the two data axes the 2D view shows) and_store_dtype(the array's NumPy dtype), set before callingsuper().__init__, which raisesAttributeErrorotherwise._read_old_valuesand_write_values: read and write the voxels a brush touches._on_stroke_completed: called once per finished stroke, for example to flush or upload it.commitandabort: end the session.
The underscored methods are hooks for subclasses, not for callers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cellier_controller
|
CellierController
|
|
required |
visual_id
|
UUID
|
|
required |
scene_id
|
UUID
|
|
required |
canvas_id
|
UUID
|
Mouse subscriptions are scoped to this canvas; its camera is held
still for the session (in 2D and 3D), without changing the camera
models' |
required |
data_store_id
|
UUID
|
Recorded on every |
required |
brush_value
|
int
|
|
1
|
brush_radius_voxels
|
float
|
|
2.0
|
history_depth
|
int
|
|
100
|
abort
abstractmethod
¶
End the session, discarding the session's paint.
What can be discarded depends on the controller: see the subclass
abort for its limits.
cellier.paint.SyncPaintController ¶
Bases: AbstractPaintController
Paint controller for LabelMemoryStore.
Directly and synchronously mutates the backing numpy array on every
brush application, then announces the write with
store.notify_changed("contents", regions=...); the controller
reslices every visual reading the store, so the display updates
immediately. Suitable for testing and in-memory annotation
workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cellier_controller
|
CellierController
|
|
required |
visual_id
|
UUID
|
|
required |
scene_id
|
UUID
|
|
required |
canvas_id
|
UUID
|
|
required |
data_store
|
LabelMemoryStore
|
The store whose |
required |
displayed_axes
|
tuple[int, int]
|
The two data-array axes currently displayed in 2D for the bound
canvas, in |
required |
brush_value
|
int
|
|
1
|
brush_radius_voxels
|
float
|
|
2.0
|
history_depth
|
int
|
|
100
|
abort ¶
Revert the undoable strokes by replaying the undo stack in reverse.
Only what the undo stack holds is reverted: it keeps the last
history_depth strokes, so older strokes stay painted. A stroke
that has not been released yet is not on the stack either, and also
stays painted.
cellier.paint.MultiscalePaintController ¶
Bases: AbstractPaintController
Paint controller for OME-Zarr / multiscale-zarr data stores.
Stages all writes in a tensorstore transaction (RAM-only) until the user commits or aborts the session, or an autosave flushes them (see autosave_interval_s). Visible feedback is provided by writing directly into the GPU paint cache; the shader composites paint over the base sample so painted voxels are visible immediately without a slicer round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cellier_controller
|
CellierController
|
|
required |
visual_id
|
UUID
|
|
required |
scene_id
|
UUID
|
|
required |
canvas_id
|
UUID
|
|
required |
data_store
|
Any
|
The store behind a |
required |
visual_block_size
|
int
|
Tile / brick side length used by the visual's render config.
Must match the |
required |
displayed_axes
|
tuple[int, ...]
|
The two data-array axes currently displayed in 2D for the bound
canvas, in |
required |
brush_value
|
int
|
|
1
|
brush_radius_voxels
|
float
|
|
2.0
|
history_depth
|
int
|
|
100
|
autosave_interval_s
|
float | None
|
If set, a |
None
|
last_autosave_time
property
¶
last_autosave_time: datetime | None
Datetime of the most recent autosave, or None if none yet.
abort ¶
Discard staged paint and clear the GPU paint textures.
Only paint staged since the last flush is discarded. With
autosave_interval_s set, each autosave writes the staged paint
to disk and starts a new transaction, so paint from before the most
recent autosave is already on disk and stays.
History¶
cellier.paint.ActiveStroke ¶
Accumulator that builds a PaintStrokeCommand during a drag.
record is called once per brush application. Successive calls
concatenate their voxel arrays. finalise constructs the
immutable PaintStrokeCommand. After finalise, no further
record calls are permitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visual_id
|
UUID
|
The painted visual. |
required |
data_store_id
|
UUID
|
The store the stroke writes to. |
required |
gesture_id
|
UUID or None
|
The gesture this stroke belongs to, if known. |
None
|
dtype
|
numpy dtype or None
|
The dtype the values are kept in; pass the store's, so undo writes
back exactly what was there (label ids above 2**24 do not survive
a float32 round trip). None keeps each |
None
|
record ¶
Append the voxels painted in one brush application.
finalise ¶
finalise() -> PaintStrokeCommand
Return the completed command. Do not call record after this.
Successive record calls during a drag often overlap. For each
unique voxel we keep the first old_values seen — that is
the true pre-stroke value. Without this dedup, an undo replays
stale "old" values captured after earlier in-stroke writes,
leaving residue. new_values are also taken from the first
occurrence (within one stroke they are constant anyway).
cellier.paint.CommandHistory ¶
Bounded deque of PaintStrokeCommand with undo/redo pointers.
Only the undo stack is bounded by max_depth; the redo stack is
unbounded because it is cleared by push before it can grow
indefinitely.
cellier.paint.PaintStrokeCommand
dataclass
¶
Immutable record of one completed brush stroke.
Attributes:
| Name | Type | Description |
|---|---|---|
visual_id |
UUID
|
|
data_store_id |
UUID
|
|
voxel_indices |
ndarray
|
Shape |
old_values |
ndarray
|
Shape |
new_values |
ndarray
|
Shape |
Write buffers & layers¶
cellier.paint.WriteBuffer ¶
Bases: Protocol
Protocol for staged voxel writes against a level-0 store.
Concrete implementations stage writes in RAM, allow read-your-writes visibility, and flush or discard atomically.
Implementations must be safe to call from the Qt main thread; the paint controller never invokes them from a background thread.
stage ¶
Stage a vector of point writes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_indices
|
ndarray
|
Shape |
required |
values
|
ndarray
|
Shape |
required |
read_staged ¶
Return the current values at the given voxel indices.
With read-your-writes semantics, this returns staged values for
voxels that have been written through stage, falling back to
the underlying store for unwritten voxels.
Returns shape (N,) in the underlying store's native dtype.
cellier.paint.TensorStoreWriteBuffer ¶
WriteBuffer backed by a tensorstore.Transaction.
Wraps a single TensorStore handle (typically the level-0 store of a
multiscale data store) in an isolated transaction. All writes are
coalesced in tensorstore's in-memory write buffer until commit
or abort is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
TensorStore
|
The tensorstore handle to paint against. This must be the level-0 store of the multiscale data store. |
required |
Notes
The transaction is created in isolated mode (the default) which
is what we want: paints are not visible outside the transaction
until commit.
After commit or abort the buffer is one-shot — calling
stage again will fail since the transaction has been finalised.
The paint controller wraps lifecycle management around this.
transaction
property
¶
The active transaction, or None after commit/abort.
transactional_store
property
¶
The store wrapped in this buffer's transaction (read-your-writes).
__init__ ¶
Construct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
TensorStore
|
Untransacted level-0 store handle. |
required |
transaction
|
Transaction | None
|
Optional pre-built transaction. When provided, the same
transaction can be shared with other consumers (e.g. the
data store's read path) so they observe staged writes.
When |
None
|
cellier.paint.WriteLayer ¶
Sparse in-memory tracker of dirty level-0 bricks for a paint session.
Records which bricks have been touched; the painted voxel data
itself lives in the WriteBuffer. N-dim agnostic — used
unchanged for 2-D and 3-D paint sessions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_store_id
|
UUID of the painted store. Recorded but unused by |
required | |
block_size
|
int
|
Side length of one level-0 brick in voxels. Must match the
|
required |
voxel_to_brick_key ¶
voxel_to_brick_key(voxel_idx: ndarray) -> BrickKey
Map a level-0 voxel index to its enclosing level-0 BrickKey.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_idx
|
ndarray
|
Shape |
required |
Returns:
| Type | Description |
|---|---|
BrickKey
|
|
cellier.paint.BrickKey ¶
Bases: NamedTuple
Identifier for a level-k brick by its grid coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
LOD level. |
required |
grid_coords
|
tuple[int, ...]
|
One grid index per spatial axis, in data-array axis order. Length matches the painted store's ndim (2 for 2-D, 3 for 3-D). |
required |