kaolin.render.camera.OrthographicIntrinsics

API

class kaolin.render.camera.OrthographicIntrinsics(width, height, params, near=0.01, far=100.0)

Bases: CameraIntrinsics

Holds the intrinsics parameters of a theoretical orthographic camera: how it should project from camera space to normalized screen / clip space. This is the most simplistic form of a camera projection model which does not distort objects at the distance.

See documentation of CameraIntrinsics for numerous ways of how to use this class.

The orthographic camera explicitly exposes the orthographic transformation matrix. This may typically be useful for rasterization based rendering pipelines (i.e: OpenGL).

In general, intrinsic classes keep a batched tensor of parameters. However, for orthographic projections there are no parameters to keep, and therefore the params tensor is empty.

The matrix returned by this class supports differentiable torch operations.

Parameters
DEFAULT_FAR = 100.0
DEFAULT_NEAR = 0.01
property fov_distance: FloatTensor
classmethod from_frustum(width, height, fov_distance=1.0, near=0.01, far=100.0, num_cameras=1, device=None, dtype=torch.float32)

Constructs a new instance of OrthographicIntrinsics from view frustum dimensions

fov_distance artificially defines the “zoom scale” of the view.

Parameters
  • width (int) – width of the camera resolution

  • height (int) – height of the camera resolution

  • fov_distance (optiona, float) – the field of view distance. Default: 1.0

  • near (optional, float) – near clipping plane, define the min depth of the view frustrum or to normalize the depth values. Default: 1e-2

  • far (optional, float) – far clipping plane, define the max depth of teh view frustrum or to normalize the depth values. Default: 1e2

  • num_cameras (optional, int) – the numbers of camera in this object. Default: 1

  • device (optional, str) – the device on which parameters will be allocated. Default: cpu

  • dtype (optional, str) – the dtype on which parameters will be alloacted. Default: torch.float

Returns

the constructed orthographic camera intrinsics

Return type

(OrthographicIntrinsics)

property lens_type: str
normalize_depth(depth)

Normalizes depth values to the NDC space defined by the view frustum.

Parameters

depth (torch.Tensor) – the depths to be normalized, of shape \((\text{num_depths},)\) or \((\text{num_cameras}, \text{num_depths})\)

Returns

The normalized depth values to the ndc range defined by the projection matrix, of shape \((\text{num_cameras}, \text{num_depths})\)

Return type

(torch.Tensor)

orthographic_matrix(left, right, bottom, top, near, far)

Constructs a matrix which normalizes a cuboid-shaped view-frustum to normalized device coordinates (NDC). Orthographic projections do not consider perspectives. This method is similar in behaviour to the now deprecated OpenGL function glOrtho().

Input values are determined by the screen dimensions and intrinsic coordinate conventions, for example:

  1. \((\text{left}=0, \text{right}=\text{width}, \text{bottom}=\text{height}, \text{top}=0)\) for origin at top-left of the screen, y axis pointing downwards

  2. \((\text{left}=-\dfrac{\text{width}}{2}, \text{right}=\dfrac{\text{width}}{2}, \text{bottom}=-\dfrac{\text{height}}{2}, \text{top}=\dfrac{\text{height}}{2})\) for origin at center of the screen, and y axis pointing upwards.

Parameters
  • left (float) – location of the left face of the view-frustum.

  • right (float) – location of the right face of the view-frustum.

  • bottom (float) – location of the bottom face of the view-frustum.

  • top (float) – location of the top face of the view-frustum.

  • near (float) – location of the near face of the view-frustum. Should always be larger than zero and smaller than the far clipping plane. If used in conjunction with a perspective matrix, the near clipping plane should be identical for both.

  • far (float) – location of the near face of the view-frustum. Should always be larger than the near clipping plane. If used in conjunction with a perspective matrix, the far clipping plane should be identical for both.

Returns

the orthographic matrix, of shape \((1, 4, 4)\).

Return type

(torch.Tensor)

classmethod param_types()
Returns

an enum describing each of the intrinsic parameters managed by the orthographic camera. This enum also defines the order in which values are kept within the params buffer.

Return type

(IntrinsicsParamsDefEnum)

projection_matrix()

Creates an OpenGL compatible orthographic projection matrix to NDC coordinates.

Returns

the projection matrix, of shape \((\text{num_cameras}, 4, 4)\)

Return type

(torch.Tensor)

transform(vectors)

Apply perspective projection to NDC coordinates.

Assumptions:

  • Camera is looking down the negative z axis (that is: Z axis points outwards from screen, OpenGL compatible).

  • Practitioners are advised to keep near-far gap as narrow as possible, to avoid inherent depth precision errors.

Parameters

vectors (torch.Tensor) – the vectors to be transformed, can homogeneous of shape \((\text{num_vectors}, 4)\) or \((\text{num_cameras}, \text{num_vectors}, 4)\) or non-homogeneous of shape \((\text{num_vectors}, 3)\) or \((\text{num_cameras}, \text{num_vectors}, 3)\)

Returns

the transformed vectors, of same shape than vectors but last dim 3

Return type

(torch.Tensor)

zoom(amount)

Applies a zoom on the camera by adjusting the lens.

Parameters

amount – Amount of adjustment