18 #ifndef __itkFFTWCommon_h
19 #define __itkFFTWCommon_h
22 #if defined( ITK_USE_FFTWF ) || defined( ITK_USE_FFTWD )
28 #if !defined(FFTW_WISDOM_ONLY)
31 #error "FFTW 3.3.2 or later is required so that FFTW_WISDOM_ONLY is defined."
50 template<
typename TPixel >
60 #if defined( ITK_USE_FFTWF )
76 bool canDestroyInput=
false)
78 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
87 bool canDestroyInput=
false)
89 int * sizes =
new int[2];
92 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
104 bool canDestroyInput=
false)
106 int * sizes =
new int[3];
110 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
121 bool canDestroyInput=
false)
124 fftwf_plan_with_nthreads(threads);
127 unsigned roflags = flags;
128 if( ! (flags & FFTW_ESTIMATE) )
130 roflags = flags | FFTW_WISDOM_ONLY;
132 PlanType plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
133 if( plan == ITK_NULLPTR )
136 if( canDestroyInput )
139 plan = fftwf_plan_dft_c2r(rank,n,in,out,flags);
145 for(
int i=0; i<rank; i++ )
150 fftwf_plan_dft_c2r(rank,n,din,out,flags);
153 plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
157 assert( plan !=
NULL );
167 bool canDestroyInput=
false)
169 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
178 bool canDestroyInput=
false)
180 int * sizes =
new int[2];
183 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
195 bool canDestroyInput=
false)
197 int * sizes =
new int[3];
201 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
212 bool canDestroyInput=
false)
216 fftwf_plan_with_nthreads(threads);
219 unsigned roflags = flags;
220 if( ! (flags & FFTW_ESTIMATE) )
222 roflags = flags | FFTW_WISDOM_ONLY;
224 PlanType plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
225 if( plan == ITK_NULLPTR )
228 if( canDestroyInput )
231 plan = fftwf_plan_dft_r2c(rank,n,in,out,flags);
237 for(
int i=0; i<rank; i++ )
242 fftwf_plan_dft_r2c(rank,n,din,out,flags);
245 plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
249 assert( plan !=
NULL );
259 bool canDestroyInput=
false)
261 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
271 bool canDestroyInput=
false)
273 int * sizes =
new int[2];
276 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
289 bool canDestroyInput=
false)
291 int * sizes =
new int[3];
295 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
307 bool canDestroyInput=
false)
310 fftwf_plan_with_nthreads(threads);
313 unsigned roflags = flags;
314 if( ! (flags & FFTW_ESTIMATE) )
316 roflags = flags | FFTW_WISDOM_ONLY;
318 PlanType plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
319 if( plan == ITK_NULLPTR )
322 if( canDestroyInput )
325 plan = fftwf_plan_dft(rank,n,in,out,sign,flags);
331 for(
int i=0; i<rank; i++ )
336 fftwf_plan_dft(rank,n,din,out,sign,flags);
339 plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
343 assert( plan !=
NULL );
355 fftwf_destroy_plan(p);
359 #endif // ITK_USE_FFTWF
362 #if defined( ITK_USE_FFTWD )
377 bool canDestroyInput=
false)
379 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
388 bool canDestroyInput=
false)
390 int * sizes =
new int[2];
393 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
405 bool canDestroyInput=
false)
407 int * sizes =
new int[3];
411 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
422 bool canDestroyInput=
false)
425 fftw_plan_with_nthreads(threads);
428 unsigned roflags = flags;
429 if( ! (flags & FFTW_ESTIMATE) )
431 roflags = flags | FFTW_WISDOM_ONLY;
433 PlanType plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
434 if( plan == ITK_NULLPTR )
437 if( canDestroyInput )
440 plan = fftw_plan_dft_c2r(rank,n,in,out,flags);
446 for(
int i=0; i<rank; i++ )
451 fftw_plan_dft_c2r(rank,n,din,out,flags);
454 plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
458 assert( plan !=
NULL );
468 bool canDestroyInput=
false)
470 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
479 bool canDestroyInput=
false)
481 int * sizes =
new int[2];
484 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
496 bool canDestroyInput=
false)
498 int * sizes =
new int[3];
502 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
513 bool canDestroyInput=
false)
516 fftw_plan_with_nthreads(threads);
519 unsigned roflags = flags;
520 if( ! (flags & FFTW_ESTIMATE) )
522 roflags = flags | FFTW_WISDOM_ONLY;
524 PlanType plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
525 if( plan == ITK_NULLPTR )
528 if( canDestroyInput )
531 plan = fftw_plan_dft_r2c(rank,n,in,out,flags);
537 for(
int i=0; i<rank; i++ )
542 fftw_plan_dft_r2c(rank,n,din,out,flags);
545 plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
549 assert( plan !=
NULL );
559 bool canDestroyInput=
false)
561 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
571 bool canDestroyInput=
false)
573 int * sizes =
new int[2];
576 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
589 bool canDestroyInput=
false)
591 int * sizes =
new int[3];
595 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
607 bool canDestroyInput=
false)
610 fftw_plan_with_nthreads(threads);
613 unsigned roflags = flags;
614 if( ! (flags & FFTW_ESTIMATE) )
616 roflags = flags | FFTW_WISDOM_ONLY;
618 PlanType plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
619 if( plan == ITK_NULLPTR )
622 if( canDestroyInput )
625 plan = fftw_plan_dft(rank,n,in,out,sign,flags);
631 for(
int i=0; i<rank; i++ )
636 fftw_plan_dft(rank,n,din,out,sign,flags);
639 plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
643 assert( plan !=
NULL );
655 fftw_destroy_plan(p);
static PlanType Plan_dft_r2c(int rank, const int *n, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static SimpleFastMutexLock & GetLockMutex()
static PlanType Plan_dft(int rank, const int *n, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static void Execute(PlanType p)
static PlanType Plan_dft_r2c_1d(int n, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_2d(int nx, int ny, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
A container to store a Mutex.
static PlanType Plan_dft_1d(int n, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r(int rank, const int *n, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static void DestroyPlan(PlanType p)
static PlanType Plan_dft_c2r_2d(int nx, int ny, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_3d(int nx, int ny, int nz, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_1d(int n, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_3d(int nx, int ny, int nz, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_2d(int nx, int ny, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static void DestroyPlan(PlanType p)
static PlanType Plan_dft_3d(int nx, int ny, int nz, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_3d(int nx, int ny, int nz, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r(int rank, const int *n, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
fftwf_complex ComplexType
static PlanType Plan_dft_c2r_1d(int n, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static void SetNewWisdomAvailable(const bool &v)
static PlanType Plan_dft_r2c_2d(int nx, int ny, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_2d(int nx, int ny, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_3d(int nx, int ny, int nz, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static void Execute(PlanType p)
static PlanType Plan_dft_c2r_1d(int n, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_1d(int n, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_3d(int nx, int ny, int nz, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft(int rank, const int *n, ComplexType *in, ComplexType *out, int sign, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c(int rank, const int *n, PixelType *in, ComplexType *out, unsigned flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_2d(int nx, int ny, ComplexType *in, PixelType *out, unsigned flags, int threads=1, bool canDestroyInput=false)