Raytracer

Public API

PlantRayTracer.AreaSourceMethod
AreaSource(mesh)

Create an area irradiance source geometry given a triangular mesh.

Examples

julia> using PlantGeomPrimitives

julia> e = Ellipse();

julia> source_geom = AreaSource(e);
source
PlantRayTracer.AvgSplitType
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).

Examples

julia> rule = AvgSplit(1,5);
source
PlantRayTracer.BVHType
BVH(gbox, nodes, tris, ids)

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.

source
PlantRayTracer.BlackType
Black(nw::Int)

Create a black material object to store power for nw wavelengths. See VPL documentation for details.

Examples

julia> b = Black(1);

julia> b = Black(3);
source
PlantRayTracer.FixedSourceType
FixedSource(dir)
FixedSource(θ, Φ)

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

Examples

julia> source_dir = FixedSource(0.0, 0.0);

julia> import PlantGeomPrimitives as PG

julia> source_dir = FixedSource(PG.Vec(0.0, 0.0, -1.0));
source
PlantRayTracer.LambertianMethod
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)).

Examples

julia> l = Lambertian(τ = 0.1, ρ = 0.2);

julia> l = Lambertian(τ = (0.1, 0.45), ρ = (0.2, 0.45));
source
PlantRayTracer.LambertianSourceType
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.

Examples

julia> import PlantGeomPrimitives as PG

julia> source_dir = LambertianSource(PG.X(), PG.Y(), PG.Z());

julia> source_dir = LambertianSource((PG.X(), PG.Y(), PG.Z()));
source
PlantRayTracer.LineSourceType
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.

Examples

julia> import PlantGeomPrimitives as PG

julia> source_geom = LineSource(PG.Vec(1.0, 1.0, 1.0), PG.Y());
source
PlantRayTracer.NaiveType
Naive(tris::Vector{Triangle{FT}}, ids::Vector{Int}, rule) where {FT}

Wrap the scene into a global bounding box (no acceleration), given the triangles in a scene, the ids linking each triangle to the corresponding material objects. The argument rule is left for compatibility with BVH, it does not do anything.

Examples

julia> using PlantGeomPrimitives

julia> tris = PlantRayTracer.Triangle(Ellipse());

julia> ids  = repeat([1], length(tris));

julia> Naive(tris, ids);
source
PlantRayTracer.NaiveType
Naive

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

source
PlantRayTracer.PhongMethod
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)).

Examples

julia> p = Phong(τ = 0.1, ρd = 0.2, ρsmax = 0.5);

julia> p = Phong(τ = (0.1, 0.45), ρd = (0.2, 0.45), ρsmax = (0.5, 0.5));
source
PlantRayTracer.PointSourceType
PointSource(vec)

Create a point irradiance source geometry at given 3D location vec, defined as vector of Cartesian coordinates (Vec(x, y, z)).

Examples

julia> import PlantGeomPrimitives as PG

julia> source_geom = PointSource(PG.Vec(1.0, 1.0, 1.0));
source
PlantRayTracer.RTSettingsType
RTSettings(;verbose = true, parallel = false, pkill = 0.2, maxiter = 2,
            sampler = Random.Xoshiro(123456789), nx = 3, ny = 3, nz = 0, dx = 0.0,
            dy = 0.0, dz = 0.0)

Settings for the ray tracer:

  • verbose indicates if the ray tracer will print warnings and other information.

  • 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 (this excludes interactions with materials of type Sensor).

  • sampler is the pseudo-random number generator to be used by the ray tracer.

  • nx and ny are the number of times the mesh will be cloned 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 mesh), 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 mesh 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.

Examples

julia> RTSettings(parallel = true, maxiter = 3);
source
PlantRayTracer.RayTracerType
RayTracer(mesh, 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 (mesh), 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.

source
PlantRayTracer.RayTracerMethod
RayTracer(mesh, sources; settings = RTSettings(), acceleration = Naive, rule = nothing)

Create a RayTracer object from a mesh, a tuple of sources (objects that inherit from Source), or a single source, 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).

Examples

julia> using PlantGeomPrimitives;

julia> mesh = Ellipse();

julia> mat = Lambertian(τ = 0.1, ρ = 0.2);

julia> add_property!(mesh, :materials, [mat for _ in 1:ntriangles(mesh)]);

julia> source = DirectionalSource(mesh, θ = 0.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000);

julia> rt = RayTracer(mesh, source);

julia> sources = (DirectionalSource(mesh, θ = 0.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000),
                  DirectionalSource(mesh, θ = 45.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000));

julia> rt = RayTracer(mesh, sources);
source
PlantRayTracer.SAHType
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).

Examples

julia> rule = SAH{3}(1,5);
source
PlantRayTracer.SensorType
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.

Examples

julia> s = Sensor(1);

julia> s = Sensor(3);
source
PlantRayTracer.SourceMethod
Source(geom, angle, power::Number, nrays)
Source(geom, angle, power::Tuple, nrays)

Create an 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.

Examples

julia> import PlantGeomPrimitives as PG

julia> source_geom = PointSource(PG.O());

julia> source_dir = FixedSource(0.0, 0.0);

julia> Source(source_geom, source_dir, 1.0, 1_000);
source
PlantRayTracer.TwoSidedSensorType
TwoSidedSensor(nw::Int)

Create a sensor material object to store power for nw wavelengths. A two-sided 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. The accumulated power is stored separately for rays hitting on the front and back side of the sensor.

Examples

julia> s = TwoSidedSensor(1);

julia> s = TwoSidedSensor(3);
source
PlantRayTracer.DirectionalSourceMethod
DirectionalSource(box::AABB; θ, Φ, radiosity, nrays)
DirectionalSource(mesh::Mesh; θ, Φ, radiosity, nrays)

Create a Directional source (including geometry and angle components) by providing an axis-aligned bounding box (box) or an Mesh object as well as the zenith (θ) and azimuth (Φ) angles, the radiosity of the source projected on the horizontal plane and the number of rays to be generated. Directional sources may generate incorrect results in the absence of a grid cloner that extends the mesh. This is because the rays are generated from the upper face of the mesh's bounding box. See VPL documentation for details on light sources.

Examples

julia> using PlantGeomPrimitives;

julia> mesh = Ellipse();

julia> source = DirectionalSource(mesh, θ = 0.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000);
source
PlantRayTracer.accelerateMethod
accelerate(mesh::Mesh; settings = RTSettings(), acceleration = Naive, rule = nothing)

Create an AccMesh object from a mesh, 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 AccMesh object contains the acceleration structure and the grid cloner structure built on top of the original 3D meshes in mesh. See VPL documentation for details.

Examples

julia> using PlantGeomPrimitives;

julia> mesh = Ellipse();

julia> acc = accelerate(mesh);
source
PlantRayTracer.get_nwMethod
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.

Examples

julia> using PlantGeomPrimitives;

julia> mesh = Ellipse();

julia> mat = Lambertian(τ = 0.1, ρ = 0.2);

julia> add_property!(mesh, :materials, [mat for _ in 1:ntriangles(mesh)]);

julia> source = DirectionalSource(mesh, θ = 0.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000);

julia> rt = RayTracer(mesh, source);

julia> get_nw(rt)
1
source
PlantRayTracer.get_nwMethod
get_nw(s::Source)

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

Examples

julia> using PlantGeomPrimitives;

julia> mesh = Ellipse();

julia> source = DirectionalSource(mesh, θ = 0.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000);

julia> get_nw(source);
source
PlantRayTracer.powerMethod
power(material::Material)

Extract the power stored inside a material.

Examples

julia> l = Lambertian(τ = 0.1, ρ = 0.2);

julia> power(l);
source
PlantRayTracer.powerMethod
power(material::TwoSidedSensor; front = true)

Extract the power stored inside a two sided material. ```

source
PlantRayTracer.reset!Method
reset!(material::Material)

Reset the power stored inside a material back to zero

Examples

julia> l = Lambertian(τ = 0.1, ρ = 0.2);

julia> l.power[1] = 10.0;

julia> reset!(l);

julia> l;
source
PlantRayTracer.rhoMethod
rho(vals...)

Generate values of reflectivity to be used in material object. vals... is a list of one or more comma-separated values, corresponding to the different wavelengths/wavebands to be simulated in a ray tracer.

Examples

julia> rho(1.0, 0.0, 2.0);
source
PlantRayTracer.tauMethod
tau(vals...)

Generate values of transmisivity to be used in material object. vals... is a list of one or more comma-separated values, corresponding to the different wavelengths/wavebands to be simulated in a ray tracer.

Examples

julia> tau(1.0, 0.0, 2.0);
source
PlantRayTracer.trace!Method
trace!(rt)

Run the ray tracing simulations. This function will overwrite the power component of any material object that is included in the mesh. It returns the total number of rays being traced (primary and secondary) without including interactions with Sensor objects (first value returned) or including interactions with Sensor objects (second value returned). See VPL documentation for more details on the ray tracer.

Examples

julia> using PlantGeomPrimitives;

julia> mesh = Ellipse();

julia> mat = Lambertian(τ = 0.1, ρ = 0.2);

julia> add_property!(mesh, :materials, [mat for _ in 1:ntriangles(mesh)]);

julia> source = DirectionalSource(mesh, θ = 0.0, Φ = 0.0, radiosity = 1.0, nrays = 1_000);

julia> rt = RayTracer(mesh, source);

julia> trace!(rt);
source

Private

Private functions, types or constants from PlantRayTracer. These are not exported, so you need to prefix the function name with PlantRayTracer. to access them. Also bear in mind that these are not part of the public API, so they may change without notice.

PlantRayTracer.TriangleMethod
Triangle(p1::Vec, p2::Vec, p3::Vec)

Create a ray tracing Triangle object given the three vertices p1, p2 and p3.

Examples

julia> using PlantGeomPrimitives

julia> t = PlantRayTracer.Triangle(Vec(1.0, 0.0, 1.0), Vec(0.0, 1.0, .0), Vec(1.0, 1.0, 1.0));
source
PlantRayTracer.TriangleMethod
Triangle()

Create a ray tracing Triangle object with default vertices (unit vectors in each axis).

Examples

julia> t = PlantRayTracer.Triangle();
source
PlantRayTracer.TriangleMethod
Triangle(mesh::Mesh)

Create a vector of ray tracing Triangle objects from a Mesh object.

Examples

julia> using PlantGeomPrimitives;

julia> e = Ellipse();

julia> t = PlantRayTracer.Triangle(e);
source