Cameras

class yt_idv.cameras.base_camera.BaseCamera(*args: t.Any, **kwargs: t.Any)[source]

Bases: HasTraits

Camera object used in the Interactive Data Visualization

Parameters:
  • position (iterable, or 3 element array in code_length) – The initial position of the camera.

  • focus (iterable, or 3 element array in code_length) – A point in space that the camera is looking at.

  • up (iterable, or 3 element array in code_length) – The ‘up’ direction for the camera.

  • fov (float, optional) – An angle defining field of view in degrees. For an orthographic projection, this sets the half-height of the view volume to tan(fov/2) * |position - focus|, matching the perspective frustum’s extent at the focal plane.

  • near_plane (float, optional) – The distance to the near plane of the perspective camera.

  • far_plane (float, optional) – The distance to the far plane of the perspective camera.

  • aspect_ratio (float, optional) – The ratio between the height and the width of the camera’s fov.

  • projection_type (str, optional) – The projection used to map 3D space onto the image plane, either “perspective” (default, rays diverge from the camera position), “orthographic” (parallel rays along the view direction) or “ray_table” (a ray direction per pixel from ray_table, for panoramic and other non-linear lenses).

  • ray_table (array, optional) – For the “ray_table” projection, a (height, width, 3) array of camera-space ray directions (the camera looks down -z with +y up), row 0 at the bottom, zero where a pixel has no ray; see yt_idv.cameras.ray_table. Depth is the distance from the ray’s origin over far_plane.

  • ray_origins (array, optional) – For the “ray_table” projection, each ray’s origin as an offset from position in camera space, times ray_origin_scale, shaped like ray_table (e.g. per-column eye positions for omnidirectional stereo). By default every ray starts at position.

  • ray_origin_scale (float, optional) – Scales ray_origins into model units, so a fixed table can follow a changing scale.

aspect_ratio

A float trait.

bind_ray_table(ray_target, tile_target, origin_target)[source]

Bind the ray table, its tile cones and its origins, if this camera uses them.

compute_matrices
dict()[source]
far_plane

A float trait.

focus
fov

A float trait.

held

A boolean (True, False) trait.

hold_traits(func)[source]

Suppress per-trait matrix rebuilds inside the block, then call func once.

near_plane

A float trait.

orientation

A numpy array trait type.

pan(dx, dy)[source]

Pan the camera by a given amount in normalized device coordinates.

position
projection_matrix

A numpy array trait type.

projection_type

An enum of strings where the case should be ignored.

ray_origin_scale

A float trait.

ray_origins

A numpy array trait type.

ray_table

A numpy array trait type.

scroll_delta

A float trait.

set_orientation(orientation)[source]

Set the orientation quaternion and re-derive position, up and the view.

The camera keeps its focus and its distance from the focus; position and up are rotated to match the new orientation.

up

A numpy array trait type.

update(position=None, focus=None, up=None, fov=None, near_plane=None, far_plane=None, aspect_ratio=None, projection_type=None)[source]

Set several traits at once, then rebuild the view and projection.

Traits left as None are untouched. The view matrix is rebuilt from position, focus and up and the orientation quaternion is re-derived from it (see update_matrices). To set the orientation directly, use set_orientation instead.

update_from_dict(cdict)[source]

Restore the camera from a snapshot produced by dict().

The orientation entry is dropped: it is derived from position, focus and up, and update re-derives it.

update_matrices()[source]

Rebuild the view matrix from position, focus and up, then the projection.

Call this after setting position, focus or up directly. The orientation quaternion is re-derived from the new view matrix.

update_orientation(start_x, start_y, end_x, end_y)[source]

Change camera orientation matrix using delta of mouse’s cursor position

Parameters:
  • start_x (float) – initial cursor position in x direction

  • start_y (float) – initial cursor position in y direction

  • end_x (float) – final cursor position in x direction

  • end_y (float) – final cursor position in y direction

view_matrix

A numpy array trait type.

Per-pixel ray directions for the "ray_table" projection.

A ray table is a (height, width, 3) float32 array of ray directions in camera space (OpenGL convention: the camera looks down -z, +y is up, +x is right), one per pixel, row 0 at the bottom of the image. A zero vector marks a pixel with no ray. Any lens (equirectangular, fisheye, or one measured from another renderer) can be supplied this way.

yt_idv.cameras.ray_table.equirectangular_rays(width_px, height_px)[source]

Rays of a full equirectangular panorama.

Longitude runs from -180 degrees at the left edge to +180 at the right, with the view direction at the center; latitude runs from -90 at the bottom to +90.

yt_idv.cameras.ray_table.fisheye_rays(width_px, height_px, fov=180.0)[source]

Rays of an equidistant fisheye whose image circle fills the shorter side.

fov is the full field of view across the circle, in degrees; pixels outside the circle have no ray.

yt_idv.cameras.ray_table.tile_bounds(n_pixels, n_tiles)[source]

Pixel boundaries of n_tiles tiles, split as grid_expand.geom.glsl does.

yt_idv.cameras.ray_table.tile_cones(rays, tile_pixels=32)[source]

Bounding cones of a ray table’s screen tiles.

Accepts a rays that is (height, width, 3) where the third dimension is x’, y’, z’. Returns a (n_tiles_y, n_tiles_x, 4) float32 array of (unit axis, half-angle in radians), with a half-angle of -1 for tiles with no rays. At most MAX_TILES tiles are used along each axis.