kaolin.render.camera.CameraIntrinsics

API

class kaolin.render.camera.CameraIntrinsics(width: int, height: int, params: Tensor, near: float, far: float)

Bases: ABC

as_dict()

Returns parameters necessary to instantiate same CameraInitrinsics as a dictionary that is writable to JSON or YAML.

Returns

dict

aspect_ratio() float

Returns the aspect ratio of the cameras held by this object.

classmethod cat(cameras: Sequence[CameraIntrinsics])

Concatenate multiple CameraIntrinsics’s.

Assumes all cameras use the same width, height, near and far planes.

Parameters

cameras (Sequence of CameraIntrinsics) – the cameras to concatenate.

Returns

The concatenated cameras as a single CameraIntrinsics.

Return type

(CameraIntrinsics)

clip_mask(depth: Tensor) BoolTensor

Creates a boolean mask for clipping depth values which fall out of the view frustum.

Parameters

depth (torch.Tensor) – depth values

Returns

a mask, marking whether depth values are within the view frustum or not, of same shape than depth.

Return type

(torch.BoolTensor)

cpu() CameraIntrinsics
cuda() CameraIntrinsics
property device: str

the torch device of parameters tensor

double() CameraIntrinsics
property dtype

the torch dtype of parameters tensor

property far: float
float() CameraIntrinsics
static from_dict(in_dict)

Constructs intrinsics from a simple dictionary, such as that returned from as_dict; uses registered subclasses to figure out which subclass to instantiate based on its registered_name.

Returns: CameraIntrinsics subclass instance.

gradient_mask(*args: Union[str, IntEnum]) Tensor

Creates a gradient mask, which allows to backpropagate only through params designated as trainable.

This function does not consider the requires_grad field when creating this mask.

Parameters

*args – A vararg list of the intrinsic params that should allow gradient flow. This function also supports conversion of params from their string names. (i.e: ‘focal_x’ will convert to PinholeParamsDefEnum.focal_x)

Example

>>> # equivalent to:   mask = intrinsics.gradient_mask(IntrinsicsParamsDefEnum.focal_x,
>>> #                                                  IntrinsicsParamsDefEnum.focal_y)
>>> mask = intrinsics.gradient_mask('focal_x', 'focal_y')
>>> intrinsics.params.register_hook(lambda grad: grad * mask.float())
>>> # intrinsics will now allow gradient flow only for PinholeParamsDefEnum.focal_x and
>>> # PinholeParamsDefEnum.focal_y.
half() CameraIntrinsics
property height: int
abstract property lens_type: str
named_params() List[Dict[str, float]]

Get a descriptive list of named parameters per camera.

Returns

The named parameters.

Return type

(list of dict)

property ndc_max: float
property ndc_min: float
property near: float
param_count() int
Returns

number of intrinsic parameters managed per camera

Return type

(int)

abstract classmethod param_types() Type[IntEnum]
Returns

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

Return type

(IntrinsicsParamsDefEnum)

parameters() Tensor

Returns: (torch.Tensor): the intrinsics parameters buffer

projection_matrix()
classmethod registered_name()
property requires_grad: bool

True if the current intrinsics object allows gradient flow

set_ndc_range(ndc_min, ndc_max)

Warning

This method is not implemented

to(*args, **kwargs) CameraIntrinsics

An instance of this object with the parameters tensor on the given device. If the specified device is the same as this object, this object will be returned. Otherwise a new object with a copy of the parameters tensor on the requested device will be created.

See also

torch.Tensor.to()

abstract transform(vectors: Tensor) Tensor

Projects the vectors from view space / camera space to NDC (normalized device coordinates) space. The NDC space used by kaolin is a left-handed coordinate system which uses OpenGL conventions:

Y      Z
^    /
|  /
|---------> X

The coordinates returned by this class are not concerned with clipping, and therefore the range of values returned by this transformation is not numerically bounded between \([-1, 1]\).

To support a wide range of lens, this function is compatible with both linaer or non-linear transformations (which are not representable by matrices). CameraIntrinsics subclasses should always implement this method using pytorch differential operations.

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)

viewport_matrix(vl=0, vr=None, vb=0, vt=None, min_depth=0.0, max_depth=1.0) Tensor

Constructs a viewport matrix which transforms coordinates from NDC space to pixel space. This is the general matrix form of glViewport, familiar from OpenGL.

NDC coordinates are expected to be in: * [-1, 1] for the (x,y) coordinates. * [ndc_min, ndc_max] for the (z) coordinate.

Pixel coordinates are in: * [vl, vr] for the (x) coordinate. * [vb, vt] for the (y) coordinate. * [0, 1] for the (z) coordinate (yielding normalized depth).

When used in conjunction with a projection_matrix(), a transformation from camera view space to window space can be obtained.

Note that for the purpose of rendering with OpenGL shaders, this matrix is not required, as viewport transformation is already applied by the hardware.

By default, this matrix assumes the NDC screen spaces have the y axis pointing up. Under this assumption, and a [-1, 1] NDC space, the default values of this method are compatible with OpenGL glViewport.

See also

glViewport() at https://registry.khronos.org/OpenGL-Refpages/gl4/html/glViewport.xhtml and https://en.wikibooks.org/wiki/GLSL_Programming/Vertex_Transformations#Viewport_Transformation

projection_matrix() which converts coordinates from camera view space to NDC space.

Note

  1. This matrix changes form depending on the NDC space used.

  2. Returned values are floating points, rather than integers (thus this method is compatible with antialising ops).

Parameters
  • vl (int) – Viewport left (pixel coordinates x) - where the viewport starts. Default is 0.

  • vr (int) – Viewport right (pixel coordinates x) - where the viewport ends. Default is camera width.

  • vb (int) – Viewport bottom (pixel coordinates y) - where the viewport starts. Default is 0.

  • vt (int) – Viewport top (pixel coordinates y) - where the viewport ends. Default is camera height.

  • min_depth (float) – Minimum of output depth range. Default is 0.0.

  • max (float) – Maximum of output depth range. Default is 1.0.

Returns

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

Return type

(torch.Tensor)

property width: int
abstract zoom(amount)

Applies a zoom on the camera by adjusting the lens.

Parameters

amount – Amount of adjustment