CompactRays

class raytracing.compact.CompactRays(compactRaysStructuredBuffer=None, maxCount=None, rays=None)

Bases: Rays

A contiguous buffer holding many rays, ready for GPU transfer.

Where a regular Rays is a Python list of independent Ray objects, CompactRays stores all ray data in a single numpy structured array so that the memory can be sent to an OpenCL or CUDA device in one call.

Individual rays are accessed with compact_rays[i], which returns a CompactRay view — not a copy. Modifying the view modifies the buffer.

Three construction modes are supported:

  1. From an existing buffer (compactRaysStructuredBuffer) — wraps raw bytes, typically received back from the GPU after computation.

  2. From a count (maxCount) — allocates a zero-filled buffer of the requested size, to be filled later.

  3. From a list of ``Ray`` objects (rays) — allocates a buffer and copies each ray into it, converting from Python objects to the compact layout.

Parameters:
  • compactRaysStructuredBuffer (buffer, optional) – A pre-existing contiguous buffer of CompactRay.Struct data.

  • maxCount (int, optional) – Number of ray slots to allocate (zero-filled).

  • rays (list of Ray, optional) – Regular Ray objects to convert into the compact layout.

Raises:

ValueError – If none of the three construction arguments is provided.

See also

CompactRay

A view into one slot of this buffer.

append(tuple)

A ray can be appended to the List of the rays using this function.

Parameters:

ray (object of ray class) – a ray with height y and angle theta

fillWithRandomUniform(yMax=1.0, yMin=None, thetaMax=1.5707963267948966, thetaMin=None)

Fill the buffer with rays at random heights and angles.

Each ray receives a uniformly distributed height in [yMin, yMax] and angle in [thetaMin, thetaMax]. If the minimum values are not given, symmetric ranges around zero are used.

Parameters:
  • yMax (float) – Maximum height. (Default=1.0)

  • yMin (float, optional) – Minimum height. Defaults to -yMax.

  • thetaMax (float) – Maximum angle in radians. (Default=pi/2)

  • thetaMin (float, optional) – Minimum angle in radians. Defaults to -thetaMax.

property thetaValues

Returns the angles of rays in the list.

property yValues

Returns the heights of rays in the list.

Methods

__init__([compactRaysStructuredBuffer, ...])

append(tuple)

A ray can be appended to the List of the rays using this function.

fillWithRandomUniform([yMax, yMin, ...])

Fill the buffer with rays at random heights and angles.

Inherited Methods

display([title, showTheta])

This function plots the intensity profiles of a list of rays.

displayProgress()

This function prints the progress of the iterations

load(filePath[, append])

A list of rays can be loaded using this function.

rayAnglesHistogram([binCount, minValue, ...])

This functions calculates the histogram for the angle of the rays.

rayCountHistogram([binCount, minValue, maxValue])

This functions calculates the histogram for the height of the rays.

save(filePath)

A list of rays can be saved using this function.

Attributes

count

Returns the number of rays in the list.

rays

thetaValues

Returns the angles of rays in the list.

yValues

Returns the heights of rays in the list.