RigsofRods
Soft-body Physics Simulation
FFT.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 */
24 
25 #ifndef _Hydrax_Noise_FFT_H_
26 #define _Hydrax_Noise_FFT_H_
27 
28 
29 
30 #include "Noise.h"
31 
32 #include <complex>
33 
36 
39 
40 namespace Hydrax{ namespace Noise
41 {
44  class FFT : public Noise
45  {
46  public:
49  struct Options
50  {
56  float Scale;
58  Ogre::Vector2 WindDirection;
62  float KwPower;
64  float Amplitude;
65 
69  float GPU_Strength;
78  Ogre::Vector3 GPU_LODParameters;
79 
83  : Resolution(128)
84  , PhysicalResolution(32.0f)
85  , Scale(0.25f)
86  , WindDirection(Ogre::Vector2(4,5))
87  , AnimationSpeed(1)
88  , KwPower(6.0f)
89  , Amplitude(1.0f)
90  , GPU_Strength(2.0f)
91  , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
92  {
93  }
94 
104  Options(const int& _Resolution,
105  const float& _PhysicalResolution,
106  const float& _Scale,
107  const Ogre::Vector2& _WindDirection,
108  const float& _AnimationSpeed,
109  const float& _KwPower,
110  const float& _Amplitude)
111  : Resolution(_Resolution)
112  , PhysicalResolution(_PhysicalResolution)
113  , Scale(_Scale)
114  , WindDirection(_WindDirection)
115  , AnimationSpeed(_AnimationSpeed)
116  , KwPower(_KwPower)
117  , Amplitude(_Amplitude)
118  , GPU_Strength(2.0f)
119  , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
120  {
121  }
122 
134  Options(const int& _Resolution,
135  const float& _PhysicalResolution,
136  const float& _Scale,
137  const Ogre::Vector2& _WindDirection,
138  const float& _AnimationSpeed,
139  const float& _KwPower,
140  const float& _Amplitude,
141  const float &_GPU_Strength,
142  const Ogre::Vector3 &_GPU_LODParameters)
143  : Resolution(_Resolution)
144  , PhysicalResolution(_PhysicalResolution)
145  , Scale(_Scale)
146  , WindDirection(_WindDirection)
147  , AnimationSpeed(_AnimationSpeed)
148  , KwPower(_KwPower)
149  , Amplitude(_Amplitude)
150  , GPU_Strength(_GPU_Strength)
151  , GPU_LODParameters(_GPU_LODParameters)
152  {
153  }
154  };
155 
158  FFT();
159 
163  FFT(const Options &Options);
164 
167  ~FFT();
168 
171  void create();
172 
178 
181  void remove();
182 
186  void update(const Ogre::Real &timeSinceLastFrame);
187 
191  void saveCfg(Ogre::String &Data);
192 
196  bool loadCfg(Ogre::ConfigFile &CfgFile);
197 
203  float getValue(const float &x, const float &y);
204 
208  void setOptions(const Options &Options);
209 
213  inline const Options& getOptions() const
214  {
215  return mOptions;
216  }
217 
218  private:
221  void _initNoise();
222 
226  void _calculeNoise(const float &delta);
227 
230  void _executeInverseFFT();
231 
235  void _normalizeFFTData(const float& scale);
236 
243  const float _getPhillipsSpectrum(const Ogre::Vector2& waveVector, const Ogre::Vector2& wind, const float& kwPower_ = 2.0f) const;
244 
248  const float _getGaussianRandomFloat() const;
249 
253 
257  float *re, *img;
260 
262  std::complex<float> *initialWaves;
264  std::complex<float> *currentWaves;
268  float time;
269 
272 
275  };
276 }}
277 
280 
281 #endif
Hydrax::Noise::FFT::currentWaves
std::complex< float > * currentWaves
the data of the simulation at time t, which is formed using the data at time 0 and the angular freque...
Definition: FFT.h:264
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Noise::FFT::_executeInverseFFT
void _executeInverseFFT()
Execute inverse fast fourier transform.
Definition: FFT.cpp:547
Hydrax::Noise::FFT::_initNoise
void _initNoise()
Initialize noise.
Definition: FFT.cpp:433
Hydrax::Noise::FFT::~FFT
~FFT()
Destructor.
Definition: FFT.cpp:66
Hydrax::Noise::FFT::_getGaussianRandomFloat
const float _getGaussianRandomFloat() const
Get a Gaussian random number with mean 0 and standard deviation 1, using Box - muller transform.
Definition: FFT.cpp:506
Hydrax::Noise::FFT::Options::AnimationSpeed
float AnimationSpeed
Animation speed.
Definition: FFT.h:60
Hydrax::Noise::FFT::Options::WindDirection
Ogre::Vector2 WindDirection
Wind direction.
Definition: FFT.h:58
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Noise::FFT::Options::Amplitude
float Amplitude
Noise amplitude.
Definition: FFT.h:64
Hydrax::Noise::FFT::_getPhillipsSpectrum
const float _getPhillipsSpectrum(const Ogre::Vector2 &waveVector, const Ogre::Vector2 &wind, const float &kwPower_=2.0f) const
Get the Philipps Spectrum, used to create the amplitudes and phases.
Definition: FFT.cpp:525
Hydrax::Noise::FFT::getOptions
const Options & getOptions() const
Get current FFT noise options.
Definition: FFT.h:213
Hydrax::Noise::FFT::Options::KwPower
float KwPower
KwPower.
Definition: FFT.h:62
Hydrax::Noise::FFT::createGPUNormalMapResources
bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition: FFT.cpp:175
Hydrax::Noise::FFT::maximalValue
float maximalValue
The minimal value of the result data of the fft transformation.
Definition: FFT.h:259
Hydrax::Noise::FFT::_updateGPUNormalMapResources
void _updateGPUNormalMapResources()
Update gpu normal map resources.
Definition: FFT.cpp:371
Hydrax::GPUNormalMapManager
Class to manager GPU normal maps.
Definition: GPUNormalMapManager.h:45
Hydrax::Noise::FFT::mGPUNormalMapManager
GPUNormalMapManager * mGPUNormalMapManager
GPUNormalMapManager pointer.
Definition: FFT.h:271
Noise.h
Hydrax::Noise::FFT::saveCfg
void saveCfg(Ogre::String &Data)
Save config.
Definition: FFT.cpp:391
Hydrax::Noise::FFT::update
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: FFT.cpp:423
Hydrax::Noise::FFT::Options::GPU_LODParameters
Ogre::Vector3 GPU_LODParameters
LOD Parameters, in order to obtain a smooth normal map we need to decrease the detail level when the ...
Definition: FFT.h:78
Hydrax::Noise::FFT
FFT noise module class.
Definition: FFT.h:44
Hydrax::Noise::FFT::resolution
int resolution
FFT resolution.
Definition: FFT.h:255
Hydrax::Noise::FFT::_calculeNoise
void _calculeNoise(const float &delta)
Calcule noise.
Definition: FFT.cpp:469
Hydrax::Noise::FFT::Options::GPU_Strength
float GPU_Strength
GPU Normal map generator parameters Only if GPU normal map generation is active.
Definition: FFT.h:70
Hydrax::Noise::FFT::setOptions
void setOptions(const Options &Options)
Set/Update fft noise options.
Definition: FFT.cpp:125
Hydrax::Noise::FFT::mOptions
Options mOptions
Perlin noise options.
Definition: FFT.h:274
Hydrax::Noise::FFT::FFT
FFT()
Default constructor.
Definition: FFT.cpp:37
Hydrax::Noise::Noise
Base noise class, Override it for create different ways of create water noise.
Definition: Noise.h:42
Hydrax::Noise::FFT::Options::Scale
float Scale
Noise scale.
Definition: FFT.h:56
Hydrax::Noise::FFT::Options::Options
Options()
Default constructor.
Definition: FFT.h:82
Hydrax::Noise::FFT::create
void create()
Create.
Definition: FFT.cpp:73
Hydrax::Noise::FFT::getValue
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition: FFT.cpp:757
Hydrax::Noise::FFT::angularFrequencies
float * angularFrequencies
the angular frequencies
Definition: FFT.h:266
Hydrax::Noise::FFT::Options::PhysicalResolution
float PhysicalResolution
Physical resolution.
Definition: FFT.h:54
Hydrax::Noise::FFT::Options::Options
Options(const int &_Resolution, const float &_PhysicalResolution, const float &_Scale, const Ogre::Vector2 &_WindDirection, const float &_AnimationSpeed, const float &_KwPower, const float &_Amplitude, const float &_GPU_Strength, const Ogre::Vector3 &_GPU_LODParameters)
User constructor.
Definition: FFT.h:134
Hydrax::Noise::FFT::remove
void remove()
Remove.
Definition: FFT.cpp:85
Hydrax::Noise::FFT::loadCfg
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: FFT.cpp:404
Hydrax::Noise::FFT::img
float * img
Definition: FFT.h:257
Hydrax::Noise::FFT::time
float time
Current time.
Definition: FFT.h:268
Hydrax::Noise::FFT::initialWaves
std::complex< float > * initialWaves
the data which is referred as h0{x,t), that is, the data of the simulation at the time 0.
Definition: FFT.h:262
Hydrax::Noise::FFT::Options::Options
Options(const int &_Resolution, const float &_PhysicalResolution, const float &_Scale, const Ogre::Vector2 &_WindDirection, const float &_AnimationSpeed, const float &_KwPower, const float &_Amplitude)
User constructor.
Definition: FFT.h:104
Hydrax::Noise::FFT::re
float * re
Pointers to resolution*resolution float size arrays.
Definition: FFT.h:257
Ogre
Definition: ExtinguishableFireAffector.cpp:35
Hydrax::Noise::FFT::Options::Resolution
int Resolution
Noise resolution (2^n)
Definition: FFT.h:52
Hydrax::Noise::FFT::_normalizeFFTData
void _normalizeFFTData(const float &scale)
Normalize fft data.
Definition: FFT.cpp:714
x
float x
Definition: (ValueTypes) quaternion.h:5
Hydrax::Noise::FFT::Options
Struct wich contains fft noise module options.
Definition: FFT.h:49