Core 1.0
Phasor2 Class Reference

Procedural phasor noise in the plane. More...

#include <phasornoise.h>

Inheritance diagram for Phasor2:
AnalyticScalarField2

Public Types

enum class  Profile { Sine , Sawtooth , Triangle , Square }
 Periodic profiles applied to the phase field. More...

Public Member Functions

 Phasor2 (const double &=10.0, const double &=8.0, const double &=0.0, const double &=0.0, int=16, unsigned int=0)
 Create a phasor noise.
virtual ~Phasor2 ()
 Empty.
double Value (const Vector2 &) const override
 Compute the phasor noise at a given point, in [0,1].
Vector2 Phasor (const Vector2 &) const
 Compute the complex sum of kernels at a given point.
double Phase (const Vector2 &) const
 Compute the phase at a given point, in [-π, π].
double Gabor (const Vector2 &) const
 Compute the Gabor noise at a given point, which is the real part of the complex sum.
double Intensity (const Vector2 &) const
 Compute the intensity at a given point, which is the modulus of the complex sum.
void SetProfile (Profile, const double &=0.5)
 Set the periodic profile applied to the phase.
double KernelRadius () const
 Return the radius of the truncated kernels.
virtual double Orientation (const Vector2 &) const
 Orientation of the kernels at a given point.
virtual double Frequency (const Vector2 &) const
 Frequency of the kernels at a given point.
Public Member Functions inherited from AnalyticScalarField2
 AnalyticScalarField2 (bool=true)
 Constructor.
virtual Vector2 Gradient (const Vector2 &) const
 Compute the gradient of the field.
virtual Matrix2 Hessian (const Vector2 &) const
 Compute the hessian at a given point.
virtual ScalarField2 Sample (const Array2 &) const
 Create a discrete scalar field by sampling a given domain.
bool Inside (const double &) const
 Check if the value is considered as inside or outside.
void Curvature (const Vector2 &, double &, double &) const
 Compute the gaussian and mean curvatures.
virtual Box2 GetBox () const
 Return the bounding box.

Protected Member Functions

Vector2 Cell (const Vec2I &, const Vector2 &) const
 Compute the sum of the complex kernels of a cell at a given point.
double Periodic (const double &) const
 Apply the periodic profile to a phase.
Protected Member Functions inherited from AnalyticScalarField2
Matrix Local (const Vector2 &) const
 Compute the local neighborhood in the one-ring aroung a point.

Protected Attributes

double frequency = 10.0
 Frequency, number of oscillations per unit length.
double bandwidth = 8.0
 Bandwidth b of the Gaussian envelope \( \exp(-\pi b^2 r^2) \) of the kernels.
double angle = 0.0
 Main orientation of the oscillations, in radians.
double spread = 0.0
 Angular spread factor in [0,1], 0 for an oriented noise, 1 for an isotropic noise.
int kernels = 16
 Number of kernels per cell.
unsigned int seed = 0
 Random seed.
Profile profile = Profile::Sine
 Periodic profile.
double density = 0.5
 Duty cycle of the square profile, in [0,1].
double radius = 0.0
 Radius of the truncated kernels.
Protected Attributes inherited from AnalyticScalarField2
bool sign = true
 Sign convention, used for normal computation.
Box2 box = Box2::Infinity
 Domain, set as infinite for base class.

Static Protected Attributes

static const double truncation = 0.01
 Value of the Gaussian envelope at the kernel radius.
Static Protected Attributes inherited from AnalyticScalarField2
static const double epsilon = 1e-6
 \( \varepsilon \) value for first order partial derivatives (gradient).
static const double epsilonhessian = 1e-4
 Larger \( \varepsilon \) value for second order partial derivatives (hessian).

Detailed Description

Procedural phasor noise in the plane.

Phasor noise is a sparse convolution noise that sums complex Gabor kernels and only keeps the phase of the resulting complex field. Contrary to Gabor noise, whose amplitude fluctuates, the phase field yields oscillations with a constant contrast, and an arbitrary periodic profile (sine, sawtooth, triangle, square) can be applied to it.

After Thibault Tricard, Semyon Efremov, Cédric Zanni, Fabrice Neyret, Jonàs Martínez and Sylvain Lefebvre, Procedural phasor noise, ACM Transactions on Graphics, 38(4), 2019. The reference implementation by the authors is available at https://github.com/mfx-inria/phasornoise.

The complex field is defined as a sum of kernels:

\[ G(\mathbf{p}) = \sum_k \exp\left(-\pi b^2 \|\mathbf{p}-\mathbf{p}_k\|^2\right) \exp\left(i \left(2 \pi f\, \mathbf{d}_k \cdot (\mathbf{p}-\mathbf{p}_k) + \varphi_k\right)\right) \]

where \( \mathbf{p}_k \) are random kernel centers, \( \mathbf{d}_k \) unit directions, \( \varphi_k \) random phases, \( f \) the frequency and \( b \) the bandwidth. The phasor noise is the phase \( \phi(\mathbf{p}) = \arg G(\mathbf{p}) \), and the value of the field is a periodic profile of this phase.

Kernels are truncated at the radius \( r = \sqrt{-\ln(t)/\pi}/b \) where the Gaussian envelope reaches the truncation value t. The plane is partitioned into square cells of size 2r, each one containing a fixed number of kernels with random positions, directions and phases. Because the kernel radius is half the cell size, a point is only influenced by the 2×2 cells closest to it, which makes the evaluation cost equal to four times the number of kernels per cell.

The ratio between frequency and bandwidth controls the number of oscillations within a kernel: with \( f\,r \) about 1.5, kernels hold a few periods, which yields well defined oscillations.

The orientation and the frequency of the kernels can be locally controlled by overloading Phasor2::Orientation() and Phasor2::Frequency(), which are evaluated at the kernel centers.

Phasor2 phasor(20.0, 16.0, Math::Pi / 4.0); // Frequency, bandwidth, orientation
phasor.SetProfile(Phasor2::Profile::Square, 0.3); // Thin stripes
double v = phasor.Value(Vector2(0.5, 0.25));
static constexpr double Pi
.
Definition mathematics.h:168
@ Square
Square wave, whose duty cycle is defined by the density.
Definition phasornoise.h:17
Phasor2(const double &=10.0, const double &=8.0, const double &=0.0, const double &=0.0, int=16, unsigned int=0)
Create a phasor noise.
Definition phasornoise2.cpp:58
Vector2()
Empty.
Definition evector.h:637
See also
GaborNoise

Member Enumeration Documentation

◆ Profile

enum class Phasor2::Profile
strong

Periodic profiles applied to the phase field.

Enumerator
Sine 

Sine wave.

Sawtooth 

Sawtooth, linear ramp of the phase.

Triangle 

Triangle wave.

Square 

Square wave, whose duty cycle is defined by the density.

Constructor & Destructor Documentation

◆ Phasor2()

Phasor2::Phasor2 ( const double & f = 10.0,
const double & b = 8.0,
const double & a = 0.0,
const double & s = 0.0,
int n = 16,
unsigned int seed = 0 )
explicit

Create a phasor noise.

Parameters
fFrequency, number of oscillations per unit length.
bBandwidth of the Gaussian envelope of the kernels, which should be strictly positive.
aMain orientation of the oscillations, in radians.
sAngular spread factor in [0,1], 0 for an oriented noise, 1 for an isotropic noise.
nNumber of kernels per cell.
seedRandom seed.

Member Function Documentation

◆ Cell()

Vector2 Phasor2::Cell ( const Vec2I & ij,
const Vector2 & q ) const
protected

Compute the sum of the complex kernels of a cell at a given point.

The random number generator of the cell is seeded by hashing the cell coordinates with Vec2I::pcg2d(), combined with the hashed seed of the noise, so that every cell and every seed get an independent sequence of kernels.

Parameters
ijInteger coordinates of the cell.
qCoordinates of the point relative to the cell, scaled so that the cell is the unit square.

◆ Frequency()

double Phasor2::Frequency ( const Vector2 & p) const
virtual

Frequency of the kernels at a given point.

The default implementation returns the constant frequency; overload this function to define a frequency field.

Parameters
pPoint, center of the kernel.

◆ Gabor()

double Phasor2::Gabor ( const Vector2 & p) const

Compute the Gabor noise at a given point, which is the real part of the complex sum.

Parameters
pPoint.

◆ Intensity()

double Phasor2::Intensity ( const Vector2 & p) const

Compute the intensity at a given point, which is the modulus of the complex sum.

The phase is ill defined where the intensity is close to zero, which happens at isolated singular points.

Parameters
pPoint.

◆ Orientation()

double Phasor2::Orientation ( const Vector2 & p) const
virtual

Orientation of the kernels at a given point.

The default implementation returns the constant main orientation; overload this function to define an orientation field.

Parameters
pPoint, center of the kernel.

◆ Periodic()

double Phasor2::Periodic ( const double & phi) const
protected

Apply the periodic profile to a phase.

Parameters
phiPhase, in [-π, π].
Returns
Value in [0,1].

◆ Phase()

double Phasor2::Phase ( const Vector2 & p) const

Compute the phase at a given point, in [-π, π].

Parameters
pPoint.

◆ Phasor()

Vector2 Phasor2::Phasor ( const Vector2 & p) const

Compute the complex sum of kernels at a given point.

The real part is a Gabor noise, the argument is the phasor noise.

Parameters
pPoint.

◆ SetProfile()

void Phasor2::SetProfile ( Profile p,
const double & d = 0.5 )

Set the periodic profile applied to the phase.

Parameters
pProfile.
dDuty cycle of the square profile, in [0,1], ignored for the other profiles.

◆ Value()

double Phasor2::Value ( const Vector2 & p) const
overridevirtual

Compute the phasor noise at a given point, in [0,1].

Parameters
pPoint.

Reimplemented from AnalyticScalarField2.