s6.rendering package¶
Submodules¶
s6.rendering.test_visuals module¶
s6.rendering.visuals module¶
3D/2D scene visuals and helpers built on VisPy.
This module provides small, composable scene graph nodes for common visualizations used in Sense Core:
Image planes, 3D polylines, and point markers
Camera frustums and simple camera widgets
Loading and orienting triangle meshes from external files
A lightweight binding system (
VisualTree) to connect visuals to values in an application context
Most visuals subclass vispy.scene.Node and implement
set_data(...) to update their state from conveniently-typed inputs
(s6.schema.Vector3D, NumPy arrays, dictionaries). Camera-related
utilities rely on intrinsic/extrinsic parameters compatible with
s6.vision.camera.
- class s6.rendering.visuals.Camera3D(transform_matrix, intrinsic_matrix, distortion_coeffs, resolution, near: float = 0.05, far: float = 0.45, color='blue', parent=None)¶
Bases:
VisualTreeElementSimple camera widget rendering a frustum and marker at the origin.
- unproject_points(points)¶
Unproject 2D pixel points to a plane at
fardepth.- Parameters:
points (ndarray, shape (N, 2)) – Pixel coordinates. Distortion is removed using the provided coefficients.
- Returns:
3D points lying on the plane
z = farin camera space.- Return type:
ndarray, shape (N, 3)
- update_transform(transform_matrix: ndarray)¶
Update the transform of the frustum from a 4x4 matrix.
- class s6.rendering.visuals.ExternalMeshVisual(file='cad.obj', parent=None)¶
Bases:
NodeLoad and display a mesh from a file with fixed transform and styling.
- class s6.rendering.visuals.Frustum(intrinsic_matrix: ndarray, distortion_coeffs: ndarray, resolution: tuple, near=0.01, far=1, color='blue', parent=None)¶
Bases:
VisualTreeElementStatic frustum wireframe visual constructed at init time.
- static create_frustum(intrinsic_matrix, distortion_coeffs, resolution, near=0.1, far=2.0)¶
Compute frustum vertices and connectivity for given camera intrinsics.
- class s6.rendering.visuals.Frustum3D(near: float = 0.05, far: float = 0.35, color='blue', *, parent=None)¶
Bases:
VisualTreeElementFrustum wireframe visual with adjustable near/far planes.
- static create_frustum(intrinsic_matrix, distortion_coeffs, resolution, near=0.1, far=2.0)¶
Compute frustum vertices/edges for camera intrinsics and depth range.
- Returns:
vertices (ndarray, shape (9, 3)) – Camera origin + 4 near-plane corners + 4 far-plane corners.
lines (ndarray, shape (M, 2)) – Indices of line segments forming the wireframe.
- set_data(value: Dict[str, Any])¶
Update the frustum from a mapping with extrinsic/intrinsic params.
Expected keys:
extrinsic,intrinsic,distortion,resolution.
- update_transform(transform_matrix: ndarray)¶
Set world transform from a 4x4 matrix (row-major).
- class s6.rendering.visuals.FrustumData(*, extrinsic: List[List[float]], intrinsic: List[List[float]], distortion: List[float], resolution: Tuple[int, int])¶
Bases:
BaseModelCamera parameters for rendering a frustum.
- extrinsic¶
4x4 world-to-camera matrix.
- Type:
list[list[float]]
- intrinsic¶
3x3 intrinsic matrix
K.- Type:
list[list[float]]
- distortion¶
OpenCV distortion coefficients.
- Type:
list[float]
- resolution¶
Image resolution
(width, height)in pixels.- Type:
(int, int)
- distortion: List[float]¶
- extrinsic: List[List[float]]¶
- intrinsic: List[List[float]]¶
- resolution: Tuple[int, int]¶
- class s6.rendering.visuals.Image(*, parent=None)¶
Bases:
VisualTreeElementImage plane visual for 2D arrays.
Notes
The image is vertically flipped on assignment to account for VisPy’s coordinate convention.
- set_data(value: ndarray)¶
Set the image data from an
(H, W[, C])NumPy array.
- class s6.rendering.visuals.Line3D(color='yellow', *, parent=None, **kwargs)¶
Bases:
VisualTreeElement3D line strip visual from a sequence of points.
- class s6.rendering.visuals.LineData(*, points: List[Vector3D])¶
Bases:
BaseModelPolyline container of 3D points.
- class s6.rendering.visuals.Marker3D(radius=0.0035, color='white', parent=None)¶
Bases:
VisualTreeElementSolid sphere marker at a 3D position.
- class s6.rendering.visuals.Mesh3D(file: str, tip_vertex: int, parent=None)¶
Bases:
VisualTreeElementMesh visual loaded from an OBJ file.
- Parameters:
file (str) – Path to an OBJ file. All meshes in the scene are concatenated.
tip_vertex (int) – Index of a representative tip vertex used to auto-orient the mesh when a target direction is provided.
parent (vispy.scene.Node, optional) – Parent node in the scene graph.
- class s6.rendering.visuals.ProjectionHelper¶
Bases:
objectConvenience functions for camera distortion/undistortion.
- static distort_points(norm_points, camera_matrix, distortion_coeffs)¶
Apply lens distortion to normalized image points.
- Parameters:
norm_points (ndarray, shape (N, 2)) – Normalized pixel coordinates.
camera_matrix (ndarray, shape (3, 3)) – Intrinsic matrix
K.distortion_coeffs (ndarray) – Distortion coefficients in OpenCV format.
- Returns:
Distorted pixel coordinates.
- Return type:
ndarray, shape (N, 2)
- static undistort_points(distorted_points, camera_matrix, distortion_coeffs)¶
Remove lens distortion from pixel coordinates.
- Parameters:
distorted_points (ndarray, shape (N, 2)) – Distorted pixel coordinates.
camera_matrix (ndarray, shape (3, 3)) – Intrinsic matrix
K.distortion_coeffs (ndarray) – Distortion coefficients in OpenCV format.
- Returns:
Undistorted pixel coordinates.
- Return type:
ndarray, shape (N, 2)
- class s6.rendering.visuals.VisualTree¶
Bases:
objectBind context keys to visuals with optional transforms.
The tree maps one or more dotted keys to a list of
(visual, func)pairs. Duringupdate(), the first existing key supplies a value, which is optionally transformed byfuncand passed toVisualTreeElement.set_data().- bind(visual: VisualTreeElement, keys: str | List[str], bind_lambda: Callable[[Any], Any] | None = None)¶
Bind a visual to one or more context keys.
- Parameters:
visual (VisualTreeElement) – Target visual to receive updates.
keys (str or list of str) – Dotted key(s) to look up in the context (first found wins).
bind_lambda (callable, optional) – Transform
value -> valuebefore passing toset_data.
- update(context)¶
Update all bound visuals from a context mapping.
Chooses the first available key for each binding, optionally applies its transform, then calls
visual.set_data(value).
- class s6.rendering.visuals.VisualTreeElement(*, parent=None)¶
Bases:
Node,ABCBase scene node with a simple data-binding contract.
Subclasses implement
set_data()to update their visual state from a bound value. Instances can be registered withVisualTree.- abstractmethod set_data(value)¶
Update the visual based on a bound value.
- s6.rendering.visuals.query(value, parts)¶
Traverse nested mappings/lists using a list of keys.
- Parameters:
value (Any) – Root object (typically a nested dict/list context).
parts (list of str) – Sequence of keys or indices forming a path, e.g.,
["camera", "0", "K"].
- Returns:
The value at the path, or
Noneif any segment is missing.- Return type:
Any | None