RayBundle

class pyvsim.Primitives.RayBundle[source]

This class represents an arbitrary number of light rays. The reason for having them wrapped in a single class is that it allows full vectorization of the raytracing procedure.

This class shall be used in a disposable fashion, as it is not possible to eliminate rays from it, etc.

Methods

append(initialVector, initialPosition=None, wavelength=5.32e-07)[source]

This method is used to append new rays in the bundle.

Parameters :

initialVector : numpy.ndarray \((N,3)\)

if N rays are given, each element is the initial vector for ray tracing of each ray

initialPosition : numpy.ndarray \((N,3)\)

if no parameter is passed, rays will depart from the origin of the bundle. Otherwise they will depart from the given points. If N points were given, a single common starting point can be given

wavelength : numpy.ndarray \((N)\)

the wavelength of the rays in meters (this changes the color and the behavior of the rays, if any dispersing element is present in the simulation

Notes

  • If the starting point is omitted, it will assume that the rays departs from the origin of the bundle
  • This method was not made to be efficient in a loop (there are many checks), so it should be used ideally only once to append all rays
  • This method destroys data that was already ray-traced, if any

Examples

  1. A single ray is inserted:
>>> bundle = RayBundle()
>>> bundle.append(np.array([1,0,0]), np.array([0,0,0]))
  1. Several rays are inserted, each with a starting point:
>>> bundle.append(np.array([[1,0,0],[1,0,0]]), 
...               np.array([[0,0,0],[0,0,1]]))
  1. Several rays are inserted, with a common starting point:
>>> bundle.append(np.array([[1,0,0],[0,1,0]], 
...               np.array([0,0,0]))
clear()[source]

Removes all rays and ray tracing data from the bundle.

clearData()[source]

This method removes all elements from the self.items list and the ray pathes

delete(n)[source]

This method is not implemented, and is present only to respect the Assembly interface. As deleting a single ray requires many matrix reshapings, it is better to clear all the data and redo the ray tracing.

Raises :NotImplementedError :
finalIntersections = None

A (N) matrix with references to the object at the last point of each ray. If no object is at this point, None is returned

initialVectors = None

A numpy.ndarray with the shape (N,3) with the starting vectors of the N rays in the bundle

maximumRayTrace = None

Defines the maximum ray length during ray tracing

preAllocatedSteps = None

Memory is pre allocated to increase ray tracing performance. The number of pre allocated steps is defined here. Reallocation is very expensive, so a wise definition of this parameter is needed

rayIntersections = None

Stores references to the objects that each ray intersects. This is a (M,N) pointer matrix. M is the number of allocated steps and N is the number of rays in the bundle

rayLastVectors = None

Stores in a (N,3) matrix the last vector of each ray. This is used as a transition matrix and also in the case where ray tracing is to be restarted

rayLength = None

A (N) matrix with the length of each ray, calculated from its origin. If the ray does not intersect anything at this step, the value None will be stored

rayPaths = None

The points followed by each ray. The ray path matrix is organized as a 3D matrix, with the first index being the simulation step, the second is the ray number and the third is the coordinate. So the shape is (M,N,3), with M the number of allocated steps, N the number of rays in the bundle and 3 as the number of spatial coodinates

rotateImplementation(angle, axis, pivotPoint)[source]

This method rotates the starting points and deletes all ray tracing data, because a rotation or a translation of light rays may completely change the light paths.

Parameters :

angle :

Angle : scalar (in radians)

axis : numpy.ndarray \((1, 3)\)

Vector around which the rotation occurs.

pivotPoint : numpy.ndarray \((1, 3)\)

Point in space around which the rotation occurs. If not given, rotates around origin.

startingPoints = None

A numpy.ndarray with the shape (N,3) with the starting points of the N rays in the bundle

stepRayTrace = None

Defines the maximum length of a segment of ray during the tracing procedure (should be kept as long as possible to save computational time unless a special purpose tracing is needed)

steps = None

The number of tracing steps executed to the moment

trace(tracingRule=1, restart=False)[source]

A method for starting ray tracing. The bundle must be included in the environment assembly where ray tracing will be done (the position, however, is not important)

Parameters :

tracingRule :

Either RayBundle.TRACING_FOV or RayBundle.TRACING_LASER_REFLECTION, this parameter tells if ray tracing should stop at opaque surfaces (this is the case when tracing to determine the field of view) or not (to trace for laser safety calculations)

Raises :

RuntimeError :

If the bundle is not inserted in an assembly, this error will be raised.

translateImplementation(translation)[source]

This method changes the rays starting points, and waits for clear data to delete all ray tracing related information.

Parameters :

translation : numpy.ndarray \((3)\)

A [dx, dy, dz] vector

wavelength = None

Defines the light wavelength of the rays. This is important in the cases where materials with chromatic dispersion are used

This Page