38 TCSTPlan(fftwf_r2r_kind forward, std::vector<int> size);
43 void execute(
const D& in_data, D& out_data)
const;
45 const std::vector<int>&
get_size()
const;
48 mutable value_type *m_in;
49 mutable value_type *m_out;
51 std::vector<int> m_size;
55 fftwf_plan m_forward_plan;
56 fftwf_plan m_backward_plan;
58 virtual void do_execute(value_type *buffer)
const = 0;
61 Scale(
float scale): m_scale(scale){
63 value_type operator ()(
const value_type& x)
const{
82 size_t rank = m_size.size();
83 fftwf_r2r_kind backward;
88 for (
size_t i = 0; i < rank; ++i)
89 m_scale *= 0.5 / ( size[i] + 1.0);
92 for (
size_t i = 0; i < rank; ++i)
93 m_scale *= 0.5 / ( size[i] - 1.0);
96 for (
size_t i = 0; i < rank; ++i)
97 m_scale *= 0.5 / size[i];
109 backward = FFTW_RODFT01;
112 backward = FFTW_REDFT01;
115 backward = FFTW_RODFT10;
118 backward = FFTW_REDFT10;
121 throw std::invalid_argument(
"TCSTPlan: unknown transformtion requested");
124 std::vector<fftwf_r2r_kind> fw_kind(rank, forward);
125 std::vector<fftwf_r2r_kind> bw_kind(rank, backward);
128 const int howmany =
sizeof(
value_type)/
sizeof(
float);
129 cvdebug() <<
"howmany = " << howmany <<
"\n";
131 for (
size_t i = 0; i < rank; ++i)
135 if (NULL == (m_in = (
value_type *) fftwf_malloc(
sizeof(T) * m_n))) {
136 msg =
"unable to allocate FFTW data";
140 if ( NULL == (m_out = (
value_type *) fftwf_malloc(
sizeof(T) * m_n))) {
141 msg =
"unable to allocate FFTW data";
145 if (0 == (m_forward_plan = fftwf_plan_many_r2r(rank, &size[0], howmany,
146 m_in, NULL, howmany, 1,
147 m_out, NULL, howmany, 1,
148 &fw_kind[0], FFTW_ESTIMATE))) {
149 msg =
"unable to create FFTW forward plan";
153 if (0 == (m_backward_plan = fftwf_plan_many_r2r(rank, &size[0], howmany,
154 m_out, NULL, howmany, 1,
155 m_in, NULL, howmany, 1,
156 &bw_kind[0], FFTW_ESTIMATE))) {
157 msg =
"unable to create FFTW backward plan";
164 fftwf_destroy_plan(m_forward_plan);
170 throw std::runtime_error(msg);
173 template <
typename T>
176 fftwf_destroy_plan(m_backward_plan);
177 fftwf_destroy_plan(m_forward_plan);
183 template <
typename T>
184 template <
typename D>
187 assert(m_n == in_data.size());
188 assert(m_n == out_data.size());
190 copy(in_data.begin(), in_data.end(), m_in);
191 fftwf_execute( m_forward_plan);
193 fftwf_execute(m_backward_plan);
194 transform( m_in, m_in + m_n, out_data.begin(), Scale(m_scale) );
TCSTPlan(fftwf_r2r_kind forward, std::vector< int > size)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
void execute(const D &in_data, D &out_data) const
const std::vector< int > & get_size() const
#define NS_MIA_END
conveniance define to end the mia namespace