Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FFT.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __FFT_hh__
27 #define __FFT_hh__
28 
29 #include <bias_config.h>
30 #include <Base/Common/W32Compat.hh>
31 #include <math.h>
32 
33 #include <Base/Debug/Debug.hh>
34 #include <Base/Math/Vector.hh>
35 
36 #include <complex>
37 #include <iostream>
38 #include <fftw3.h>
39 
40 namespace BIAS {
41 
42 
43 /**
44  * @class FFT
45  @ingroup g_mathalgo
46  @brief Wrapper to the fftw3 library.
47  @note Use fast as follows:
48  - call Init() with appropriate size
49  - call GetInput() and fill it with data
50  - call Compute()
51  - get Results with GetPhase(), GetMagnitude() or GetRes()
52 
53  a slow interface for Vector<double> also exists
54  an example exists in Examples/ExampleFFT, see ExampleFFT.cpp
55  @author woelk 03/2004
56 */
57  class BIASMathAlgo_EXPORT FFT : public Debug
58  {
59 
60  public:
61  FFT();
62  ~FFT();
63 
64  /** initializes the internal variables. This may take some time
65  (i.e. several seconds) since some measurements are done */
66  void Init(int size);
67 
68  /** cal this before a second call to Init() */
69  void Release();
70 
71  /** returns the internal data. Do _not_ delete */
72  inline double *GetInput()
73  { return _in; }
74 
75  /** slow, memcopys in to internal input data */
76  void Compute(double *in);
77 
78  /** slow, memcopys in to internal input data */
79  void Compute(Vector<double> &in);
80 
81  /** input must be filled before with GetInput */
82  inline void Compute()
83  { fftw_execute(_p); }
84 
85  /** returns the resulting phase, phase must be of length
86  size/2+1 (rounded downwards) */
87  void GetPhase(double *phase);
88 
89  /** returns the resulting magnitude, mag must be of length
90  size/2+1 (rounded downwards) */
91  void GetMagnitude(double *mag);
92 
93  /** returns the internal data. Do _not_ delete
94  res is of length size/2+1 */
95  inline std::complex<double>* GetResult()
96  { return reinterpret_cast<std::complex<double> *>(_out); }
97 
98  /** returns the magnitude */
99  void GetPhase(Vector<double>& phase);
100 
101  /** returns the phase */
102  void GetMagnitude(Vector<double>& mag);
103 
104  void DumpResult(std::ostream& os=std::cout);
105 
106  protected:
107  fftw_complex *_out;
108  double *_in;
109  fftw_plan _p;
110  size_t _InputSize; // in bytes
111  int _Size; // length of input
112  int _OutNum; // length of output = _Size/2 + 1
113  };
114 
115 } // namespace
116 
117 #endif // __FFT_hh__
int _Size
Definition: FFT.hh:111
fftw_plan _p
Definition: FFT.hh:109
Wrapper to the fftw3 library.
Definition: FFT.hh:57
std::complex< double > * GetResult()
returns the internal data.
Definition: FFT.hh:95
double * GetInput()
returns the internal data.
Definition: FFT.hh:72
size_t _InputSize
Definition: FFT.hh:110
void Compute()
input must be filled before with GetInput
Definition: FFT.hh:82
int _OutNum
Definition: FFT.hh:112
double * _in
Definition: FFT.hh:108
fftw_complex * _out
Definition: FFT.hh:107