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) or “orthographic” (parallel rays along the view direction).

aspect_ratio

A float trait.

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.

position
projection_matrix

A numpy array trait type.

projection_type

An enum of strings where the case should be ignored.

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.