BRL-CAD
noise.h
Go to the documentation of this file.
1 /* N O I S E . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /*----------------------------------------------------------------------*/
22 /* @file noise.h */
23 /** @addtogroup noise */
24 /** @{ */
25 
26 /** @brief
27  *
28  * These noise functions provide mostly random noise at the integer
29  * lattice points. The functions should be evaluated at non-integer
30  * locations for their nature to be realized.
31  *
32  * Contains contributed code from:
33  * F. Kenton Musgrave
34  * Robert Skinner
35  *
36  */
37 
38 #ifndef BN_NOISE_H
39 #define BN_NOISE_H
40 
41 #include "common.h"
42 #include "vmath.h"
43 #include "bn/defines.h"
44 
46 
47 /*
48  * fractal noise support
49  */
50 
51 BN_EXPORT extern void bn_noise_init(void);
52 
53 /**
54  *@brief
55  * Robert Skinner's Perlin-style "Noise" function
56  *
57  * Results are in the range [-0.5 .. 0.5]. Unlike many
58  * implementations, this function provides random noise at the integer
59  * lattice values. However this produces much poorer quality and
60  * should be avoided if possible.
61  *
62  * The power distribution of the result has no particular shape,
63  * though it isn't as flat as the literature would have one believe.
64  */
65 BN_EXPORT extern double bn_noise_perlin(point_t pt);
66 
67 /* FIXME: Why isn't the result listed first? */
68 
69 /**
70  * Vector-valued "Noise"
71  */
72 BN_EXPORT extern void bn_noise_vec(point_t point,
73  point_t result);
74 
75 /**
76  * @brief
77  * Procedural fBm evaluated at "point"; returns value stored in
78  * "value".
79  *
80  * @param point location to sample noise
81  * @param ``h_val'' fractal increment parameter
82  * @param ``lacunarity'' gap between successive frequencies
83  * @param ``octaves'' number of frequencies in the fBm
84  *
85  * The spectral properties of the result are in the APPROXIMATE range
86  * [-1..1] Depending upon the number of octaves computed, this range
87  * may be exceeded. Applications should clamp or scale the result to
88  * their needs. The results have a more-or-less gaussian
89  * distribution. Typical results for 1M samples include:
90  *
91  * @li Min -1.15246
92  * @li Max 1.23146
93  * @li Mean -0.0138744
94  * @li s.d. 0.306642
95  * @li Var 0.0940295
96  *
97  * The function call pow() is relatively expensive. Therefore, this
98  * function pre-computes and saves the spectral weights in a table for
99  * re-use in successive invocations.
100  */
101 BN_EXPORT extern double bn_noise_fbm(point_t point,
102  double h_val,
103  double lacunarity,
104  double octaves);
105 
106 /**
107  * @brief
108  * Procedural turbulence evaluated at "point";
109  *
110  * @return turbulence value for point
111  *
112  * @param point location to sample noise at
113  * @param ``h_val'' fractal increment parameter
114  * @param ``lacunarity'' gap between successive frequencies
115  * @param ``octaves'' number of frequencies in the fBm
116  *
117  * The result is characterized by sharp, narrow trenches in low values
118  * and a more fbm-like quality in the mid-high values. Values are in
119  * the APPROXIMATE range [0 .. 1] depending upon the number of octaves
120  * evaluated. Typical results:
121  @code
122  * Min 0.00857137
123  * Max 1.26712
124  * Mean 0.395122
125  * s.d. 0.174796
126  * Var 0.0305536
127  @endcode
128  * The function call pow() is relatively expensive. Therefore, this
129  * function pre-computes and saves the spectral weights in a table for
130  * re-use in successive invocations.
131  */
132 BN_EXPORT extern double bn_noise_turb(point_t point,
133  double h_val,
134  double lacunarity,
135  double octaves);
136 
137 /**
138  *
139  * From "Texturing and Modeling, A Procedural Approach" 2nd ed
140  */
141 BN_EXPORT extern double bn_noise_mf(point_t point,
142  double h_val,
143  double lacunarity,
144  double octaves,
145  double offset);
146 
147 /**
148  *@brief
149  * A ridged noise pattern
150  *
151  * From "Texturing and Modeling, A Procedural Approach" 2nd ed p338
152  */
153 BN_EXPORT extern double bn_noise_ridged(point_t point,
154  double h_val,
155  double lacunarity,
156  double octaves,
157  double offset);
158 
160 
161 #endif /* BN_NOISE_H */
162 /** @} */
163 /*
164  * Local Variables:
165  * mode: C
166  * tab-width: 8
167  * indent-tabs-mode: t
168  * c-file-style: "stroustrup"
169  * End:
170  * ex: shiftwidth=4 tabstop=8
171  */
double bn_noise_turb(point_t point, double h_val, double lacunarity, double octaves)
Procedural turbulence evaluated at "point";.
Header file for the BRL-CAD common definitions.
double bn_noise_ridged(point_t point, double h_val, double lacunarity, double octaves, double offset)
A ridged noise pattern.
double bn_noise_mf(point_t point, double h_val, double lacunarity, double octaves, double offset)
#define __BEGIN_DECLS
Definition: common.h:73
Coord * point
Definition: chull3d.cpp:52
double bn_noise_perlin(point_t pt)
Robert Skinner's Perlin-style "Noise" function.
void bn_noise_init(void)
These noise functions provide mostly random noise at the integer lattice points. The functions should...
Definition: noise.c:173
double bn_noise_fbm(point_t point, double h_val, double lacunarity, double octaves)
Procedural fBm evaluated at "point"; returns value stored in "value".
#define __END_DECLS
Definition: common.h:74
void bn_noise_vec(point_t point, point_t result)