EMAN2
emfft.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman_emfft_h__
33#define eman_emfft_h__
34
35#ifdef USE_FFTW3
36
37#include <fftw3.h>
38#include<complex>
39
40namespace EMAN
41{
44 class EMfft
45 {
46 public:
47 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
48 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
49 static int complex_to_complex_1d_inplace(std::complex<float> *data, int n);
50 static int complex_to_complex_2d_inplace(std::complex<float> *data, int nx,int ny);
51 static int complex_to_complex_1d_f(float *in, float *out, int n); // ming add
52 static int complex_to_complex_1d_b(float *in, float *out, int n); // ming add
53 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny,
54 int nz);
55 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny,
56 int nz);
57 static int complex_to_complex_nd(float *complex_data_in, float *complex_data_out, int nx,int ny,int nz);// ming add
58 static inline float *fftmalloc(int n) { return (float*)fftw_malloc(n*sizeof(float)); }
59 static inline void fftfree(float *mem) { fftw_free(mem); }
60
61 // NOTE 2018/11/13 Toshio Moriya:
62 // Added for Pawel so that he can access to EMfft::EMfftw3_cache::EMfftw3_cache() through this function
63 // This function is available only when USE_FFTW3 is defined.
64 static int initialize_plan_cache();
65
66 private:
67#ifdef FFTW_PLAN_CACHING
68#define EMFFTW3_CACHE_SIZE 32
69 static const int EMAN2_REAL_2_COMPLEX;
70 static const int EMAN2_COMPLEX_2_REAL;
71 static const int EMAN2_COMPLEX_2_COMPLEX; // inplace only
83 class EMfftw3_cache
84 {
85 public:
86 EMfftw3_cache();
87 ~EMfftw3_cache();
88
89 // NOTE 2018/11/13 Toshio Moriya:
90 // Added for Pawel
91 void clear_plans();
92 void destroy_plans();
93
107 fftwf_plan get_plan(const int rank, const int x, const int y, const int z, const int r2c_flag,const int ip_flag, fftwf_complex* complex_data, float* real_data);
108 private:
109 // Prints useful debug information to standard out
110 void debug_plans();
111
112 // Store the number of plans currently contained in this EMfftw3_cache object
113 int num_plans;
114
115 // Store the rank of the plan
116 int rank[EMFFTW3_CACHE_SIZE];
117 // Store the dimensions of the plan (always in 3D, if dimensions are "unused" they are taken to be 1)
118 int plan_dims[EMFFTW3_CACHE_SIZE][3];
119 // store whether the plan was real to complex or vice versa
120 int r2c[EMFFTW3_CACHE_SIZE];
121 // Store the plans themselves
122 fftwf_plan fftwplans[EMFFTW3_CACHE_SIZE];
123 // Store whether or not the plan was inplace
124 int ip[EMFFTW3_CACHE_SIZE];
125 };
126
127 static EMfftw3_cache plan_cache;
128#endif
129 };
130}
131#endif //USE_FFTW3
132
133//#ifdef CUDA_FFT
134//class EMfft
135// {
136// public:
137// static int real_to_complex_1d(float *real_data, float *complex_data, int n);
138// static int complex_to_real_1d(float *complex_data, float *real_data, int n);
139
140// static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny,
141// int nz);
142// static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny,
143// int nz);
144// private:
145// static const int EMAN2_REAL_2_COMPLEX;
146// static const int EMAN2_COMPLEX_2_REAL;
147// static const int EMAN2_FFTW2_INPLACE;
148// static const int EMAN2_FFTW2_OUT_OF_PLACE;
149// };
150//#endif //CUDA_FFT
151
152
153#ifdef NATIVE_FFT
154namespace EMAN
155{
158 class EMfft
159 {
160 public:
161 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
162 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
163
164 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny, int nz);
165 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny, int nz);
166 };
167}
168#endif //NATIVE_FFT
169
170#ifdef USE_ACML
171#include <acml.h>
172#include <functional>
173
174namespace EMAN
175{
178 class EMfft
179 {
180 public:
181 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
182 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
183
184 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny, int nz);
185 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny, int nz);
186 static inline float *fftmalloc(int n) { return (float*)malloc(n*sizeof(float)); }
187 static inline void fftfree(float *mem) { free(mem) }
188
189 private:
190 static int real_to_complex_2d(float *real_data, float *complex_data, int nx, int ny);
191 static int complex_to_real_2d(float *complex_data, float *real_data, int nx, int ny);
192 static int real_to_complex_3d(float *real_data, float *complex_data, int nx, int ny, int nz);
193 static int complex_to_real_3d(float *complex_data, float *real_data, int nx, int ny, int nz);
194
195 class time_sqrt_n : public std::unary_function<float, float> {
196 public:
197 time_sqrt_n(int n) : n_(n), factor(sqrt(float(n_))) {}
198 float operator()(float x) const {return x*factor;}
199 private:
200 const int n_;
201 const float factor;
202 };
203
204 class divide_sqrt_n : public std::unary_function<float, float> {
205 public:
206 divide_sqrt_n(int n) : n_(n), factor(sqrt(float(n_))) {}
207 float operator()(float x) const {return x/factor;}
208 private:
209 const int n_;
210 const float factor;
211 };
212 };
213}
214#endif //USE_ACML
215
216#endif //eman_emfft_h__
EMData * sqrt() const
return square root of current image
float & operator()(const int ix, const int iy, const int iz) const
Overload operator() for array indexing.
Definition: emdata_core.h:727
E2Exception class.
Definition: aligner.h:40
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517