Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

emfft.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  * 
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  * 
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  * 
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  * 
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  * 
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  * 
00034  * */
00035  
00036 #ifndef eman_emfft_h__
00037 #define eman_emfft_h__
00038 
00039 #ifdef FFTW2
00040 
00041 #include <srfftw.h>
00042 namespace EMAN
00043 {
00046         class EMfft
00047         {
00048           public:
00049                 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
00050                 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
00051 
00052                 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny,
00053                                                                           int nz);
00054                 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny,
00055                                                                           int nz);
00056                 private:
00057 #ifdef  FFTW_PLAN_CACHING
00058 #define EMFFTW2_ND_CACHE_SIZE 20
00059 #define EMFFTW2_1D_CACHE_SIZE 20        
00060                 static const int EMAN2_REAL_2_COMPLEX;
00061                 static const int EMAN2_COMPLEX_2_REAL;
00062                 static const int EMAN2_FFTW2_INPLACE;
00063                 static const int EMAN2_FFTW2_OUT_OF_PLACE;
00074                 class EMfftw2_cache_nd
00075                 {
00076                 public:
00077                         EMfftw2_cache_nd();
00078                         ~EMfftw2_cache_nd();
00079 
00091                         rfftwnd_plan get_plan(const int rank, const int x, const int y, const int z, const int r2c_flag, int ip_flag);
00092                 private:
00093                         // Prints useful debug information to standard out
00094                         void debug_plans();
00095                 
00096                         // Store the number of plans currently contained in this EMfftw3_cache object
00097                         int num_plans;
00098 
00099                         // Store the rank of the plan
00100                         int rank[EMFFTW2_ND_CACHE_SIZE];
00101                         // Store the dimensions of the plan (always in 3D, if dimensions are "unused" they are taken to be 1)
00102                         int plan_dims[EMFFTW2_ND_CACHE_SIZE][3];
00103                         // store whether the plan was real to complex or vice versa
00104                         int r2c[EMFFTW2_ND_CACHE_SIZE];
00105                         // Store whether or not the plan was inplace
00106                         int ip[EMFFTW2_ND_CACHE_SIZE];
00107                         // Store the plans themselves
00108                         rfftwnd_plan rfftwnd_plans[EMFFTW2_ND_CACHE_SIZE];
00109                 };
00110                 
00120                 class EMfftw2_cache_1d
00121                 {
00122                 public:
00123                         EMfftw2_cache_1d();
00124                         ~EMfftw2_cache_1d();
00125 
00132                         rfftw_plan get_plan(const int x, const int r2c_flag);
00133                 private:
00134                         // Prints useful debug information to standard out
00135                         void debug_plans();
00136         
00137                         // Store the number of plans currently contained in this EMfftw3_cache object
00138                         int num_plans;
00139 
00140                         // Store the dimensions of the plan (always in 3D, if dimensions are "unused" they are taken to be 1)
00141                         int plan_dims[EMFFTW2_1D_CACHE_SIZE];
00142                         // store whether the plan was real to complex or vice versa
00143                         int r2c[EMFFTW2_1D_CACHE_SIZE];
00144                         // Store the plans themselves
00145                         rfftw_plan rfftw1d_plans[EMFFTW2_1D_CACHE_SIZE];
00146                 };
00147                 
00148                 static EMfftw2_cache_nd plan_nd_cache;
00149                 static EMfftw2_cache_1d plan_1d_cache;
00150 #endif 
00151         };
00152 }
00153 #endif  //FFTW2
00154 
00155 #ifdef FFTW3
00156 
00157 #include <fftw3.h>
00158  
00159 namespace EMAN
00160 {
00163         class EMfft
00164         {
00165           public:
00166                 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
00167                 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
00168 
00169                 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny,
00170                                                                           int nz);
00171                 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny,
00172                                                                           int nz);
00173           private:
00174 #ifdef FFTW_PLAN_CACHING
00175 #define EMFFTW3_CACHE_SIZE 20
00176                 static const int EMAN2_REAL_2_COMPLEX;
00177                 static const int EMAN2_COMPLEX_2_REAL;
00178                 static const int EMAN2_FFTW2_INPLACE;
00179                 static const int EMAN2_FFTW2_OUT_OF_PLACE;
00191                 class EMfftw3_cache
00192                 {
00193                 public:
00194                         EMfftw3_cache();
00195                         ~EMfftw3_cache();
00196 
00210                         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);
00211                 private:
00212                         // Prints useful debug information to standard out
00213                         void debug_plans();
00214                         
00215                         // Store the number of plans currently contained in this EMfftw3_cache object
00216                         int num_plans;
00217 
00218                         // Store the rank of the plan
00219                         int rank[EMFFTW3_CACHE_SIZE];
00220                         // Store the dimensions of the plan (always in 3D, if dimensions are "unused" they are taken to be 1)
00221                         int plan_dims[EMFFTW3_CACHE_SIZE][3];
00222                         // store whether the plan was real to complex or vice versa
00223                         int r2c[EMFFTW3_CACHE_SIZE];
00224                         // Store the plans themselves
00225                         fftwf_plan fftwplans[EMFFTW3_CACHE_SIZE];
00226                         // Store whether or not the plan was inplace
00227                         int ip[EMFFTW3_CACHE_SIZE];
00228                 
00229                 };
00230 
00231                 static EMfftw3_cache plan_cache;
00232 #endif 
00233         };
00234 }
00235 #endif  //FFTW3
00236 
00237 #ifdef CUDA_FFT
00238 class EMfft
00239         {
00240         public:
00241                 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
00242                 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
00243 
00244                 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny,
00245                                                                           int nz);
00246                 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny,
00247                                                                           int nz);
00248         private:
00249                 static const int EMAN2_REAL_2_COMPLEX;
00250                 static const int EMAN2_COMPLEX_2_REAL;
00251                 static const int EMAN2_FFTW2_INPLACE;
00252                 static const int EMAN2_FFTW2_OUT_OF_PLACE;
00253         };
00254 #endif //CUDA_FFT
00255 
00256 
00257 #ifdef NATIVE_FFT
00258 namespace EMAN
00259 {
00262         class EMfft
00263         {
00264           public:
00265                 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
00266                 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
00267 
00268                 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny, int nz);
00269                 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny, int nz);
00270         };
00271 }
00272 #endif  //NATIVE_FFT
00273 
00274 #ifdef  ACML
00275 #include <acml.h>
00276 #include <functional>
00277 
00278 namespace EMAN
00279 {
00282         class EMfft
00283         {
00284           public:
00285                 static int real_to_complex_1d(float *real_data, float *complex_data, int n);
00286                 static int complex_to_real_1d(float *complex_data, float *real_data, int n);
00287 
00288                 static int real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny, int nz);
00289                 static int complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny, int nz);
00290           
00291           private:
00292                 static int real_to_complex_2d(float *real_data, float *complex_data, int nx, int ny);
00293                 static int complex_to_real_2d(float *complex_data, float *real_data, int nx, int ny);
00294                 static int real_to_complex_3d(float *real_data, float *complex_data, int nx, int ny, int nz);
00295                 static int complex_to_real_3d(float *complex_data, float *real_data, int nx, int ny, int nz);
00296                 
00297                 class time_sqrt_n : public std::unary_function<float, float> {
00298                   public:
00299                         time_sqrt_n(int n) : n_(n), factor(sqrt(float(n_))) {}
00300                         float operator()(float x) const {return x*factor;}      
00301                   private:
00302                     const int n_;
00303                     const float factor;
00304                 };
00305                 
00306                 class divide_sqrt_n : public std::unary_function<float, float> {
00307                   public:
00308                         divide_sqrt_n(int n) : n_(n), factor(sqrt(float(n_))) {}
00309                         float operator()(float x) const {return x/factor;}
00310                   private:
00311                         const int n_;
00312                         const float factor;
00313                 };
00314         };
00315 }       
00316 #endif  //ACML
00317 
00318 #endif  //eman_emfft_h__

Generated on Tue May 25 17:34:09 2010 for EMAN2 by  doxygen 1.4.4