core/vnl/algo/vnl_fft_base.txx
Go to the documentation of this file.
00001 #ifndef vnl_fft_base_txx_
00002 #define vnl_fft_base_txx_
00003 /*
00004   fsm
00005 */
00006 #include "vnl_fft_base.h"
00007 #include <vnl/algo/vnl_fft.h>
00008 #include <vcl_cassert.h>
00009 
00010 template <int D, class T>
00011 void vnl_fft_base<D, T>::transform(vcl_complex<T> *signal, int dir)
00012 {
00013   assert((dir == +1) || (dir == -1));
00014 
00015   // transform along each dimension, i, in turn.
00016   for (int i=0; i<D; ++i) {
00017     int N1 = 1; // n[0] n[1] ... n[i-1]
00018     int N2 = 1; // n[i]
00019     int N3 = 1; // n[i+1] n[i+2] ... n[D-1]
00020     for (int j=0; j<D; ++j) {
00021       int d = factors_[j].number();
00022       if (j <  i) N1 *= d;
00023       if (j == i) N2 *= d;
00024       if (j >  i) N3 *= d;
00025     }
00026 
00027     // pretend the signal is N1xN2xN3. we want to transform
00028     // along the second dimension.
00029     for (int n1=0; n1<N1; ++n1) {
00030       // FIXME: we could avoid one loop by using the LOT parameter
00031       // but it's not entirely clear that would save us anything.
00032 
00033       for (int n3=0; n3<N3; ++n3) {
00034         // This relies on the assumption that std::complex<T> is layout
00035         // compatible with "struct { T real; T imag; }". It is probably
00036         // a valid assumption for all sane C++ libraries.
00037         T *data = (T *) (signal + n1*N2*N3 + n3);
00038 
00039         long info = 0;
00040         vnl_fft_gpfa (/* A */     data,
00041                       /* B */     data + 1,
00042                       /* TRIGS */ factors_[i].trigs (),
00043                       /* INC */   2*N3,
00044                       /* JUMP */  0,
00045                       /* N */     N2,
00046                       /* LOT */   1,
00047                       /* ISIGN */ dir,
00048                       /* NIPQ */  factors_[i].pqr (),
00049                       /* INFO */  &info);
00050         assert(info != -1);
00051       }
00052     }
00053   }
00054 }
00055 
00056 #undef VNL_FFT_BASE_INSTANTIATE
00057 #define VNL_FFT_BASE_INSTANTIATE(D, T) \
00058 template struct vnl_fft_base<D, T >
00059 
00060 #endif