chombo-discharge
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
PerlinSdf Class Reference

Class that implements the improved Perlin noise function. More...

#include <CD_PerlinSdf.H>

Inheritance diagram for PerlinSdf:
Inheritance graph
[legend]
Collaboration diagram for PerlinSdf:
Collaboration graph
[legend]

Public Member Functions

 PerlinSdf (const Real a_noiseAmp, const RealVect &a_noiseFreq, const Real a_persistence, const int a_octaves, const bool a_reseed=false)
 Full constructor.
 
 PerlinSdf (const PerlinSdf &a_inputIF)
 Copy constructor.
 
virtual ~PerlinSdf ()
 Destructor.
 
virtual Real value (const RealVect &a_pos) const
 Level-set function.
 
virtual BaseIF * newImplicitFunction () const
 Factory method.
 

Static Public Member Functions

static int random (const int i)
 Simple random number generator.
 

Protected Member Functions

virtual void reseed ()
 Reseed function.
 
double noise (const double a_x, const double a_y, const double a_z) const
 Ken Perlin's 3D noise function.
 
Real noise (const RealVect &a_pos) const
 Chombo interface to Perlin noise function.
 
Real octaveNoise (const RealVect &a_pos) const
 Octave noise function. Returns noise over over several octaves.
 

Static Protected Member Functions

static Real lerp (const Real t, const Real a, const Real b)
 Interpolation function.
 
static Real fade (const Real t)
 Fade function.
 
static Real grad (const int hash, const double x, const double y, const double z)
 Gradient function using hash table lookup.
 

Protected Attributes

RealVect m_noiseFreq
 Perlin noise frequency.
 
Real m_noiseAmp
 Perlin noise amplitude.
 
Real m_persistence
 Perlin octave fade factor.
 
int m_octaves
 Number of octaves to use for noise.
 
double p [512]
 Permutation table.
 

Static Protected Attributes

static constexpr int m_permutationTable [256]
 Ken Perlin's original permutation array.
 

Detailed Description

Class that implements the improved Perlin noise function.

Typically, you will use this function to displace a level-set function by using SumIF. However, Perlin noise is also a signed distance function, and so it can be used as an implicit function as well.

Note
See the original paper by Ken Perlin for understanding the algorithm: "Improving Noise. Ken Perlin (2002)"

Constructor & Destructor Documentation

◆ PerlinSdf() [1/2]

PerlinSdf::PerlinSdf ( const Real  a_noiseAmp,
const RealVect a_noiseFreq,
const Real  a_persistence,
const int  a_octaves,
const bool  a_reseed = false 
)

Full constructor.

Parameters
[in]a_noiseAmpNoise amplitude
[in]a_noiseFreqBase frequency
[in]a_octavesNumber of octaves to use for Perlin noise
[in]a_persistenceReduction factor for each octave
[in]a_reseedReseed permutation vector (true) or use Ken Perlin's original one (false)

◆ PerlinSdf() [2/2]

PerlinSdf::PerlinSdf ( const PerlinSdf a_inputIF)

Copy constructor.

Parameters
[in]a_inputIFInput PerlinSdf

Member Function Documentation

◆ fade()

Real PerlinSdf::fade ( const Real  t)
staticprotected

Fade function.

Returns
Return value
Parameters
[in]tDescription

◆ grad()

Real PerlinSdf::grad ( const int  hash,
const double  x,
const double  y,
const double  z 
)
staticprotected

Gradient function using hash table lookup.

Returns
Return value
Parameters
[in]hashDescription
[in]xDescription
[in]yDescription
[in]zDescription

◆ lerp()

Real PerlinSdf::lerp ( const Real  t,
const Real  a,
const Real  b 
)
staticprotected

Interpolation function.

Returns
Return value
Parameters
[in]tDescription
[in]aDescription
[in]bDescription

◆ newImplicitFunction()

BaseIF * PerlinSdf::newImplicitFunction ( ) const
virtual

Factory method.

Returns
New copy of this implicit function

◆ noise() [1/2]

double PerlinSdf::noise ( const double  a_x,
const double  a_y,
const double  a_z 
) const
protected

Ken Perlin's 3D noise function.

For 2D, we use Ken Perlin's function with z = 0

Parameters
[in]a_xPosition
[in]a_yPosition
[in]a_zPosition
Returns
Return value

◆ noise() [2/2]

Real PerlinSdf::noise ( const RealVect a_pos) const
protected

Chombo interface to Perlin noise function.

Returns
Return value
Parameters
[in,out]a_posDescription

◆ octaveNoise()

Real PerlinSdf::octaveNoise ( const RealVect a_pos) const
protected

Octave noise function. Returns noise over over several octaves.

Returns
Return value
Parameters
[in,out]a_posDescription

normFrac;

◆ random()

int PerlinSdf::random ( const int  i)
static

Simple random number generator.

Returns
Return value
Parameters
[in]iI

◆ value()

Real PerlinSdf::value ( const RealVect a_pos) const
virtual

Level-set function.

Parameters
[in]a_posPosition
Returns
Function value at the given point

Member Data Documentation

◆ m_permutationTable

constexpr int PerlinSdf::m_permutationTable
staticconstexprprotected
Initial value:
= {
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142,
8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203,
117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165,
71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41,
55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89,
18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250,
124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189,
28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34,
242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31,
181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114,
67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180}

Ken Perlin's original permutation array.


The documentation for this class was generated from the following files: