Rays

giant.ray_tracer.rays:

class giant.ray_tracer.rays.Rays(start, direction, ignore=None)[source]

A class to store/manipulate rays.

In GIANT a ray is defined by a start and a direction (and optionally a list of ids to ignore when tracing a ray through a scene/to a shape. In addition, given these inputs, this class automatically computes the inverse direction (1/direction) which is used when intersecting the rays with an axis aligned bounding box.

When creating rays, if you are creating multiple rays that share the same start or the same direction you should input these as a single array of length 3 (not 3x1). This will allow us to use numpy broadcasting rules to efficiently represent the rays without having to duplicate memory. In addition, you can update the start/direction of the rays by using the rotate() and translate() methods, or by setting to the start and direction directly.

To use the ignore attribute of the rays you need to encode the full id of whatever you are trying to ignore. This can be very tricky and depends on what your tracing the rays against. For instance, if you are directly tracing the rays with a RawSurface like a Triangle64 then the id is simply the facet number (row number in the RawSurface.facets array). If you are tracing with a Solid, then the id is the Solid.id. If you are tracing with a KDTree then the id needs to be a combination of the ids of the path through the tree to the leaf node containing the facet, plus the row number for the facet in the KDNode.surface of the leaf node (this can conveniently be determined using get_ignore_inds()). If you are tracing with a scene, then you need to take the id of the geometry combined with index of the scene object in the Scene.target_objs list. All of these get combined into a single integer. Given this, it is rare to set the ignore attribute yourself. Instead, typically you either let GIANT set the attribute for you automatically, or you get the value from a previous trace (the facet component of INTERSECT_DTYPE will fully encode the id for whatever you traced through).

This class supports iterating through rays one at a time using the normal python syntax (for ray in rays: ...). That being said, this is not super efficient and is not the way GIANT handles multiple rays internally. You can also use indexing on the Rays object, which will return another Rays object. This can be useful for things like boolean indexing and slicing.

Parameters:
  • start (Sequence | ndarray) – Where the rays begin at as a length 3 array or a 3xn array

  • direction (Sequence | ndarray) – The direction that the rays proceed in as a length 3 array or a 3xn array (typically this should be unit vectors)

  • ignore (Sequence | ndarray | None) – The ids to ignore when tracing the rays. This should be either None for no ignores, a length n array for a single ignore per ray (set to -1 for rays where you don’t want any ignores), or a length n Sequence of arrays (where there are multiple (possibly different numbers) ignores for each ray)

property start: ndarray

The beginning location(s) of the ray(s) as an 3xn array of start locations (if n==1 then a flat 3 component array is returned).

If there are multiple directions and only a single start then this will still return a 3xn array but will use numpy broadcasting so that memory is not duplicated.

property direction: ndarray

The direction vector(s) of the ray(s) as an 3xn array of vector(s) (if n==1 then a flat 3 component array is returned).

If there are multiple starts and only a single direction then this will still return a 3xn array but will use numpy broadcasting so that memory is not duplicated.

property inv_direction: ndarray

The inverse of the direction vectors (1/directions) as a 3xn array (if n==1 then a flat 3 component array is returned).

If there are multiple starts and only a single direction then this will still return a 3xn array but will use numpy broadcasting so that memory is not duplicated.

property ignore: Sequence | ndarray | None

An array of the full ids of whatever you are trying to ignore for specific rays or None.

This is generally used when illuminating a scene as a way to ignore the surface that a ray starts at. See the class documentation for more details on how this mush be set.

Summary of Methods

rotate

Rotates the start location(s) and the direction(s) of the ray(s) in place.

translate

Translates the start location(s) of the ray(s) in place.