SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 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 <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 
89  typedef FFTTraits<T> fftw_traits;
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
Wrap FFTW types and functions depending on the primitive type (float or double)
Definition: FFT.h:37
fftw_traits::complex_t complex_t
Definition: FFT.h:92
Wraps the FFTW API with a more C++ like one.
Definition: FFT.h:86
FFTTraits< T > fftw_traits
Definition: FFT.h:87
std::shared_ptr< typename fftw_traits::plan_t > plan_ptr_t
Definition: FFT.h:91
STL class.
int fftRoundDimension(int size)
Definition: FFT.cpp:49