# Module RayTracing

# Meshes

# ** VPL.RayTracing.Triangle** —

*Method*.

`Triangle(p1, p2, p3)`

Create a ray tracing `Triangle`

object given the three vertices `p1`

, `p2`

and `p3`

.

# ** VPL.RayTracing.Triangle** —

*Method*.

`Triangle(mesh)`

Create a vector of ray tracing `Triangle`

objects from a `Mesh`

object.

# ** VPL.RayTracing.Triangle** —

*Method*.

`Triangle(mesh)`

Create a vector of ray tracing `Triangle`

objects from a `Scene`

object.

# RayTracer

# ** VPL.RayTracing.get_nw** —

*Function*.

`get_nw(s::Source)`

Retrieve the number of wavelengths that rays from a source will contain.

`get_nw(rt::RayTracer)`

Retrieve the number of wavelengths being simulated by the ray tracer. See VPL documentation for more details on the ray tracer.

# ** VPL.RayTracing.RTSettings** —

*Type*.

```
RTSettings(;parallel = false, pkill = 0.2, maxiter = 2, sampler = Random.Xoshiro(123456789),
= 3, ny = 3, nz = 0, dx = 0.0, dy = 0.0, dz = 0.0) nx
```

Settings for the ray tracer: `parallel`

indicates if the raytracer will run on a single core or make use of multiple cores in the machine based on Julia’s multithreading support. `pkill`

is the probably that a ray is terminated by the Russian roulette after it has been scattered a `maxiter`

number of times. `sampler`

is the pseudo-random number generator to be used by the ray tracer. `nx`

and `ny`

are the number of times the scene will be clone by the grid cloner in each direction along the x and y axis (e.g., setting `nx = 1`

and `ny = 1`

will generate a grid of 3 x 3 clones of the original scene), whereas `dx`

and `dy`

will be distance at which each new clone will be generated (along the axis). `nz`

is the number of times the scene will be cloned in the vertical direction. Unlike horizontal cloning, the vertical cloning is always done in the positive direction of `z`

axis and the number of clones will be exactly `nz`

. See VPL documentation for more details on the ray tracer.

# ** VPL.RayTracing.accelerate** —

*Function*.

`accelerate(scene::Scene; settings = RTSettings(), acceleration = Naive, rule = nothing)`

Create an `AccScene`

object from a scene, settings and acceleration function (choose from `Naive`

or `BVH`

). The argument `rule`

is only required for the accelerator `BVH`

and it must be an object of type `SAH`

or `AvgSplit`

(it is ignored for the `Naive`

accelerator). The `AccScene`

object contains the acceleration structure and the grid cloner structure built on top of the original 3D meshes in `scene`

. See VPL documentation for details.

# ** VPL.RayTracing.RayTracer** —

*Type*.

`RayTracer(scene, materials, sources, settings)`

Create a ray tracer object from an acceleration structure built around a 3D mesh, a grid cloner structure around the acceleration structure (`scene`

), a vector of materials associated to the mesh (`materials`

), a vector of sources of irradiance (`sources`

) and settings. (as generated by `RTSettings()`

). See VPL documentation for more details on the ray tracer.

# ** VPL.RayTracing.trace!** —

*Function*.

`trace!(rt)`

Run the ray tracing simulations. This function will overwrite the `power`

component of any material object that is included in the scene. It returns the total number of rays being traced (primary and secondary). See VPL documentation for more details on the ray tracer.

# Acceleration structures

# ** VPL.RayTracing.Naive** —

*Type*.

` Naive`

Allow to run the ray tracer without an acceleration structure. This should be assigned to the argument `acceleration`

in the `RayTracer`

function.

# ** VPL.RayTracing.BVH** —

*Type*.

` BVH`

Construct a Bounding Volume Hierarchy around the triangular meshes to accelerate the ray tracer. This should be assigned to the argument `acceleration`

in the `RayTracer`

function, in combination with a corresponding `rule`

.

# ** VPL.RayTracing.SAH** —

*Type*.

`SAH{K}(minN, maxL)`

Rule to be used in `RayTracer`

when `acceleration = BVH`

. It will divide each node at the axis and location using the Surface Area Heuristics. To speed up the construction, only `K`

cuts will be tested per axis. These cuts will correspond to the quantiles along each axis. The rule is parameterized by the minimum number of triangles in a leaf node (`minN`

) and the maximum depth of the tree (`maxL`

).

# ** VPL.RayTracing.AvgSplit** —

*Type*.

`AvgSplit(minN, maxL)`

Rule to be used in `RayTracer`

when `acceleration = BVH`

. It will divide each node along the longest axis through the mean coordinate value. The rule is parameterized by the minimum number of triangles in a leaf node (`minN`

) and the maximum depth of the tree (`maxL`

).

# Sources

# ** VPL.RayTracing.Source** —

*Type*.

```
Source(geom, angle, power::Number, nrays)
Source(geom, angle, power::Tuple, nrays)
```

Createn irradiance source given a source geometry, a source angle, the power per ray and the total number of rays to be generated from this source. When simulating more than one wavelength simultaneously, a tuple of power values should be given, of the same length as in the materials used in the scene. See VPL documentation for details on source geometries and source angles.

# ** VPL.RayTracing.DirectionalSource** —

*Function*.

```
DirectionalSource(box::AABB, θ, Φ, radiosity, nrays)
DirectionalSource(scene::Scene, θ, Φ, radiosity, nrays)
```

Create a Directional source (including geometry and angle components) by providing an axis-aligned bounding box (`box`

) or an `Scene`

object (`scene`

) as well as the zenith (`θ`

) and azimuth (`Φ`

) angles, the radiosity of the source and the number of rays to be generated. Directional sources may generate incorrect results in the absence of a grid cloner that extendes the scenes. This is because the rays are generated from the upper face of the scene’s bounding box. See VPL documentation for details on light sources.

# ** VPL.RayTracing.PointSource** —

*Type*.

`PointSource(vec)`

Create a point irradiance source geometry at given 3D location `vec`

, defined as vector of Cartesian coordinates (`Vec(x, y, z)`

).

# ** VPL.RayTracing.LineSource** —

*Type*.

`LineSource(p, line)`

Create a line irradiance source geometry given an origin (`p`

) and a segment (`line`

) both specified as vector of Cartesian coordinates (`Vec(x, y, z)`

). This will create a line source between the points `p`

and `p .+ line`

.

# ** VPL.RayTracing.AreaSource** —

*Type*.

`AreaSource(mesh)`

Create an area irradiance source geometry given a triangular mesh.

# ** VPL.RayTracing.LambertianSource** —

*Type*.

```
LambertianSource(x, y, z)
LambertianSource(axes)
```

Create a Lambertian irradiance source angle by given a local coordinate system as three separate `Vec`

objects representing the axes (x, y, z) or as tuple containing the three axes. Rays will be generated towards the hemisphere defined by the `z`

direction. See VPL documentation for details on irradiance sources.

# ** VPL.RayTracing.FixedSource** —

*Type*.

```
FixedSource(dir)
FixedSource(θ, Φ)
```

Create a fixed irradiance source by given a vector with the direction of the rays (dir) or zenith (θ) and azimuth (Φ) angles.

# Materials

# ** VPL.RayTracing.Sensor** —

*Type*.

`Sensor(nw::Int)`

Create a sensor material object to store power for `nw`

wavelengths. A sensor material will let rays pass through without altering the direction or irradiance. They will also not count for the total number of ray iterations.

# ** VPL.RayTracing.Black** —

*Type*.

`Black(nw::Int)`

Create a black material object to store power for `nw`

wavelengths. See VPL documentation for details.

# ** VPL.RayTracing.Lambertian** —

*Type*.

`Lambertian(;τ = 0.0, ρ = 0.0)`

Create a `Lambertian`

material object from the values of transmittance (`τ`

) and reflectance (`ρ`

). When more than one wavelength is being simulated, a tuple of values should be passed for each optical property (as in `τ = (0.1,0.2)`

).

# ** VPL.RayTracing.Phong** —

*Type*.

`Phong(;τ = 0.0, ρd = 0.0, ρsmax = 0.0, n = 2)`

Create a `Phong`

material object from the values of transmittance (`τ`

) diffuse reflectance (`ρd`

), maximum Phong specular reflectance (`ρsmax`

) and `n`

is the specular exponent that controls the “Phong reflectance lobe”. When more than one wavelength is being simulated, a tuple of values should be passed for each optical property (as in `τ = (0.1, 0.3)`

).

# ** VPL.RayTracing.power** —

*Function*.

`power(material::Material)`

Extract the power stored inside a material.

# ** VPL.RayTracing.reset!** —

*Method*.

`reset!(material::Material)`

Reset the power stored inside a material back to zero

# ** VPL.RayTracing.tau** —

*Function*.

`tau(vals...)`

Generate values of transmisivity to be used in material object. `vals...`

is a list of one or more comma separted values, corresponding to the different wavelengths/wavebands to be simulated in a ray tracer.

# ** VPL.RayTracing.rho** —

*Function*.

`rho(vals...)`

Generate values of reflectivity to be used in material object. `vals...`

is a list of one or more comma separted values, corresponding to the different wavelengths/wavebands to be simulated in a ray tracer.