SourceXtractorPlusPlus  0.11
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 <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
static plan_ptr_t createForwardPlan(int howmany, int width, int height, std::vector< T > &in, std::vector< complex_t > &out)
Definition: FFT.cpp:155
static func_execute_inv_t * func_execute_inv
Definition: FFT.h:57
static func_plan_inv_t * func_plan_inv
Definition: FFT.h:74
static func_plan_fwd_t * func_plan_fwd
Definition: FFT.h:53
static plan_ptr_t createInversePlan(int howmany, int width, int height, std::vector< complex_t > &in, std::vector< T > &out)
Definition: FFT.cpp:199
STL class.
decltype(fftwf_execute_dft_r2c) typedef func_execute_fwd_t
Definition: FFT.h:50
Wraps the FFTW API with a more C++ like one.
Definition: FFT.h:87
static func_execute_fwd_t * func_execute_fwd
Definition: FFT.h:56
static void executeInverse(plan_ptr_t &plan, std::vector< complex_t > &in, std::vector< T > &out)
Definition: FFT.cpp:250
decltype(fftw_plan_many_dft_c2r) typedef func_plan_inv_t
Definition: FFT.h:68
decltype(fftw_plan_many_dft_r2c) typedef func_plan_fwd_t
Definition: FFT.h:67
FFTTraits< T > fftw_traits
Definition: FFT.h:88
decltype(fftwf_execute_dft_c2r) typedef func_execute_inv_t
Definition: FFT.h:51
static func_plan_fwd_t * func_plan_fwd
Definition: FFT.h:73
static func_execute_inv_t * func_execute_inv
Definition: FFT.h:77
std::shared_ptr< typename fftw_traits::plan_t > plan_ptr_t
Definition: FFT.h:92
decltype(fftw_execute_dft_r2c) typedef func_execute_fwd_t
Definition: FFT.h:70
decltype(fftw_destroy_plan) typedef func_destroy_plan_t
Definition: FFT.h:69
decltype(fftwf_plan_many_dft_c2r) typedef func_plan_inv_t
Definition: FFT.h:48
decltype(fftw_execute_dft_c2r) typedef func_execute_inv_t
Definition: FFT.h:71
static func_execute_fwd_t * func_execute_fwd
Definition: FFT.h:76
STL class.
int fftRoundDimension(int size)
Definition: FFT.cpp:49
decltype(fftwf_destroy_plan) typedef func_destroy_plan_t
Definition: FFT.h:49
decltype(fftwf_plan_many_dft_r2c) typedef func_plan_fwd_t
Definition: FFT.h:47
static func_destroy_plan_t * func_destroy_plan
Definition: FFT.h:75
std::complex< T > complex_t
Definition: FFT.h:93
static func_destroy_plan_t * func_destroy_plan
Definition: FFT.h:55
static void executeForward(plan_ptr_t &plan, std::vector< T > &in, std::vector< complex_t > &out)
Definition: FFT.cpp:244
static func_plan_inv_t * func_plan_inv
Definition: FFT.h:54