sdfs Module

This module defines the signed distance function (SDF) abstract type and all types that inherit from it. The SDF abstract type defines 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.

  • cylinder
  • sphere
  • box
  • torus
  • cone
  • triprism (triangular prism)
  • capsule
  • plane
  • segment
  • egg

This is the module the user should import to other module not sdf_base!



Interfaces

public interface box

Interface to box SDF initialising function

  • private function box_init(lengths, optProp, layer, transform) result(out)

    Initalising function for Box SDF.

    Arguments

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

    Lengths of each dimension of the box

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(box)

public interface capsule

Interface to capsule SDF initialising function

  • private function capsule_init(a, b, r, optProp, layer, transform) result(out)

    Initalising function for capsule SDF.

    Arguments

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

    Capsule startpoint

    type(vector), intent(in) :: b

    Capsule endpoint

    real(kind=wp), intent(in) :: r

    Capsule radius

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(capsule)

public interface cone

Interface to cone SDF initialising function

  • private function cone_init(a, b, ra, rb, optProp, layer, transform) result(out)

    Initalising function for Capped Cone SDF.

    Arguments

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

    Centre of base of Cone

    type(vector), intent(in) :: b

    Tip of cone

    real(kind=wp), intent(in) :: ra

    Radius of Cones base

    real(kind=wp), intent(in) :: rb

    Radius of Cones tip. For rb = 0.0 get normal uncapped cone.

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(cone)

public interface cylinder

Interface to cylinder SDF initialising function

  • private function cylinder_init(a, b, radius, optProp, layer, transform) result(out)

    Initalising function for Cylinder SDF.

    Arguments

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

    Vector position at centre of the bottom circle

    type(vector), intent(in) :: b

    Vector position at centre of the top circle

    real(kind=wp), intent(in) :: radius

    Radius of cylinder

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(cylinder)

public interface egg

Interface to egg SDF initialising function

  • private function egg_init(r1, r2, h, optProp, layer, transform) result(out)

    Initalising function for egg SDF. makes a Moss egg. ref.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: r1

    R1 controls "fatness" of the egg. Actually controls the base circle radius.

    real(kind=wp), intent(in) :: r2

    R2 contorls the pointiness of the egg. Actually controls radius of top circle.

    real(kind=wp), intent(in) :: h

    h controls the height of the egg. Actually controls y position of top circle.

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(egg)

public interface plane

Interface to plane SDF initialising function

  • private function plane_init(a, optProp, layer, transform) result(out)

    Initalising function for plane SDF.

    Arguments

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

    Plane normal. must be normalised

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(plane)

public interface segment

Interface to segment SDF initialising function

  • private function segment_init(a, b, optProp, layer, transform) result(out)

    Initalising function for segment SDF. Note this is a 2D function

    Arguments

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

    segment start point

    type(vector), intent(in) :: b

    segment end point

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(segment)

public interface sphere

  • private function sphere_init(radius, optProp, layer, transform) result(out)

    Initalising function for Sphere SDF.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: radius

    radius of the Sphere

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(sphere)

public interface torus

Interface to torus SDF initialising function

  • private function torus_init(oradius, iradius, optProp, layer, transform) result(out)

    Initalising function for Torus SDF.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: oradius

    Outer radius of Torus

    real(kind=wp), intent(in) :: iradius

    Inner radius of Torus

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(torus)

public interface triprism

Interface to triprisim SDF initialising function

  • private function triprism_init(h1, h2, optProp, layer, transform) result(out)

    Initalising function for triprisim SDF.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: h1

    Height of triprisim

    real(kind=wp), intent(in) :: h2

    length of triprisim

    type(opticalProp_t), intent(in) :: optProp

    Optical properties of the SDF

    integer, intent(in) :: layer

    ID number of sdf

    real(kind=wp), intent(in), optional :: transform(4,4)

    Optional transform to apply to SDF

    Return Value type(triprism)


Derived Types

type, public, extends(sdf_base) ::  box

Box SDF

Components

Type Visibility Attributes Name Initial
integer, public :: layer

Layer ID of SDF

type(vector), public :: lengths

Length of each dimension of the box

type(opticalProp_t), public :: optProps

Optical property of the SDF

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

Transform to apply to SDF.

Constructor

Interface to box SDF initialising function

private function box_init (lengths, optProp, layer, transform)

Initalising function for Box SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_box

type, public, extends(sdf_base) ::  capsule

Capsule SDF

Components

Type Visibility Attributes Name Initial
type(vector), public :: a
type(vector), public :: b
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

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

Transform to apply to SDF.

Constructor

Interface to capsule SDF initialising function

private function capsule_init (a, b, r, optProp, layer, transform)

Initalising function for capsule SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_capsule

type, public, extends(sdf_base) ::  cone

Cone SDF

Components

Type Visibility Attributes Name Initial
type(vector), public :: a
type(vector), public :: b
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

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

Transform to apply to SDF.

Constructor

Interface to cone SDF initialising function

private function cone_init (a, b, ra, rb, optProp, layer, transform)

Initalising function for Capped Cone SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_cone

type, public, extends(sdf_base) ::  cylinder

Cylinder SDF

Components

Type Visibility Attributes Name Initial
type(vector), public :: a
type(vector), public :: b
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

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

Transform to apply to SDF.

Constructor

Interface to cylinder SDF initialising function

private function cylinder_init (a, b, radius, optProp, layer, transform)

Initalising function for Cylinder SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_cylinder

type, public, extends(sdf_base) ::  egg

Egg SDF

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: h
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

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

Transform to apply to SDF.

Constructor

Interface to egg SDF initialising function

private function egg_init (r1, r2, h, optProp, layer, transform)

Initalising function for egg SDF. makes a Moss egg. ref.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_egg

type, public, extends(sdf_base) ::  plane

Plane SDF

Components

Type Visibility Attributes Name Initial
type(vector), public :: a
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

Interface to plane SDF initialising function

private function plane_init (a, optProp, layer, transform)

Initalising function for plane SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_plane

type, public, extends(sdf_base) ::  segment

Segment SDF (2D)

Components

Type Visibility Attributes Name Initial
type(vector), public :: a
type(vector), public :: b
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

Interface to segment SDF initialising function

private function segment_init (a, b, optProp, layer, transform)

Initalising function for segment SDF. Note this is a 2D function

Type-Bound Procedures

procedure, public :: evaluate => evaluate_segment

type, public, extends(sdf_base) ::  sphere

Sphere SDF

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 :: radius
real(kind=wp), public :: transform(4,4)

Transform to apply to SDF.

Constructor

private function sphere_init (radius, optProp, layer, transform)

Initalising function for Sphere SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_sphere

type, public, extends(sdf_base) ::  torus

Torus SDF

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: iradius
integer, public :: layer

Layer ID of SDF

type(opticalProp_t), public :: optProps

Optical property of the SDF

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

Transform to apply to SDF.

Constructor

Interface to torus SDF initialising function

private function torus_init (oradius, iradius, optProp, layer, transform)

Initalising function for Torus SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_torus

type, public, extends(sdf_base) ::  triprism

Triprisim SDF

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: h1
real(kind=wp), public :: h2
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

Interface to triprisim SDF initialising function

private function triprism_init (h1, h2, optProp, layer, transform)

Initalising function for triprisim SDF.

Type-Bound Procedures

procedure, public :: evaluate => evaluate_triprism

Functions

private function box_init(lengths, optProp, layer, transform) result(out)

Initalising function for Box SDF.

Arguments

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

Lengths of each dimension of the box

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(box)

private function capsule_init(a, b, r, optProp, layer, transform) result(out)

Initalising function for capsule SDF.

Arguments

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

Capsule startpoint

type(vector), intent(in) :: b

Capsule endpoint

real(kind=wp), intent(in) :: r

Capsule radius

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(capsule)

private function cone_init(a, b, ra, rb, optProp, layer, transform) result(out)

Initalising function for Capped Cone SDF.

Arguments

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

Centre of base of Cone

type(vector), intent(in) :: b

Tip of cone

real(kind=wp), intent(in) :: ra

Radius of Cones base

real(kind=wp), intent(in) :: rb

Radius of Cones tip. For rb = 0.0 get normal uncapped cone.

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(cone)

private function cylinder_init(a, b, radius, optProp, layer, transform) result(out)

Initalising function for Cylinder SDF.

Arguments

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

Vector position at centre of the bottom circle

type(vector), intent(in) :: b

Vector position at centre of the top circle

real(kind=wp), intent(in) :: radius

Radius of cylinder

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(cylinder)

private function egg_init(r1, r2, h, optProp, layer, transform) result(out)

Initalising function for egg SDF. makes a Moss egg. ref.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: r1

R1 controls "fatness" of the egg. Actually controls the base circle radius.

real(kind=wp), intent(in) :: r2

R2 contorls the pointiness of the egg. Actually controls radius of top circle.

real(kind=wp), intent(in) :: h

h controls the height of the egg. Actually controls y position of top circle.

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(egg)

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

Evaluation function for Box SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Capsule SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Cone SDF.

Arguments

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

Return Value real(kind=wp)

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

Evaluation function for Cylinder SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Egg SDF. ref

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Plane SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Segment SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Sphere SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Torus SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

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

Evaluation function for Triprisim SDF.

Arguments

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

vector position to evaluate SDF at

Return Value real(kind=wp)

private function plane_init(a, optProp, layer, transform) result(out)

Initalising function for plane SDF.

Arguments

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

Plane normal. must be normalised

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(plane)

private function segment_init(a, b, optProp, layer, transform) result(out)

Initalising function for segment SDF. Note this is a 2D function

Arguments

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

segment start point

type(vector), intent(in) :: b

segment end point

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(segment)

private function sphere_init(radius, optProp, layer, transform) result(out)

Initalising function for Sphere SDF.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: radius

radius of the Sphere

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(sphere)

private function torus_init(oradius, iradius, optProp, layer, transform) result(out)

Initalising function for Torus SDF.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: oradius

Outer radius of Torus

real(kind=wp), intent(in) :: iradius

Inner radius of Torus

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(torus)

private function triprism_init(h1, h2, optProp, layer, transform) result(out)

Initalising function for triprisim SDF.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: h1

Height of triprisim

real(kind=wp), intent(in) :: h2

length of triprisim

type(opticalProp_t), intent(in) :: optProp

Optical properties of the SDF

integer, intent(in) :: layer

ID number of sdf

real(kind=wp), intent(in), optional :: transform(4,4)

Optional transform to apply to SDF

Return Value type(triprism)