diff options
author | Daniel Genrich <daniel.genrich@gmx.net> | 2009-08-09 05:30:32 +0400 |
---|---|---|
committer | Daniel Genrich <daniel.genrich@gmx.net> | 2009-08-09 05:30:32 +0400 |
commit | d48ca69985ce3f20db89650b0050b04c903b1815 (patch) | |
tree | d3781e2498aa3631c6940a85ca543eb067582f9f /intern/smoke | |
parent | 18121524dd626cc9fec510220ff5f808fe3bd5b9 (diff) |
Smoke: decoupling of wavelet #2, new noise strength option on gui, fftw3 option in place for cmake, scons yet uncommited
Diffstat (limited to 'intern/smoke')
-rw-r--r-- | intern/smoke/CMakeLists.txt | 7 | ||||
-rw-r--r-- | intern/smoke/extern/smoke_API.h | 12 | ||||
-rw-r--r-- | intern/smoke/intern/FFT_NOISE.h | 2 | ||||
-rw-r--r-- | intern/smoke/intern/FLUID_3D.cpp | 33 | ||||
-rw-r--r-- | intern/smoke/intern/FLUID_3D.h | 4 | ||||
-rw-r--r-- | intern/smoke/intern/WTURBULENCE.cpp | 27 | ||||
-rw-r--r-- | intern/smoke/intern/WTURBULENCE.h | 9 | ||||
-rw-r--r-- | intern/smoke/intern/smoke_API.cpp | 41 |
8 files changed, 84 insertions, 51 deletions
diff --git a/intern/smoke/CMakeLists.txt b/intern/smoke/CMakeLists.txt index 90768e58be0..221bc911d20 100644 --- a/intern/smoke/CMakeLists.txt +++ b/intern/smoke/CMakeLists.txt @@ -24,8 +24,7 @@ # # ***** END GPL LICENSE BLOCK ***** -SET(INC ${PNG_INC} ${ZLIB_INC} intern ../../extern/bullet2/src ../memutil ../guardealloc) -# ${FFTW3_INC} +SET(INC ${PNG_INC} ${ZLIB_INC} intern ../../extern/bullet2/src ../memutil ../guardealloc ${FFTW3_INC}) FILE(GLOB SRC intern/*.cpp) @@ -33,6 +32,10 @@ IF(WITH_OPENMP) ADD_DEFINITIONS(-DPARALLEL=1) ENDIF(WITH_OPENMP) +IF(WITH_FFTW3) + ADD_DEFINITIONS(-DFFTW3=1) +ENDIF(WITH_FFTW3) + BLENDERLIB(bf_smoke "${SRC}" "${INC}") #, libtype='blender', priority = 0 ) diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h index b7819d06edc..ba14a247bf1 100644 --- a/intern/smoke/extern/smoke_API.h +++ b/intern/smoke/extern/smoke_API.h @@ -36,11 +36,9 @@ struct FLUID_3D *smoke_init(int *res, int amplify, float *p0, float *p1, float d void smoke_free(struct FLUID_3D *fluid); void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta); - void smoke_step(struct FLUID_3D *fluid); float *smoke_get_density(struct FLUID_3D *fluid); -float *smoke_get_bigdensity(struct FLUID_3D *fluid); float *smoke_get_heat(struct FLUID_3D *fluid); float *smoke_get_velocity_x(struct FLUID_3D *fluid); float *smoke_get_velocity_y(struct FLUID_3D *fluid); @@ -51,9 +49,15 @@ unsigned char *smoke_get_obstacle(struct FLUID_3D *fluid); size_t smoke_get_index(int x, int max_x, int y, int max_y, int z); size_t smoke_get_index2d(int x, int max_x, int y); -void smoke_set_noise(struct FLUID_3D *fluid, int type); +// wavelet turbulence functions +struct WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype); +void smoke_turbulence_free(struct WTURBULENCE *wt); +void smoke_turbulence_step(struct WTURBULENCE *wt, struct FLUID_3D *fluid); -void smoke_get_bigres(struct FLUID_3D *fluid, int *res); +float *smoke_turbulence_get_density(struct WTURBULENCE *wt); +void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res); +void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type); +void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength); #ifdef __cplusplus } diff --git a/intern/smoke/intern/FFT_NOISE.h b/intern/smoke/intern/FFT_NOISE.h index 9ae9682e2a0..e1000f72fb3 100644 --- a/intern/smoke/intern/FFT_NOISE.h +++ b/intern/smoke/intern/FFT_NOISE.h @@ -22,7 +22,7 @@ #ifndef FFT_NOISE_H_ #define FFT_NOISE_H_ -#if 0 +#if FFTW3==1 #include <iostream> #include <fftw3.h> #include <MERSENNETWISTER.h> diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp index 5f40a823238..7e3a00417c1 100644 --- a/intern/smoke/intern/FLUID_3D.cpp +++ b/intern/smoke/intern/FLUID_3D.cpp @@ -59,10 +59,12 @@ FLUID_3D::FLUID_3D(int *res, int amplify, float *p0, float dt) : _maxRes = MAX3(_xRes, _yRes, _zRes); // initialize wavelet turbulence + /* if(amplify) - _wTurbulence = new WTURBULENCE(_res[0],_res[1],_res[2], amplify); + _wTurbulence = new WTURBULENCE(_res[0],_res[1],_res[2], amplify, noisetype); else _wTurbulence = NULL; + */ // scale the constants according to the refinement of the grid _dx = 1.0f / (float)_maxRes; @@ -196,7 +198,7 @@ FLUID_3D::~FLUID_3D() if (_h) delete[] _h; if (_Precond) delete[] _Precond; if (_obstacles) delete[] _obstacles; - if (_wTurbulence) delete _wTurbulence; + // if (_wTurbulence) delete _wTurbulence; printf("deleted fluid\n"); } @@ -206,10 +208,6 @@ void FLUID_3D::initBlenderRNA(float *alpha, float *beta) { _alpha = alpha; _beta = beta; - - // XXX TODO DEBUG - // *_alpha = 0; - // *_beta = 0; } ////////////////////////////////////////////////////////////////////// @@ -233,12 +231,12 @@ void FLUID_3D::step() // advect everything advectMacCormack(); - if(_wTurbulence) { - _wTurbulence->stepTurbulenceFull(_dt/_dx, - _xVelocity, _yVelocity, _zVelocity, _obstacles); + // if(_wTurbulence) { + // _wTurbulence->stepTurbulenceFull(_dt/_dx, + // _xVelocity, _yVelocity, _zVelocity, _obstacles); // _wTurbulence->stepTurbulenceReadable(_dt/_dx, // _xVelocity, _yVelocity, _zVelocity, _obstacles); - } + // } /* // no file output float *src = _density; @@ -257,20 +255,7 @@ void FLUID_3D::step() IMAGE::dumpPBRT(_totalSteps, pbrtPrefix, _density, _res[0],_res[1],_res[2]); */ _totalTime += _dt; - _totalSteps++; - - // clear obstacles - for (int i = 0; i < _totalCells; i++) - { - if(_obstacles[i]) - { - _xVelocity[i] = - _yVelocity[i] = - _zVelocity[i] = 0.0f; - _pressure[i] = 0.0f; - } - _obstacles[i] = 0; - } + _totalSteps++; } ////////////////////////////////////////////////////////////////////// diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h index 3e685a8df16..ffda34021c3 100644 --- a/intern/smoke/intern/FLUID_3D.h +++ b/intern/smoke/intern/FLUID_3D.h @@ -27,7 +27,7 @@ #include <cmath> #include <iostream> #include "OBSTACLE.h" -#include "WTURBULENCE.h" +// #include "WTURBULENCE.h" #include "VEC3.h" using namespace std; @@ -115,7 +115,7 @@ class FLUID_3D float _tempAmb; /* ambient temperature */ // WTURBULENCE object, if active - WTURBULENCE* _wTurbulence; + // WTURBULENCE* _wTurbulence; // boundary setting functions void copyBorderAll(float* field); diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp index 022c8f28252..6ce29e2c8cd 100644 --- a/intern/smoke/intern/WTURBULENCE.cpp +++ b/intern/smoke/intern/WTURBULENCE.cpp @@ -43,7 +43,7 @@ static const float persistence = 0.56123f; ////////////////////////////////////////////////////////////////////// // constructor ////////////////////////////////////////////////////////////////////// -WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify) +WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype) { // if noise magnitude is below this threshold, its contribution // is negilgible, so stop evaluating new octaves @@ -53,10 +53,10 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify) _amplify = amplify; // manually adjust the overall amount of turbulence - _strength = 2.; + // DG - RNA-fied _strength = 2.; // add the corresponding octaves of noise - _octaves = (int)log((float)_amplify) / log(2.0f); // XXX DEBUG/ TODO: int casting correct? - dg + _octaves = (int)(log((float)_amplify) / log(2.0f) + 0.5); // XXX DEBUG/ TODO: int casting correct? - dg // noise resolution _xResBig = _amplify * xResSm; @@ -136,8 +136,11 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify) // noise tiles _noiseTile = new float[noiseTileSize * noiseTileSize * noiseTileSize]; + /* std::string noiseTileFilename = std::string("noise.wavelets"); generateTile_WAVELET(_noiseTile, noiseTileFilename); + */ + setNoise(noisetype); /* std::string noiseTileFilename = std::string("noise.fft"); generatTile_FFT(_noiseTile, noiseTileFilename); @@ -182,8 +185,10 @@ void WTURBULENCE::setNoise(int type) if(type == 4) // FFT { // needs fft - // std::string noiseTileFilename = std::string("noise.fft"); - // generatTile_FFT(_noiseTile, noiseTileFilename); + #if FFTW3==1 + std::string noiseTileFilename = std::string("noise.fft"); + generatTile_FFT(_noiseTile, noiseTileFilename); + #endif } else if(type == 8) // curl { @@ -196,6 +201,12 @@ void WTURBULENCE::setNoise(int type) } } +// init direct access functions from blender +void WTURBULENCE::initBlenderRNA(float *strength) +{ + _strength = strength; +} + ////////////////////////////////////////////////////////////////////// // Get the smallest valid x derivative // @@ -642,7 +653,7 @@ void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel, // base amplitude for octave 0 float coefficient = sqrtf(2.0f * fabs(energy)); - const float amplitude = _strength * fabs(0.5 * coefficient) * persistence; + const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence; // add noise to velocity, but only if the turbulence is // sufficiently undeformed, and the energy is large enough @@ -854,7 +865,7 @@ void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, floa // base amplitude for octave 0 float coefficient = sqrtf(2.0f * fabs(energy)); - const float amplitude = _strength * fabs(0.5 * coefficient) * persistence; + const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence; // add noise to velocity, but only if the turbulence is // sufficiently undeformed, and the energy is large enough @@ -925,7 +936,7 @@ void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, floa maxVelMag = sqrt(maxVelMag) * dt; int totalSubsteps = (int)(maxVelMag / (float)maxVel); totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; - + // printf("totalSubsteps: %d\n", totalSubsteps); totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; const float dtSubdiv = dt / (float)totalSubsteps; diff --git a/intern/smoke/intern/WTURBULENCE.h b/intern/smoke/intern/WTURBULENCE.h index 858a47b7dd1..d4e6b0c6a17 100644 --- a/intern/smoke/intern/WTURBULENCE.h +++ b/intern/smoke/intern/WTURBULENCE.h @@ -33,12 +33,13 @@ class WTURBULENCE { public: // both config files can be NULL, altCfg might override values from noiseCfg - WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify); + WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype); /// destructor virtual ~WTURBULENCE(); void setNoise(int type); + void initBlenderRNA(float *strength); // step more readable version -- no rotation correction void stepTurbulenceReadable(float dt, float* xvel, float* yvel, float* zvel, unsigned char *obstacles); @@ -69,13 +70,15 @@ class WTURBULENCE inline Vec3Int getResBig() { return _resBig; } inline int getOctaves() { return _octaves; } + // is accessed on through rna gui + float *_strength; + protected: // enlargement factor from original velocity field / simulation // _Big = _amplify * _Sm int _amplify; int _octaves; - float _strength; - + // noise settings float _cullingThreshold; float _noiseStrength; diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp index 281761bd387..7d476191c90 100644 --- a/intern/smoke/intern/smoke_API.cpp +++ b/intern/smoke/intern/smoke_API.cpp @@ -26,6 +26,7 @@ */ #include "FLUID_3D.h" +#include "WTURBULENCE.h" #include <stdio.h> #include <stdlib.h> @@ -41,22 +42,48 @@ extern "C" FLUID_3D *smoke_init(int *res, int amplify, float *p0, float *p1, flo return fluid; } +extern "C" WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype) +{ + // initialize wavelet turbulence + if(amplify) + return new WTURBULENCE(res[0],res[1],res[2], amplify, noisetype); + else + return NULL; +} + extern "C" void smoke_free(FLUID_3D *fluid) { delete fluid; fluid = NULL; } +extern "C" void smoke_turbulence_free(WTURBULENCE *wt) +{ + delete wt; + wt = NULL; +} + extern "C" void smoke_step(FLUID_3D *fluid) { fluid->step(); } +extern "C" void smoke_turbulence_step(WTURBULENCE *wt, FLUID_3D *fluid) +{ + if(wt) + wt->stepTurbulenceFull(fluid->_dt/fluid->_dx, fluid->_xVelocity, fluid->_yVelocity, fluid->_zVelocity, fluid->_obstacles); +} + extern "C" void smoke_initBlenderRNA(FLUID_3D *fluid, float *alpha, float *beta) { fluid->initBlenderRNA(alpha, beta); } +extern "C" void smoke_initWaveletBlenderRNA(WTURBULENCE *wt, float *strength) +{ + wt->initBlenderRNA(strength); +} + template < class T > inline T ABS( T a ) { return (0 < a) ? a : -a ; } @@ -86,16 +113,16 @@ extern "C" float *smoke_get_velocity_z(FLUID_3D *fluid) return fluid->_zVorticity; } -extern "C" float *smoke_get_bigdensity(FLUID_3D *fluid) +extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt) { - return fluid->_wTurbulence ? fluid->_wTurbulence->getDensityBig() : NULL; + return wt ? wt->getDensityBig() : NULL; } -extern "C" void smoke_get_bigres(FLUID_3D *fluid, int *res) +extern "C" void smoke_turbulence_get_res(WTURBULENCE *wt, int *res) { - if(fluid->_wTurbulence) + if(wt) { - Vec3Int r = fluid->_wTurbulence->getResBig(); + Vec3Int r = wt->getResBig(); res[0] = r[0]; res[1] = r[1]; res[2] = r[2]; @@ -118,7 +145,7 @@ extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z return x + y * max_x; } -extern "C" void smoke_set_noise(FLUID_3D *fluid, int type) +extern "C" void smoke_turbulence_set_noise(WTURBULENCE *wt, int type) { - fluid->_wTurbulence->setNoise(type); + wt->setNoise(type); } |