Camera

Cameras produce the initial ray from the camera position through the currently rendered pixel and into the scene.

class padvinder.camera.Camera(position=(0, 0, 0), up=(0, 1, 0), look_at=(0, 0, 1))[source]

Bases: object

This Camera Model sets up and contains an orthonormal coordinate system. The cameras position is the starting positon of all rays fired into the scene. The rays through the center of the image will pass through the look_at point. Position and look_at define the optical axis. The up vector provides a vague upwards direction helping to orient the camera.

Parameters:
  • position (numpy.ndarray_like) – the position of the camera in the scene, origin of the fired rays
  • up (numpy.ndarray_like) – the general upwards direction of the camera
  • look_at (numpy.ndarray_like) – the position in the scene that the camera will look at
Raises:

ValueError – if any of position, up or look_at contain Infs or NaNs or if the position and look_at are at the same point

Examples

>>> Camera()
>>> Camera((0,0,0), (0,1,0), (0,0,-1), 35)
Camera(position=[0.0, 0.0, -1.0],
       up=[0.0, 1.0, 0.0],
       look_at=[0.0, 0.0, 0.0])
position

Return the position of the camera.

up

Return the up vector of the camera.

optical_axis

Return the optical axis of the camera.

ray(pixel, resolutions, rand=True)[source]

Given the pixel and the camera resolution, returns a ray that originates at the camera position and passes through the pixel. If rand is set true, a little random offset (smaller than the distance between two pixels is added to the pixel position. This will together with multiple samples per pixel mitigate aliasing.

Parameters:
  • pixel (numpy.ndarray_like) – (x, y) coordinates of the pixel in the image - numpy style. Aka (0, 0) is the upper left hand corner and the x values are iterating downwards while y is iterating horizontally. x must be in the intervall of [0, dimension[0]] and y must be in [0, dimension[1]] The pixel [0,0] is the upper lefthand corner and the pixel [res_x, rex_y] is the lower righthand corner.
  • resolutions (numpy.ndarray_like) – (res_x, resx_y) the resolution of the camera in x and y.
  • rand (boolean) – When False, every ray passes through the exact center of the pixel. When True a random offset smaller than the distance between two pixels is added the the pixel center. The ray then passes through the perturbed pixel center.
Returns:

ray – with the position being the camera position and direction being a vector that starts at the position and passes through the (potentiall offsetted) given pixel

Return type:

Ray

Raises:

NotImplemeted – because this is an abstract base class

Examples

>>> camera = PerspectiveCamera()
>>> camera.ray((0,0), (100, 100), False)
class padvinder.camera.PerspectiveCamera(position=(0, 0, 0), up=(0, 1, 0), look_at=(0, 0, 1), focal_length=24)[source]

Bases: padvinder.camera.Camera

The Perspective Camera Model extends the orthonormal coordinate system with a focal length and therefore a concrete image plane. The cameras position is the starting positon of all rays fired into the scene. The rays through the center of the image will pass through the look_at point. Position and look_at define the optical axis. The up vector provides a vague upwards direction helping to orient the camera. The focal length defines how far the 35mm equivalent sized image plane is from the camera position.

Parameters:
  • position (numpy.ndarray_like) – the position of the camera in the scene, origin of the fired rays
  • up (numpy.ndarray_like) – the general upwards direction of the camera
  • look_at (numpy.ndarray_like) – the position in the scene that the camera will look at
  • focal_length (float) – the distance in mm between the position and the image plane - must be in the intervall of (0, +inf).
Raises:

ValueError – if any of position, up or look_at contain Infs or NaNs or if the position and look_at are at the same point of ir the focal_length is not positive

Examples

>>> PerspectiveCamera()
>>> PerspectiveCamera((0,0,1), (0,1,0), (0,0,0), 24)
Camera(position=[0.0, 0.0, 1.0],
       up=[0.0, 1.0, 0.0],
       look_at=[0.0, 0.0, 0.0],
       focal_length=24)
focal_length

Return the focal length of the camera.

ray(pixel, resolutions, rand=True)[source]

Given the pixel and the camera resolution, returns a ray that originates at the camera position and passes through the pixel. If rand is set true, a little random offset (smaller than the distance between two pixels is added to the pixel position. This will together with multiple samples per pixel mitigate aliasing.

Parameters:
  • pixel (numpy.ndarray_like of shape (2, )) – (x, y) coordinates of the pixel in the image. Numpy style: aka (0, 0) is the upper left hand corner and the x values are iterating downwards while y is iterating horizontally. x must be in the intervall of [0, dimension[0]] and y must be in [0, dimension[1]] The pixel [0,0] is the upper lefthand corner and the pixel [res_x, rex_y] is the lower righthand corner.
  • resolutions (numpy.ndarray_like of shape (2, )) – the resolution of the camera in x and y.
  • rand (boolean) – When False, every ray passes through the exact center of the pixel. When True a random offset smaller than the distance between two pixels is added the the pixel center. The ray then passes through the perturbed pixel center.
Returns:

ray – with the position being the camera position and direction being a vector that starts at the position and passes through the (potentiall offsetted) given pixel

Return type:

Ray

Examples

>>> camera = PerspectiveCamera()
>>> camera.ray((50, 50), (100, 100), False)
Ray(position=[0, 0, 0], direction=[0, 0, 1])