SourceXtractorPlusPlus  0.10
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FFT.h
Go to the documentation of this file.
1 
17 /*
18  * @file SEFramework/FFT/FFT.h
19  * @date 11/09/18
20  * @author Alejandro Alvarez Ayllon
21  */
22 
23 #ifndef _SEFRAMEWORK_FFT_FFT_H
24 #define _SEFRAMEWORK_FFT_FFT_H
25 
26 #include <complex>
27 #include <memory>
28 #include <fftw3.h>
29 
30 
31 namespace SourceXtractor {
32 
36 template <typename T>
37 struct FFTTraits {
38 };
39 
43 template <>
44 struct FFTTraits<float> {
45  typedef fftwf_plan_s plan_t;
46  typedef fftwf_complex complex_t;
47  typedef decltype(fftwf_plan_many_dft_r2c) func_plan_fwd_t;
48  typedef decltype(fftwf_plan_many_dft_c2r) func_plan_inv_t;
49  typedef decltype(fftwf_destroy_plan) func_destroy_plan_t;
50  typedef decltype(fftwf_execute_dft_r2c) func_execute_fwd_t;
51  typedef decltype(fftwf_execute_dft_c2r) func_execute_inv_t;
52 
53  static func_plan_fwd_t *func_plan_fwd;
54  static func_plan_inv_t *func_plan_inv;
55  static func_destroy_plan_t *func_destroy_plan;
56  static func_execute_fwd_t *func_execute_fwd;
57  static func_execute_inv_t *func_execute_inv;
58 };
59 
63 template <>
64 struct FFTTraits<double> {
65  typedef fftw_plan_s plan_t;
66  typedef fftw_complex complex_t;
67  typedef decltype(fftw_plan_many_dft_r2c) func_plan_fwd_t;
68  typedef decltype(fftw_plan_many_dft_c2r) func_plan_inv_t;
69  typedef decltype(fftw_destroy_plan) func_destroy_plan_t;
70  typedef decltype(fftw_execute_dft_r2c) func_execute_fwd_t;
71  typedef decltype(fftw_execute_dft_c2r) func_execute_inv_t;
72 
73  static func_plan_fwd_t *func_plan_fwd;
74  static func_plan_inv_t *func_plan_inv;
75  static func_destroy_plan_t *func_destroy_plan;
76  static func_execute_fwd_t *func_execute_fwd;
77  static func_execute_inv_t *func_execute_inv;
78 };
79 
86 template<typename T>
87 struct FFT {
88  static_assert(std::is_floating_point<T>::value, "FFTTraits only supported for floating point types");
89 
90  typedef FFTTraits<T> fftw_traits;
91 
94 
112  static plan_ptr_t
113  createForwardPlan(int howmany, int width, int height, std::vector<T> &in, std::vector<complex_t> &out);
114 
132  static plan_ptr_t
133  createInversePlan(int howmany, int width, int height, std::vector<complex_t> &in, std::vector<T> &out);
134 
144  static void executeForward(plan_ptr_t &plan, std::vector<T> &in, std::vector<complex_t> &out);
145 
155  static void executeInverse(plan_ptr_t &plan, std::vector<complex_t> &in, std::vector<T> &out);
156 };
157 
170 int fftRoundDimension(int size);
171 
172 } // end SourceXtractor
173 
174 #endif // _SEFRAMEWORK_FFT_FFT_H
Wrap FFTW types and functions depending on the primitive type (float or double)
Definition: FFT.h:37
STL class.
Wraps the FFTW API with a more C++ like one.
Definition: FFT.h:87
FFTTraits< T > fftw_traits
Definition: FFT.h:88
std::shared_ptr< typename fftw_traits::plan_t > plan_ptr_t
Definition: FFT.h:92
STL class.
int fftRoundDimension(int size)
Definition: FFT.cpp:49
std::complex< T > complex_t
Definition: FFT.h:93