sdf_baseMod Module

This module defines the signed distance function (SDF) abstract type, sdf_base type, and model type. The SDF abstract type contains the optical properties of an SDF (mus, mua, kappa, albedo, hgg, g2,and n), as well as a transform (4x4 matrix), and the layer ID code of the SDF. The SDF abstract type also provides an abstract interface (evaluate) which each inheriting function must implement. This evaluate function is the heart of the SDF implementation. Each individual evaluate is the direct implementation of that SDF, e.g. that function defines the mathematical SDF. For more information on SDFs, check out Inigo Quilez's website from which most of the below SDFs and transforms have been taken. API based upon here



Interfaces

public interface model

  • private function model_init(array, func, kopt) result(out)

    Initalise the model type.

    Arguments

    Type IntentOptional Attributes Name
    type(sdf), intent(in) :: array(:)

    Array of SDFs

    procedure(op) :: func

    Operator to apply to SDF.

    real(kind=wp), intent(in), optional :: kopt

    Parameter used in modifier

    Return Value type(model)

public interface render

  • private subroutine render_sub(cnt, extent, samples, state)

    Render the SDFs onto a voxel grid

    Arguments

    Type IntentOptional Attributes Name
    type(sdf), intent(in) :: cnt(:)
    type(vector), intent(in) :: extent
    integer, intent(in) :: samples(3)
    type(settings_t), intent(in) :: state
  • private subroutine render_vec(cnt, state)

    Render the SDF Wrapper around the render function to allow ease of use

    Arguments

    Type IntentOptional Attributes Name
    type(sdf), intent(in) :: cnt(:)
    type(settings_t), intent(in) :: state

public interface sdf

  • private function sdf_new(rhs) result(lhs)

    sdf initializer

    Arguments

    Type IntentOptional Attributes Name
    class(sdf_base), intent(in) :: rhs

    Return Value type(sdf)


Abstract Interfaces

abstract interface

  • public pure elemental function evalInterface(this, pos) result(res)

    Evaluation function for SDF. ALL SDF must implment this.

    Arguments

    Type IntentOptional Attributes Name
    class(sdf_base), intent(in) :: this
    type(vector), intent(in) :: pos

    Return Value real(kind=wp)

abstract interface

  • public pure function op(d1, d2, k) result(res)

    Abstract function used as the base for SDF operators (union, subtraction etc)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: d1
    real(kind=wp), intent(in) :: d2
    real(kind=wp), intent(in) :: k

    Return Value real(kind=wp)

abstract interface

  • public pure function primitive(pos) result(res)

    Abstract function used as base for displacement function

    Arguments

    Type IntentOptional Attributes Name
    type(vector), intent(in) :: pos

    vector position of photon packet.

    Return Value real(kind=wp)


Derived Types

type, public, extends(sdf_base) ::  model

Model type. Allows the collection of multiple SDF into one model. Used to apply modifiers.

Components

Type Visibility Attributes Name Initial
type(sdf), public, allocatable :: array(:)

Array of SDFs in the model

procedure(op), public, nopass, pointer :: func

SDF modifier function

real(kind=wp), public :: k

Parameter that may be used in modifer function.

integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

real(kind=wp), public :: transform(4,4)

Transform to apply to SDF.

Constructor

private function model_init (array, func, kopt)

Initalise the model type.

Type-Bound Procedures

procedure, public :: evaluate => eval_model

type, public, extends(sdf_base) ::  sdf

Container type that allows the use of arrays of different SDF shapes

Components

Type Visibility Attributes Name Initial
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

real(kind=wp), public :: transform(4,4)

Transform to apply to SDF.

class(sdf_base), public, allocatable :: value

Container for any SDF that inherits from SDF_base

Constructor

private function sdf_new (rhs)

sdf initializer

Type-Bound Procedures

generic, public :: assignment(=) => sdf_assign
procedure, public :: evaluate => sdf_evaluate
procedure, public :: getAlbedo
procedure, public :: getG2 => getg2
procedure, public :: getKappa
procedure, public :: getMua
procedure, public :: getN
procedure, public :: gethgg
procedure, private :: sdf_assign

type, public, abstract ::  sdf_base

Abstract base type from which all SDF inherit from.

Components

Type Visibility Attributes Name Initial
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

real(kind=wp), public :: transform(4,4)

Transform to apply to SDF.

Type-Bound Procedures

procedure(evalInterface), public, deferred :: evaluate

Functions

public function calcNormal(p, obj)

Calculate the surface normal of a SDF at the point p numerically.

Arguments

Type IntentOptional Attributes Name
type(vector), intent(in) :: p

Position to evaluate at

class(sdf_base) :: obj

SDF to calcuate surface normal of.

Return Value type(vector)

private pure elemental function eval_model(this, pos) result(res)

Evaluate the model

Arguments

Type IntentOptional Attributes Name
class(model), intent(in) :: this
type(vector), intent(in) :: pos

Vector position to evaluate at

Return Value real(kind=wp)

private function getAlbedo(this) result(res)

Return albedo for the current SDF.

Arguments

Type IntentOptional Attributes Name
class(sdf) :: this

Return Value real(kind=wp)

private function getKappa(this) result(res)

Return for the current SDF

Arguments

Type IntentOptional Attributes Name
class(sdf) :: this

Return Value real(kind=wp)

private function getMua(this) result(res)

Return for the current SDF.

Arguments

Type IntentOptional Attributes Name
class(sdf) :: this

Return Value real(kind=wp)

private function getN(this) result(res)

Return refractive index for the current SDF.

Arguments

Type IntentOptional Attributes Name
class(sdf) :: this

Return Value real(kind=wp)

private function getg2(this) result(res)

Return factor for the current SDF.

Arguments

Type IntentOptional Attributes Name
class(sdf) :: this

Return Value real(kind=wp)

private function gethgg(this) result(res)

Return g-factor for the current SDF.

Arguments

Type IntentOptional Attributes Name
class(sdf) :: this

Return Value real(kind=wp)

private function model_init(array, func, kopt) result(out)

Initalise the model type.

Arguments

Type IntentOptional Attributes Name
type(sdf), intent(in) :: array(:)

Array of SDFs

procedure(op) :: func

Operator to apply to SDF.

real(kind=wp), intent(in), optional :: kopt

Parameter used in modifier

Return Value type(model)

private pure elemental function sdf_evaluate(this, pos) result(res)

Evaluate the SDF at a given position.

Arguments

Type IntentOptional Attributes Name
class(sdf), intent(in) :: this
type(vector), intent(in) :: pos

Return Value real(kind=wp)

private function sdf_new(rhs) result(lhs)

sdf initializer

Arguments

Type IntentOptional Attributes Name
class(sdf_base), intent(in) :: rhs

Return Value type(sdf)


Subroutines

private subroutine render_sub(cnt, extent, samples, state)

Render the SDFs onto a voxel grid

Arguments

Type IntentOptional Attributes Name
type(sdf), intent(in) :: cnt(:)
type(vector), intent(in) :: extent
integer, intent(in) :: samples(3)
type(settings_t), intent(in) :: state

private subroutine render_vec(cnt, state)

Render the SDF Wrapper around the render function to allow ease of use

Arguments

Type IntentOptional Attributes Name
type(sdf), intent(in) :: cnt(:)
type(settings_t), intent(in) :: state

private subroutine sdf_assign(lhs, rhs)

sdf initializer

Arguments

Type IntentOptional Attributes Name
class(sdf), intent(inout) :: lhs
class(sdf_base), intent(in) :: rhs