NoiseGen1 Class Reference

#include <noise1.h>

Inheritance diagram for NoiseGen1:

NoiseBase List of all members.

Public Member Functions

 NoiseGen1 ()
virtual ~NoiseGen1 ()
virtual BOOL Initialise ()
 Initialise all the data tables we need to get this noise generator going. This particular table holds random float values in the range [0..1].
virtual double VNoise1D (const Vector3D &v, double s)
virtual Vector3D VNoise3D (const Vector3D &v)
 Vector-valued version of "Noise".
virtual void SeedTable (UINT32 seed)
 Seed the random number table we use.

Private Attributes

float * RTable

Detailed Description

Aurthor: Mike
Date:
07/07/96 Notes:

Definition at line 118 of file noise1.h.


Constructor & Destructor Documentation

NoiseGen1::NoiseGen1  ) 
 

Definition at line 122 of file noise1.cpp.

00123 {
00124     RTable=NULL;
00125 }

NoiseGen1::~NoiseGen1  )  [virtual]
 

Definition at line 131 of file noise1.cpp.

00132 {
00133     if (RTable!=NULL)
00134     {
00135         free((void*)RTable);
00136         RTable=NULL;
00137     }
00138 }


Member Function Documentation

BOOL NoiseGen1::Initialise  )  [virtual]
 

Initialise all the data tables we need to get this noise generator going. This particular table holds random float values in the range [0..1].

Aurthor: Mike

Date:
07/07/96

Implements NoiseBase.

Definition at line 152 of file noise1.cpp.

00153 {
00154     // allocate some space big enough
00155     RTable = (float*)malloc(MAXPTS * sizeof(float));
00156     if (RTable==NULL)
00157         return FALSE;
00158 
00159     // create the table
00160     SeedTable(0);
00161     return TRUE;
00162 }

void NoiseGen1::SeedTable UINT32  seed  )  [virtual]
 

Seed the random number table we use.

Aurthor: Mike

Date:
07/07/96
Parameters:
seed = the seed to use as an initial value in our random number table [INPUTS]

Implements NoiseBase.

Definition at line 176 of file noise1.cpp.

00177 {
00178     if (RTable!=NULL)
00179     {
00180         // seed the random number generator for consitency
00181         srand(seed);
00182         // now create those random impulses!
00183         // ok I'm assuming rand() will be compiled in and not a opsys level call.
00184         for (INT32 i=0; i<MAXPTS; i++)
00185             RTable[i] = (float)rand() / ((float)RAND_MAX);
00186     }
00187 }

double NoiseGen1::VNoise1D const Vector3D p,
double  scale
[virtual]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/97
Parameters:
p = a three dimensional vector [INPUTS] scale = a scaling factor
Returns:
A double f, 0<=f<=1.0
Notes: Uses 2d quadratic B-Spline smoothing

1d quadratic bsplines are defined as...

C0 = 1 - 2u + u^2 C1 = 1 + 2u - 2u^2 C2 = u^2

v = (C0*p0 + C1*p1 + C2*p2)/2 0<=u<=1

Note, this spline is a none-interpolating spline, i.e. it tends towards the points but never passes through any! This doesn't matter to us as we're interpolating random impulses. To make our tile cyclic, wrap coordinates at the edges. Also note, give points { p0,p1,p2 } the curve lives in the region [p0,p1] i.e. it is does not cover all p0..p2. To get segment [p1,p2] you'll need { p1,p2,p3 } Calculating the cyclic curve through p0,p1,p2,p3 fit... [p0,p1] = CF{ p0,p1,p2 } [p1,p2] = CF{ p1,p2,p3 } [p2,p3] = CF{ p2,p3,p0 } [P3,P0] = CF{ p3,p0,p1 } i.e. 4 input points = 4 curves = 4 intervals

Implements NoiseBase.

Definition at line 227 of file noise1.cpp.

00228 {
00229     float  x2, x1, x0, y2, y1, y0, xf, yf;
00230     float  p00, p01, p02;
00231     INT32    ax, bx, cx;
00232     INT32    ay, by, cy;
00233     INT32    samplerange;
00234 
00235     // multiplying by TABLEWIDTH rather than (TABLEWIDTH-1)
00236     // forces a wrapping as our range is 0..TABLEWIDTH-1
00237     samplerange = (INT32)(scale); // *TABLEWIDTH);
00238 
00239     if (samplerange<1)
00240         return 0.0;
00241     
00242     // essentially ignore p.z (the calling routine sets it to 0)
00243     xf = ((float)p.x) * samplerange;
00244     yf = ((float)p.y) * samplerange;
00245     
00246     // index the 9 random impulses we'll used for (xf,yf)
00247     ax = (INT32)floor(xf);
00248     ay = (INT32)floor(yf);
00249 
00250     // calculate the 2d bspline blending coefs
00251     xf = xf - ax;               // u        (i.e. fract(p.x) 0..1)
00252     yf = yf - ay;               // v        (i.e. fract(p.y) 0..1)
00253     x1 = xf * xf;               // u^2
00254     y1 = yf * yf;               // v^2
00255     x2 = 0.5f * x1;             // u^2/2
00256     y2 = 0.5f * y1;             // v^2/2
00257     x1 = 0.5f + xf - x1;        // 0.5 + u - u^2
00258     y1 = 0.5f + yf - y1;        // 0.5 + v - v^2
00259     x0 = 0.5f - xf + x2;        // 0.5 - u + u^2/2
00260     y0 = 0.5f - yf + y2;        // 0.5 - v + v^2/2
00261 
00262     // get the next neighbours
00263     bx = ax + 1;
00264     by = ay + 1;
00265     cx = bx + 1;
00266     cy = by + 1;
00267 
00268     // do a potential double modulus as follows...
00269     //
00270     // 0 1 2 3 4 5 6 7 8 9  a b c d e f       index into impulse table
00271     // 0 1 2 3 4 5 6 7 0 1  2 3 4 5 6 7  ...  samplerange == 8
00272     // 0 1 2 3 4 0 1 2 0 1  2 3 4 0 1 2  ...   tablewidth == 5
00273     // ^               ^
00274     // notice the important symmetry of the values at either end of sample range
00275     // this gives tileable noise.
00276 
00277     ax = ax % samplerange;      // all 0 if samplerange == 1
00278     ay = ay % samplerange;
00279     bx = bx % samplerange;
00280     by = by % samplerange;
00281     cx = cx % samplerange;
00282     cy = cy % samplerange;
00283 
00284     if (samplerange==1)         // do something at zero if poss
00285         cx=cy=1;        
00286 
00287     if (TABLEWIDTH<samplerange)
00288     {
00289         // if our random impulse table is smaller than samplerange
00290         // then we need to mod into it.
00291         ax = ax % TABLEWIDTH;
00292         ay = ay % TABLEWIDTH;
00293         bx = bx % TABLEWIDTH;
00294         by = by % TABLEWIDTH;
00295         cx = cx % TABLEWIDTH;
00296         cy = cy % TABLEWIDTH;
00297     }
00298 
00299     ay*=TABLEWIDTH;
00300     by*=TABLEWIDTH;
00301     cy*=TABLEWIDTH;
00302 
00303     // read and interpolate the impulse values
00304     p00 = RTable[ax+ay];
00305     p01 = RTable[bx+ay];
00306     p02 = RTable[cx+ay];
00307 
00308     xf  = y0 * (x0*p00 + x1*p01 + x2*p02);
00309 
00310     p00 = RTable[ax+by];
00311     p01 = RTable[bx+by];
00312     p02 = RTable[cx+by];
00313 
00314     xf += y1 * (x0*p00 + x1*p01 + x2*p02);
00315 
00316     p00 = RTable[ax+cy];
00317     p01 = RTable[bx+cy];
00318     p02 = RTable[cx+cy];
00319 
00320     xf += y2 * (x0*p00 + x1*p01 + x2*p02);
00321     
00322     return (double)xf;
00323 }

Vector3D NoiseGen1::VNoise3D const Vector3D v  )  [virtual]
 

Vector-valued version of "Noise".

Implements NoiseBase.

Definition at line 420 of file noise1.cpp.

00421 {
00422     return Vector3D(0,0,0);
00423 }


Member Data Documentation

float* NoiseGen1::RTable [private]
 

Definition at line 131 of file noise1.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:13 2007 for Camelot by  doxygen 1.4.4