SourceXtractorPlusPlus  0.16
Please provide a description of the project.
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 <fftw3.h>
28 #include <memory>
29 #include <vector>
30 
31 namespace SourceXtractor {
32 
36 template <typename T>
37 struct FFTTraits {};
38 
42 template <>
43 struct FFTTraits<float> {
44  typedef fftwf_plan_s plan_t;
45  typedef fftwf_complex complex_t;
46  typedef decltype(fftwf_plan_dft_r2c_2d) func_plan_fwd_t;
47  typedef decltype(fftwf_plan_dft_c2r_2d) func_plan_inv_t;
48  typedef decltype(fftwf_destroy_plan) func_destroy_plan_t;
49  typedef decltype(fftwf_execute_dft_r2c) func_execute_fwd_t;
50  typedef decltype(fftwf_execute_dft_c2r) func_execute_inv_t;
51 
52  static func_plan_fwd_t* func_plan_fwd;
53  static func_plan_inv_t* func_plan_inv;
54  static func_destroy_plan_t* func_destroy_plan;
55  static func_execute_fwd_t* func_execute_fwd;
56  static func_execute_inv_t* func_execute_inv;
57 };
58 
62 template <>
63 struct FFTTraits<double> {
64  typedef fftw_plan_s plan_t;
65  typedef fftw_complex complex_t;
66  typedef decltype(fftw_plan_dft_r2c_2d) func_plan_fwd_t;
67  typedef decltype(fftw_plan_dft_c2r_2d) func_plan_inv_t;
68  typedef decltype(fftw_destroy_plan) func_destroy_plan_t;
69  typedef decltype(fftw_execute_dft_r2c) func_execute_fwd_t;
70  typedef decltype(fftw_execute_dft_c2r) func_execute_inv_t;
71 
72  static func_plan_fwd_t* func_plan_fwd;
73  static func_plan_inv_t* func_plan_inv;
74  static func_destroy_plan_t* func_destroy_plan;
75  static func_execute_fwd_t* func_execute_fwd;
76  static func_execute_inv_t* func_execute_inv;
77 };
78 
85 template <typename T>
86 struct FFT {
87  static_assert(std::is_floating_point<T>::value, "FFTTraits only supported for floating point types");
88 
90 
92  typedef typename fftw_traits::complex_t complex_t;
93 
107  static plan_ptr_t createForwardPlan(int width, int height, std::vector<T>& inout);
108 
122  static plan_ptr_t createInversePlan(int width, int height, std::vector<T>& inout);
123 
131  static void executeForward(plan_ptr_t& plan, std::vector<T>& inout);
132 
140  static void executeInverse(plan_ptr_t& plan, std::vector<T>& inout);
141 };
142 
155 int fftRoundDimension(int size);
156 
157 extern template struct FFT<float>;
158 extern template struct FFT<double>;
159 
160 } // namespace SourceXtractor
161 
162 #endif // _SEFRAMEWORK_FFT_FFT_H
int fftRoundDimension(int size)
Definition: FFT.cpp:49
decltype(fftw_plan_dft_c2r_2d) typedef func_plan_inv_t
Definition: FFT.h:67
static func_plan_inv_t * func_plan_inv
Definition: FFT.h:73
static func_destroy_plan_t * func_destroy_plan
Definition: FFT.h:74
decltype(fftw_destroy_plan) typedef func_destroy_plan_t
Definition: FFT.h:68
static func_execute_inv_t * func_execute_inv
Definition: FFT.h:76
static func_plan_fwd_t * func_plan_fwd
Definition: FFT.h:72
decltype(fftw_execute_dft_c2r) typedef func_execute_inv_t
Definition: FFT.h:70
decltype(fftw_plan_dft_r2c_2d) typedef func_plan_fwd_t
Definition: FFT.h:66
static func_execute_fwd_t * func_execute_fwd
Definition: FFT.h:75
decltype(fftw_execute_dft_r2c) typedef func_execute_fwd_t
Definition: FFT.h:69
static func_execute_fwd_t * func_execute_fwd
Definition: FFT.h:55
static func_plan_fwd_t * func_plan_fwd
Definition: FFT.h:52
decltype(fftwf_execute_dft_r2c) typedef func_execute_fwd_t
Definition: FFT.h:49
static func_destroy_plan_t * func_destroy_plan
Definition: FFT.h:54
static func_execute_inv_t * func_execute_inv
Definition: FFT.h:56
static func_plan_inv_t * func_plan_inv
Definition: FFT.h:53
decltype(fftwf_plan_dft_r2c_2d) typedef func_plan_fwd_t
Definition: FFT.h:46
decltype(fftwf_plan_dft_c2r_2d) typedef func_plan_inv_t
Definition: FFT.h:47
decltype(fftwf_execute_dft_c2r) typedef func_execute_inv_t
Definition: FFT.h:50
decltype(fftwf_destroy_plan) typedef func_destroy_plan_t
Definition: FFT.h:48
Wrap FFTW types and functions depending on the primitive type (float or double)
Definition: FFT.h:37
Wraps the FFTW API with a more C++ like one.
Definition: FFT.h:86
std::shared_ptr< typename fftw_traits::plan_t > plan_ptr_t
Definition: FFT.h:91
static void executeInverse(plan_ptr_t &plan, std::vector< T > &inout)
Definition: FFT.cpp:196
static plan_ptr_t createForwardPlan(int width, int height, std::vector< T > &inout)
Definition: FFT.cpp:111
fftw_traits::complex_t complex_t
Definition: FFT.h:92
static plan_ptr_t createInversePlan(int width, int height, std::vector< T > &inout)
Definition: FFT.cpp:151
FFTTraits< T > fftw_traits
Definition: FFT.h:87
static void executeForward(plan_ptr_t &plan, std::vector< T > &inout)
Definition: FFT.cpp:191