FFTWWrapper.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Image/FFTWWrapper.H"
00024 #include "Util/log.H"
00025
00026 FFTWWrapper::FFTWWrapper(int width, int height){
00027 #ifndef HAVE_FFTW3_H
00028 LFATAL("you must have fftw3 installed to use this function");
00029 #else
00030 imagewidth = width;
00031 imageheight = height;
00032
00033
00034
00035 out = (double(*)[2])fftw_malloc(sizeof(fftw_complex) *
00036 imageheight * (imagewidth/2+1));
00037 if(out == NULL)
00038 LINFO("Memory allocation error");
00039
00040 #endif
00041 }
00042
00043
00044 void FFTWWrapper::init(double *image){
00045 #ifndef HAVE_FFTW3_H
00046 LFATAL("you must have fftw3 installed to use this function");
00047 #else
00048 in = image;
00049 p = fftw_plan_dft_r2c_2d(imageheight, imagewidth, in, out, FFTW_MEASURE);
00050 #endif
00051 }
00052
00053
00054 void FFTWWrapper::compute(double** magspec){
00055 #ifndef HAVE_FFTW3_H
00056 LFATAL("you must have fftw3 installed to use this function");
00057 #else
00058 fftw_execute(p);
00059
00060 const int halfwidth = imagewidth/2 + 1;
00061
00062 for(int i = 0; i < imageheight; i++)
00063 for(int j = 0; j < halfwidth; j++)
00064 magspec[i][j] = mag(out[i*halfwidth+j]);
00065 #endif
00066 }
00067
00068
00069 void FFTWWrapper::compute(double* magspec){
00070 #ifndef HAVE_FFTW3_H
00071 LFATAL("you must have fftw3 installed to use this function");
00072 #else
00073 fftw_execute(p);
00074
00075 const int halfwidth = imagewidth/2 + 1;
00076
00077 for(int i = 0; i < imageheight; i++)
00078 for(int j = 0; j < halfwidth; j++)
00079 magspec[i * halfwidth + j] = mag(out[i*halfwidth+j]);
00080 #endif
00081 }
00082
00083
00084 FFTWWrapper::~FFTWWrapper(){
00085 #ifndef HAVE_FFTW3_H
00086
00087 LERROR("you must have fftw3 installed to use this function");
00088 #else
00089 fftw_destroy_plan(p);
00090
00091
00092
00093 fftw_free(out);
00094 #endif
00095 }