A portable, open-source, coherent noise-generating library for C++

Main Page | Modules | Class Hierarchy | Class List | File List | Class Members

# libnoise

## Modules

group | Models
group | Noise Modules

## Classes

class | noise::Exception
| Abstract base class for libnoise exceptions. More...
class | noise::ExceptionInvalidParam
| Invalid parameter exception. More...
class | noise::ExceptionNoModule
| No module exception. More...
class | noise::ExceptionOutOfMemory
| Out of memory exception. More...
class | noise::ExceptionUnknown
| Unknown exception. More...
struct | noise::module::ControlPoint
| This structure defines a control point. More...

## Typedefs

typedef unsigned int | noise::uint
| Unsigned integer type.
typedef unsigned int | noise::uint32
| 32-bit unsigned integer type.
typedef unsigned short | noise::uint16
| 16-bit unsigned integer type.
typedef unsigned char | noise::uint8
| 8-bit unsigned integer type.
typedef int | noise::int32
| 32-bit signed integer type.
typedef short | noise::int16
| 16-bit signed integer type.
typedef char | noise::int8
| 8-bit signed integer type.

## Enumerations

enum | noise::NoiseQuality { noise::QUALITY_FAST = 0, noise::QUALITY_STD = 1, noise::QUALITY_BEST = 2 }
| Enumerates the noise quality. More...

## Functions

double | noise::CubicInterp (double n0, double n1, double n2, double n3, double a)
| Performs cubic interpolation between two values bound between two other values.
double | noise::LinearInterp (double n0, double n1, double a)
| Performs linear interpolation between two values.
double | noise::SCurve3 (double a)
| Maps a value onto a cubic S-curve.
double | noise::SCurve5 (double a)
| Maps a value onto a quintic S-curve.
void | noise::LatLonToXYZ (double lat, double lon, double &x, double &y, double &z)
| Converts latitude/longitude coordinates on a unit sphere into 3D Cartesian coordinates.
template<class T>
T | noise::GetMax (const T &a, const T &b)
| Returns the maximum of two values.
template<class T>
T | noise::GetMin (const T &a, const T &b)
| Returns the minimum of two values.
template<class T>
void | noise::SwapValues (T &a, T &b)
| Swaps two values.
double | noise::GradientCoherentNoise3D (double x, double y, double z, int seed=0, NoiseQuality noiseQuality=QUALITY_STD)
| Generates a gradient-coherent-noise value from the coordinates of a three-dimensional input value.
double | noise::GradientNoise3D (double fx, double fy, double fz, int ix, int iy, int iz, int seed=0)
| Generates a gradient-noise value from the coordinates of a three-dimensional input value and the integer coordinates of a nearby three-dimensional value.
int | noise::IntValueNoise3D (int x, int y, int z, int seed=0)
| Generates an integer-noise value from the coordinates of a three-dimensional input value.
double | noise::MakeInt32Range (double n)
| Modifies a floating-point value so that it can be stored in a noise::int32 variable.
double | noise::ValueCoherentNoise3D (double x, double y, double z, int seed=0, NoiseQuality noiseQuality=QUALITY_STD)
| Generates a value-coherent-noise value from the coordinates of a three-dimensional input value.
double | noise::ValueNoise3D (int x, int y, int z, int seed=0)
| Generates a value-noise value from the coordinates of a three-dimensional input value.

## Variables

const double | noise::PI = 3.1415926535897932385
| Pi.
const double | noise::SQRT_2 = 1.4142135623730950488
| Square root of 2.
const double | noise::SQRT_3 = 1.7320508075688772935
| Square root of 3.
const double | noise::DEG_TO_RAD = PI / 180.0
| Converts an angle from degrees to radians.
const double | noise::RAD_TO_DEG = 1.0 / DEG_TO_RAD
| Converts an angle from radians to degrees.

## Enumeration Type Documentation

enum NoiseQuality

Enumerates the noise quality.

Enumeration values:

  QUALITY_FAST | Generates coherent noise quickly. When a coherent-noise function with this quality setting is used to generate a bump-map image, there are noticeable "creasing" artifacts in the resulting image. This is because the derivative of that function is discontinuous at integer boundaries.
  QUALITY_STD | Generates standard-quality coherent noise. When a coherent-noise function with this quality setting is used to generate a bump-map image, there are some minor "creasing" artifacts in the resulting image. This is because the second derivative of that function is discontinuous at integer boundaries.
  QUALITY_BEST | Generates the best-quality coherent noise. When a coherent-noise function with this quality setting is used to generate a bump-map image, there are no "creasing" artifacts in the resulting image. This is because the first and second derivatives of that function are continuous at integer boundaries.

## Function Documentation

double CubicInterp | ( | double | n0,
|  | double | n1,
|  | double | n2,
|  | double | n3,
|  | double | a
| ) | `[inline]`

Performs cubic interpolation between two values bound between two other values.

Parameters:

  | n0 | The value before the first value.
  | n1 | The first value.
  | n2 | The second value.
  | n3 | The value after the second value.
  | a | The alpha value.

Returns:
  The interpolated value.

The alpha value should range from 0.0 to 1.0. If the alpha value is 0.0, this function returns n1. If the alpha value is 1.0, this function returns n2.

template<class T>
T GetMax | ( | const T & | a,
|  | const T & | b
| ) |

Returns the maximum of two values.

Parameters:

  | a | The first value.
  | b | The second value.

Returns:
  The maximum of the two values.

template<class T>
T GetMin | ( | const T & | a,
|  | const T & | b
| ) |

Returns the minimum of two values.

Parameters:

  | a | The first value.
  | b | The second value.

Returns:
  The minimum of the two values.

double noise::GradientCoherentNoise3D | ( | double | x,
|  | double | y,
|  | double | z,
|  | int | seed = `0`,
|  | NoiseQuality | noiseQuality = `QUALITY_STD`
| ) |

Generates a gradient-coherent-noise value from the coordinates of a three-dimensional input value.

Parameters:

  | x | The x coordinate of the input value.
  | y | The y coordinate of the input value.
  | z | The z coordinate of the input value.
  | seed | The random number seed.
  | noiseQuality | The quality of the coherent-noise.

Returns:
  The generated gradient-coherent-noise value.

The return value ranges from -1.0 to +1.0.

For an explanation of the difference between gradient noise and value noise, see the comments for the GradientNoise3D() function.

double noise::GradientNoise3D | ( | double | fx,
|  | double | fy,
|  | double | fz,
|  | int | ix,
|  | int | iy,
|  | int | iz,
|  | int | seed = `0`
| ) |

Generates a gradient-noise value from the coordinates of a three-dimensional input value and the integer coordinates of a nearby three-dimensional value.

Parameters:

  | fx | The floating-point x coordinate of the input value.
  | fy | The floating-point y coordinate of the input value.
  | fz | The floating-point z coordinate of the input value.
  | ix | The integer x coordinate of a nearby value.
  | iy | The integer y coordinate of a nearby value.
  | iz | The integer z coordinate of a nearby value.
  | seed | The random number seed.

Returns:
  The generated gradient-noise value.

Precondition:
  The difference between fx and ix must be less than or equal to one.

  The difference between fy and iy must be less than or equal to one.

  The difference between fz and iz must be less than or equal to one.

A gradient-noise function generates better-quality noise than a value-noise function. Most noise modules use gradient noise for this reason, although it takes much longer to calculate.

The return value ranges from -1.0 to +1.0.

This function generates a gradient-noise value by performing the following steps:

- It first calculates a random normalized vector based on the nearby integer value passed to this function.
- It then calculates a new value by adding this vector to the nearby integer value passed to this function.
- It then calculates the dot product of the above-generated value and the floating-point input value passed to this function.

A noise function differs from a random-number generator because it always returns the same output value if the same input value is passed to it.

int noise::IntValueNoise3D | ( | int | x,
|  | int | y,
|  | int | z,
|  | int | seed = `0`
| ) |

Generates an integer-noise value from the coordinates of a three-dimensional input value.

Parameters:

  | x | The integer x coordinate of the input value.
  | y | The integer y coordinate of the input value.
  | z | The integer z coordinate of the input value.
  | seed | A random number seed.

Returns:
  The generated integer-noise value.

The return value ranges from 0 to 2147483647.

A noise function differs from a random-number generator because it always returns the same output value if the same input value is passed to it.

void noise::LatLonToXYZ | ( | double | lat,
|  | double | lon,
|  | double & | x,
|  | double & | y,
|  | double & | z
| ) |

Converts latitude/longitude coordinates on a unit sphere into 3D Cartesian coordinates.

Parameters:

  | lat | The latitude, in degrees.
  | lon | The longitude, in degrees.
  | x | On exit, this parameter contains the x coordinate.
  | y | On exit, this parameter contains the y coordinate.
  | z | On exit, this parameter contains the z coordinate.

Precondition:
  lat must range from -90 to +90.

  lon must range from -180 to +180.

double LinearInterp | ( | double | n0,
|  | double | n1,
|  | double | a
| ) | `[inline]`

Performs linear interpolation between two values.

Parameters:

  | n0 | The first value.
  | n1 | The second value.
  | a | The alpha value.

Returns:
  The interpolated value.

The alpha value should range from 0.0 to 1.0. If the alpha value is 0.0, this function returns n0. If the alpha value is 1.0, this function returns n1.

double MakeInt32Range | ( | double | n | ) | `[inline]`

Modifies a floating-point value so that it can be stored in a noise::int32 variable.

Parameters:

  | n | A floating-point number.

Returns:
  The modified floating-point number.

This function does not modify n.

In libnoise, the noise-generating algorithms are all integer-based; they use variables of type noise::int32. Before calling a noise function, pass the x, y, and z coordinates to this function to ensure that these coordinates can be cast to a noise::int32 value.

Although you could do a straight cast from double to noise::int32, the resulting value may differ between platforms. By using this function, you ensure that the resulting value is identical between platforms.

double SCurve3 | ( | double | a | ) | `[inline]`

Maps a value onto a cubic S-curve.

Parameters:

  | a | The value to map onto a cubic S-curve.

Returns:
  The mapped value.

a should range from 0.0 to 1.0.

The derivitive of a cubic S-curve is zero at a = 0.0 and a = 1.0

double SCurve5 | ( | double | a | ) | `[inline]`

Maps a value onto a quintic S-curve.

Parameters:

  | a | The value to map onto a quintic S-curve.

Returns:
  The mapped value.

a should range from 0.0 to 1.0.

The first derivitive of a quintic S-curve is zero at a = 0.0 and a = 1.0

The second derivitive of a quintic S-curve is zero at a = 0.0 and a = 1.0

template<class T>
void SwapValues | ( | T & | a,
|  | T & | b
| ) |

Swaps two values.

Parameters:

  | a | A variable containing the first value.
  | b | A variable containing the second value.

Postcondition:
  The values within the the two variables are swapped.

double noise::ValueCoherentNoise3D | ( | double | x,
|  | double | y,
|  | double | z,
|  | int | seed = `0`,
|  | NoiseQuality | noiseQuality = `QUALITY_STD`
| ) |

Generates a value-coherent-noise value from the coordinates of a three-dimensional input value.

Parameters:

  | x | The x coordinate of the input value.
  | y | The y coordinate of the input value.
  | z | The z coordinate of the input value.
  | seed | The random number seed.
  | noiseQuality | The quality of the coherent-noise.

Returns:
  The generated value-coherent-noise value.

The return value ranges from -1.0 to +1.0.

For an explanation of the difference between gradient noise and value noise, see the comments for the GradientNoise3D() function.

double noise::ValueNoise3D | ( | int | x,
|  | int | y,
|  | int | z,
|  | int | seed = `0`
| ) |

Generates a value-noise value from the coordinates of a three-dimensional input value.

Parameters:

  | x | The x coordinate of the input value.
  | y | The y coordinate of the input value.
  | z | The z coordinate of the input value.
  | seed | A random number seed.

Returns:
  The generated value-noise value.

The return value ranges from -1.0 to +1.0.

A noise function differs from a random-number generator because it always returns the same output value if the same input value is passed to it.