Corentin Chauvin-Hameau – 2019-2020
Coverage Path Planning for an underwater robot surveying a marine farm
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
mfcpp::PerlinNoiseGenerator Class Reference

Perlin noise generator. More...

#include <perlin_noise.hpp>

Classes

struct  Vec2d
 Two dimensional vector. More...
 

Public Member Functions

 PerlinNoiseGenerator ()
 Default constructor. More...
 
 PerlinNoiseGenerator (float height, float width, unsigned int n_height, unsigned int n_width, unsigned long int seed=0)
 Constructor initialising the generator with the given parameters. More...
 
 ~PerlinNoiseGenerator ()
 
void configure (float height, float width, unsigned int n_height, unsigned int n_width, unsigned long int seed=0)
 Configures the generator. More...
 
void randomise_gradients ()
 Fills the hash list with random gradients. More...
 
void generate (unsigned long int seed=0)
 Populates the grid with random gradients from the hash list. More...
 
double evaluate (float x, float y) const
 Evaluates the perlin noise at a given position. More...
 
float accentuate (float x) const
 Applies a polynomial to accentuate the given value. More...
 

Private Member Functions

void init_random (unsigned long int seed)
 Initialises random generation. More...
 
float dot_product (Vec2d u, Vec2d v) const
 Computes the dot product between two vectors. More...
 
float dot_dist_grad (unsigned int i, unsigned int j, float x, float y) const
 Compute the dot product of the distance vector to the node an the gradient at this node. More...
 
float interpolate (float a, float b, float t) const
 Linear interpolation between two values. More...
 
float fade (float t) const
 Sixth order polynomial to smooth the noise. More...
 

Private Attributes

float height_
 Height of the 2D space in which to generate the noise. More...
 
float width_
 Width of the 2D space in which to generate the noise. More...
 
unsigned int n_height_
 Size of the discretised grid in the first dimension. More...
 
unsigned int n_width_
 Size of the discretised grid in the second dimension. More...
 
std::vector< std::vector< Vec2d > > gradients_
 Gradients evaluated at nodes of the grid. More...
 
std::vector< Vec2dhash_gradients_
 Hash list of random gradients. More...
 
bool randomise_seed_
 Whether to randomise seeding for random numbers. More...
 
unsigned long int seed_
 Seed for random numbers when no random seeding. More...
 
std::random_device random_device_
 Seed initialiser for generation of random numbers. More...
 

Detailed Description

Perlin noise generator.

Definition at line 21 of file perlin_noise.hpp.

Constructor & Destructor Documentation

mfcpp::PerlinNoiseGenerator::PerlinNoiseGenerator ( )

Default constructor.

Definition at line 56 of file perlin_noise.cpp.

mfcpp::PerlinNoiseGenerator::PerlinNoiseGenerator ( float  height,
float  width,
unsigned int  n_height,
unsigned int  n_width,
unsigned long int  seed = 0 
)

Constructor initialising the generator with the given parameters.

Parameters
heightHeight of the 2D space in which to generate the noise
widthWidth of the 2D space in which to generate the noise
n_heightSize of the discretised grid in the first dimension
n_widthSize of the discretised grid in the second dimensio
seedSeed for randomisation (0 for random seeding)

Definition at line 67 of file perlin_noise.cpp.

mfcpp::PerlinNoiseGenerator::~PerlinNoiseGenerator ( )

Definition at line 80 of file perlin_noise.cpp.

Member Function Documentation

float mfcpp::PerlinNoiseGenerator::accentuate ( float  x) const
inline

Applies a polynomial to accentuate the given value.

Values under 0.5 are pushed towards 0, while values above 0.5 are pushed towards 1.

Parameters
xGiven value
Returns
Accentuated value

Definition at line 195 of file perlin_noise.hpp.

void mfcpp::PerlinNoiseGenerator::configure ( float  height,
float  width,
unsigned int  n_height,
unsigned int  n_width,
unsigned long int  seed = 0 
)

Configures the generator.

Parameters
heightHeight of the 2D space in which to generate the noise
widthWidth of the 2D space in which to generate the noise
n_heightSize of the discretised grid in the first dimension
n_widthSize of the discretised grid in the second dimension
seedSeed for randomisation (0 for random seeding)

Definition at line 86 of file perlin_noise.cpp.

float mfcpp::PerlinNoiseGenerator::dot_dist_grad ( unsigned int  i,
unsigned int  j,
float  x,
float  y 
) const
private

Compute the dot product of the distance vector to the node an the gradient at this node.

Parameters
iIndex of the node for the first dimension
jIndex of the node for the second dimension
xFirst coordinate of the evaluated point
ySecond coordinate of the evaluated point

Definition at line 210 of file perlin_noise.cpp.

float mfcpp::PerlinNoiseGenerator::dot_product ( Vec2d  u,
Vec2d  v 
) const
private

Computes the dot product between two vectors.

Parameters
uFirst vector
vSecond vector
Returns
Dot product between u and v

Definition at line 204 of file perlin_noise.cpp.

double mfcpp::PerlinNoiseGenerator::evaluate ( float  x,
float  y 
) const

Evaluates the perlin noise at a given position.

Parameters
xFirst coordinate where to evaluate
ySecond coordinate where to evaluate
Returns
Perlin noise value at (x, y)

Definition at line 152 of file perlin_noise.cpp.

float mfcpp::PerlinNoiseGenerator::fade ( float  t) const
inlineprivate

Sixth order polynomial to smooth the noise.

Parameters
tNumber between 0 and 1
Returns
6t^5 - 15t^4 + 10t^3

Definition at line 189 of file perlin_noise.hpp.

void mfcpp::PerlinNoiseGenerator::generate ( unsigned long int  seed = 0)

Populates the grid with random gradients from the hash list.

Parameters
seedSeed for randomisation (0 for random seeding)

Definition at line 128 of file perlin_noise.cpp.

void mfcpp::PerlinNoiseGenerator::init_random ( unsigned long int  seed)
private

Initialises random generation.

Parameters
seedSeed to use for initialisation. If 0, random seeding

Definition at line 192 of file perlin_noise.cpp.

float mfcpp::PerlinNoiseGenerator::interpolate ( float  a,
float  b,
float  t 
) const
private

Linear interpolation between two values.

Parameters
aFirst value to interpolate
bSecond value to interpolate
tInterpolation ratio
Returns
Interpolation between a and b

Definition at line 220 of file perlin_noise.cpp.

void mfcpp::PerlinNoiseGenerator::randomise_gradients ( )

Fills the hash list with random gradients.

Definition at line 99 of file perlin_noise.cpp.

Member Data Documentation

std::vector<std::vector<Vec2d> > mfcpp::PerlinNoiseGenerator::gradients_
private

Gradients evaluated at nodes of the grid.

Definition at line 124 of file perlin_noise.hpp.

std::vector<Vec2d> mfcpp::PerlinNoiseGenerator::hash_gradients_
private

Hash list of random gradients.

Definition at line 127 of file perlin_noise.hpp.

float mfcpp::PerlinNoiseGenerator::height_
private

Height of the 2D space in which to generate the noise.

Definition at line 112 of file perlin_noise.hpp.

unsigned int mfcpp::PerlinNoiseGenerator::n_height_
private

Size of the discretised grid in the first dimension.

Definition at line 118 of file perlin_noise.hpp.

unsigned int mfcpp::PerlinNoiseGenerator::n_width_
private

Size of the discretised grid in the second dimension.

Definition at line 121 of file perlin_noise.hpp.

std::random_device mfcpp::PerlinNoiseGenerator::random_device_
private

Seed initialiser for generation of random numbers.

Definition at line 136 of file perlin_noise.hpp.

bool mfcpp::PerlinNoiseGenerator::randomise_seed_
private

Whether to randomise seeding for random numbers.

Definition at line 130 of file perlin_noise.hpp.

unsigned long int mfcpp::PerlinNoiseGenerator::seed_
private

Seed for random numbers when no random seeding.

Definition at line 133 of file perlin_noise.hpp.

float mfcpp::PerlinNoiseGenerator::width_
private

Width of the 2D space in which to generate the noise.

Definition at line 115 of file perlin_noise.hpp.


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