18 #ifndef itkFFTWCommon_h
19 #define itkFFTWCommon_h
22 #if defined( ITK_USE_FFTWF ) || defined( ITK_USE_FFTWD )
24 #if !defined(FFTW_WISDOM_ONLY)
27 #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 )
79 bool canDestroyInput=
false)
81 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
90 bool canDestroyInput=
false)
92 int * sizes =
new int[2];
95 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
107 bool canDestroyInput=
false)
109 int * sizes =
new int[3];
113 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
124 bool canDestroyInput=
false)
127 fftwf_plan_with_nthreads(threads);
130 unsigned roflags = flags;
131 if( ! (flags & FFTW_ESTIMATE) )
133 roflags = flags | FFTW_WISDOM_ONLY;
135 PlanType plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
136 if( plan == ITK_NULLPTR )
139 if( canDestroyInput )
142 plan = fftwf_plan_dft_c2r(rank,n,in,out,flags);
148 for(
int i=0; i<rank; i++ )
153 fftwf_plan_dft_c2r(rank,n,din,out,flags);
156 plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
160 itkAssertOrThrowMacro( plan != ITK_NULLPTR ,
"PLAN_CREATION_FAILED ");
170 bool canDestroyInput=
false)
172 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
181 bool canDestroyInput=
false)
183 int * sizes =
new int[2];
186 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
198 bool canDestroyInput=
false)
200 int * sizes =
new int[3];
204 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
215 bool canDestroyInput=
false)
219 fftwf_plan_with_nthreads(threads);
222 unsigned roflags = flags;
223 if( ! (flags & FFTW_ESTIMATE) )
225 roflags = flags | FFTW_WISDOM_ONLY;
227 PlanType plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
228 if( plan == ITK_NULLPTR )
231 if( canDestroyInput )
234 plan = fftwf_plan_dft_r2c(rank,n,in,out,flags);
240 for(
int i=0; i<rank; i++ )
245 fftwf_plan_dft_r2c(rank,n,din,out,flags);
248 plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
252 itkAssertOrThrowMacro( plan != ITK_NULLPTR ,
"PLAN_CREATION_FAILED ");
262 bool canDestroyInput=
false)
264 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
274 bool canDestroyInput=
false)
276 int * sizes =
new int[2];
279 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
292 bool canDestroyInput=
false)
294 int * sizes =
new int[3];
298 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
310 bool canDestroyInput=
false)
313 fftwf_plan_with_nthreads(threads);
316 unsigned roflags = flags;
317 if( ! (flags & FFTW_ESTIMATE) )
319 roflags = flags | FFTW_WISDOM_ONLY;
321 PlanType plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
322 if( plan == ITK_NULLPTR )
325 if( canDestroyInput )
328 plan = fftwf_plan_dft(rank,n,in,out,sign,flags);
334 for(
int i=0; i<rank; i++ )
339 fftwf_plan_dft(rank,n,din,out,sign,flags);
342 plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
346 itkAssertOrThrowMacro( plan != ITK_NULLPTR ,
"PLAN_CREATION_FAILED ");
358 fftwf_destroy_plan(p);
362 #endif // ITK_USE_FFTWF
365 #if defined( ITK_USE_FFTWD )
383 bool canDestroyInput=
false)
385 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
394 bool canDestroyInput=
false)
396 int * sizes =
new int[2];
399 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
411 bool canDestroyInput=
false)
413 int * sizes =
new int[3];
417 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
428 bool canDestroyInput=
false)
431 fftw_plan_with_nthreads(threads);
434 unsigned roflags = flags;
435 if( ! (flags & FFTW_ESTIMATE) )
437 roflags = flags | FFTW_WISDOM_ONLY;
439 PlanType plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
440 if( plan == ITK_NULLPTR )
443 if( canDestroyInput )
446 plan = fftw_plan_dft_c2r(rank,n,in,out,flags);
452 for(
int i=0; i<rank; i++ )
457 fftw_plan_dft_c2r(rank,n,din,out,flags);
460 plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
464 itkAssertOrThrowMacro( plan != ITK_NULLPTR ,
"PLAN_CREATION_FAILED ");
474 bool canDestroyInput=
false)
476 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
485 bool canDestroyInput=
false)
487 int * sizes =
new int[2];
490 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
502 bool canDestroyInput=
false)
504 int * sizes =
new int[3];
508 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
519 bool canDestroyInput=
false)
522 fftw_plan_with_nthreads(threads);
525 unsigned roflags = flags;
526 if( ! (flags & FFTW_ESTIMATE) )
528 roflags = flags | FFTW_WISDOM_ONLY;
530 PlanType plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
531 if( plan == ITK_NULLPTR )
534 if( canDestroyInput )
537 plan = fftw_plan_dft_r2c(rank,n,in,out,flags);
543 for(
int i=0; i<rank; i++ )
548 fftw_plan_dft_r2c(rank,n,din,out,flags);
551 plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
555 itkAssertOrThrowMacro( plan != ITK_NULLPTR ,
"PLAN_CREATION_FAILED ");
565 bool canDestroyInput=
false)
567 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
577 bool canDestroyInput=
false)
579 int * sizes =
new int[2];
582 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
595 bool canDestroyInput=
false)
597 int * sizes =
new int[3];
601 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
613 bool canDestroyInput=
false)
616 fftw_plan_with_nthreads(threads);
619 unsigned roflags = flags;
620 if( ! (flags & FFTW_ESTIMATE) )
622 roflags = flags | FFTW_WISDOM_ONLY;
624 PlanType plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
625 if( plan == ITK_NULLPTR )
628 if( canDestroyInput )
631 plan = fftw_plan_dft(rank,n,in,out,sign,flags);
637 for(
int i=0; i<rank; i++ )
642 fftw_plan_dft(rank,n,din,out,sign,flags);
645 plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
649 itkAssertOrThrowMacro( plan != ITK_NULLPTR ,
"PLAN_CREATION_FAILED ");
661 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. This holder class for ensuring that locks are released in the event of ...
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)
unsigned long SizeValueType
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)