This file contains the piecewise abstract type, for sampling from constants, 1D or 2D arrays. Inspired by PBRT piecewise class. Currently, the following public types are defined:
The piecewise type ensures that there is a method (sample) that can be called on all inherited types, e.g call 2Dimage%p%sample(x, y) will return a position (x,y) from where to release a photon. This class can be used to have multi-spectral or single valued wavelength, or used as a 2D image input source i.e SLMs. NOTE: optical properties are not currently adjusted on wavelength change.
initalise the piecewise1D type with an array size (n, 2). Calculates the CDF of this array. Input array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | array(:,:) |
Initalise the piecewise2D type with a given cell_width, cell_height and input image
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | cell_width |
Input cell width |
||
real(kind=wp), | intent(in) | :: | cell_height |
Input cell height |
||
real(kind=wp), | intent(in) | :: | image(:,:) |
Input image |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(piecewise), | intent(in) | :: | this | |||
real(kind=wp), | intent(out) | :: | x | |||
real(kind=wp), | intent(out) | :: | y | |||
real(kind=wp), | intent(in), | optional | :: | value |
Abstract spectrum base type.
procedure(sampleInterface), public, deferred :: sample | ../../ Deferred procdure. Used to generate a sample from spectrum or get constant value etc. |
1D piecewise type. Used for the spectral type
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=wp), | public, | allocatable | :: | array(:,:) |
Input array to sample from. Should be size(n, 2). 1st column is x-axis, 2nd column is y-axis |
||
real(kind=wp), | public, | allocatable | :: | cdf(:) |
cumulative distribution function (CDF) of array. |
public function init_piecewise1D (array) | initalise the piecewise1D type with an array size (n, 2). Calculates the CDF of this array. Input array |
procedure, public :: sample => sample1D | ../../ Overloaded sampling function |
2D piecewise type. Used for images
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=wp), | public, | allocatable | :: | cdf(:) |
cumulative distribution function (CDF) of array. |
||
real(kind=wp), | public | :: | cell_height |
Height of each cell |
|||
real(kind=wp), | public | :: | cell_width |
Width of each cell |
|||
integer, | private | :: | xoffset |
Offsets |
|||
integer, | private | :: | yoffset |
Offsets |
public function init_piecewise2D (cell_width, cell_height, image) | Initalise the piecewise2D type with a given cell_width, cell_height and input image |
procedure, public :: sample => sample2D | ../../ Overloaded sampling function |
Spectrum_t type. Used as a container type
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
class(piecewise), | public, | pointer | :: | p | => | null() |
initalise the piecewise1D type with an array size (n, 2). Calculates the CDF of this array. Input array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | array(:,:) |
Initalise the piecewise2D type with a given cell_width, cell_height and input image
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | cell_width |
Input cell width |
||
real(kind=wp), | intent(in) | :: | cell_height |
Input cell height |
||
real(kind=wp), | intent(in) | :: | image(:,:) |
Input image |
Compute the 2 indices from a Morton index Adapted from archer2 cpp course
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int64), | intent(in) | :: | z |
Morton Index |
||
integer(kind=int32), | intent(out) | :: | x |
The computed indices |
||
integer(kind=int32), | intent(out) | :: | y |
The computed indices |
The constant version of sample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(constant), | intent(in) | :: | this | |||
real(kind=wp), | intent(out) | :: | x |
Output value |
||
real(kind=wp), | intent(out) | :: | y |
Not used. Kept to keep interface the same for constant, piecewise1D and piecewise2D |
||
real(kind=wp), | intent(in), | optional | :: | value |
Not used. Kept to keep interface the same for constant, piecewise1D and piecewise2D |
Randomly sample from 1D array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(piecewise1D), | intent(in) | :: | this | |||
real(kind=wp), | intent(out) | :: | x |
Return value |
||
real(kind=wp), | intent(out) | :: | y |
Not used, but here so we can have same interface as 2D sample routine. |
||
real(kind=wp), | intent(in), | optional | :: | value |
Optional x value. If not present we generate a random one in the range [0., 1.] |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(piecewise2D), | intent(in) | :: | this | |||
real(kind=wp), | intent(out) | :: | x | |||
real(kind=wp), | intent(out) | :: | y | |||
real(kind=wp), | intent(in), | optional | :: | value |
search by bisection for 1D array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | array(:) |
Array to search |
||
integer(kind=int64), | intent(out) | :: | nlow |
index of found value |
||
real(kind=wp), | intent(in) | :: | value |
value to find in 1D array |
search by bisection for 1D array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | array(:,:) |
2D array to search. Only searches 1st column |
||
integer(kind=int64), | intent(out) | :: | nlow |
Index of found index |
||
real(kind=wp), | intent(in) | :: | value |
Value to find in the array. |