diffrp.rendering.camera#

class diffrp.rendering.camera.Camera#

Bases: object

Abstract class for camera specification.

You need to implement the V(), P() and resolution() methods if you inherit from the class.

P()#
Returns:

GPU tensor of shape (4, 4). GL projection matrix.

Return type:

torch.Tensor

V()#
Returns:

GPU tensor of shape (4, 4). GL view matrix.
Inverse of the c2w or camera pose transform matrix.
You may need to convert the camera poses if the pose is not in GL convention (X right, Y up, -Z forward). You may use calibur for this.
It should be an affine transform matrix with the last row fixed to [0, 0, 0, 1]. It is also often called an extrinsic matrix or w2c matrix in other conventions.

Return type:

torch.Tensor

__init__() None#
resolution()#
Returns:

Resolution in (h, w) order.

Return type:

Tuple[int, int]

class diffrp.rendering.camera.PerspectiveCamera(fov=30, h=512, w=512, near=0.1, far=10.0)#

Bases: Camera

Perspective camera class. Angles are in degrees.

P()#
Returns:

GPU tensor of shape (4, 4). GL projection matrix.

Return type:

torch.Tensor

__init__(fov=30, h=512, w=512, near=0.1, far=10.0) None#
classmethod from_orbit(h, w, radius, azim, elev, origin, fov=30, near=0.1, far=10.0)#

Create a perspective camera from an orbital camera.

Parameters:
  • h (int) – Height.

  • w (int) – Width.

  • radius (float) – Distance to focus origin.

  • azim (float) – Azimuth angle in degrees relative to focus origin. +Z is 0 degree.

  • elev (float) – Elevation angle in degrees relative to focus origin. -90 is down-up and 90 is up-down. Note that -90 and 90 are extreme values where azimuth is undefined, so use values like 89.999 in these cases instead.

  • origin (List[float]) – List of 3 floats, focus point of the camera.

  • fov (float) – Vertical Field of View in degrees.

  • near (float) – Camera near plane distance.

  • far (float) – Camera far plane distance.

lookat(point: List[int] | ndarray)#
resolution()#
Returns:

Resolution in (h, w) order.

Return type:

Tuple[int, int]

set_transform(tr: ndarray)#
class diffrp.rendering.camera.RawCamera(h: int, w: int, v: Tensor, p: Tensor)#

Bases: Camera

Raw data-driven camera that takes GPU tensors of the view and projection matrices to drive the camera.

P()#
Returns:

GPU tensor of shape (4, 4). GL projection matrix.

Return type:

torch.Tensor

V()#
Returns:

GPU tensor of shape (4, 4). GL view matrix.
Inverse of the c2w or camera pose transform matrix.
You may need to convert the camera poses if the pose is not in GL convention (X right, Y up, -Z forward). You may use calibur for this.
It should be an affine transform matrix with the last row fixed to [0, 0, 0, 1]. It is also often called an extrinsic matrix or w2c matrix in other conventions.

Return type:

torch.Tensor

__init__(h: int, w: int, v: Tensor, p: Tensor) None#
resolution()#
Returns:

Resolution in (h, w) order.

Return type:

Tuple[int, int]