18 #ifndef itkFFTWCommon_h
19 #define itkFFTWCommon_h
21 #if defined( ITK_USE_FFTWF ) || defined( ITK_USE_FFTWD )
22 #if defined( ITK_USE_CUFFTW )
28 #if !defined(FFTW_WISDOM_ONLY)
31 #error "FFTW 3.3.2 or later is required so that FFTW_WISDOM_ONLY is defined."
54 template<
typename TPixel >
64 #if defined( ITK_USE_FFTWF )
87 bool canDestroyInput=
false)
89 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
98 bool canDestroyInput=
false)
100 auto * sizes =
new int[2];
103 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
115 bool canDestroyInput=
false)
117 auto * sizes =
new int[3];
121 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
132 bool canDestroyInput=
false)
134 #ifndef ITK_USE_CUFFTW
136 fftwf_plan_with_nthreads(threads);
142 unsigned roflags = flags;
143 if( ! (flags & FFTW_ESTIMATE) )
145 roflags = flags | FFTW_WISDOM_ONLY;
147 PlanType plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
148 if( plan ==
nullptr )
151 if( canDestroyInput )
154 plan = fftwf_plan_dft_c2r(rank,n,in,out,flags);
160 for(
int i=0; i<rank; i++ )
165 fftwf_plan_dft_c2r(rank,n,din,out,flags);
168 plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
170 #ifndef ITK_USE_CUFFTW
174 itkAssertOrThrowMacro( plan !=
nullptr ,
"PLAN_CREATION_FAILED ");
184 bool canDestroyInput=
false)
186 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
195 bool canDestroyInput=
false)
197 auto * sizes =
new int[2];
200 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
212 bool canDestroyInput=
false)
214 auto * sizes =
new int[3];
218 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
229 bool canDestroyInput=
false)
232 #ifndef ITK_USE_CUFFTW
234 fftwf_plan_with_nthreads(threads);
240 unsigned roflags = flags;
241 if( ! (flags & FFTW_ESTIMATE) )
243 roflags = flags | FFTW_WISDOM_ONLY;
245 PlanType plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
246 if( plan ==
nullptr )
249 if( canDestroyInput )
252 plan = fftwf_plan_dft_r2c(rank,n,in,out,flags);
258 for(
int i=0; i<rank; i++ )
263 fftwf_plan_dft_r2c(rank,n,din,out,flags);
266 plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
268 #ifndef ITK_USE_CUFFTW
272 itkAssertOrThrowMacro( plan !=
nullptr ,
"PLAN_CREATION_FAILED ");
282 bool canDestroyInput=
false)
284 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
294 bool canDestroyInput=
false)
296 auto * sizes =
new int[2];
299 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
312 bool canDestroyInput=
false)
314 auto * sizes =
new int[3];
318 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
330 bool canDestroyInput=
false)
332 #ifndef ITK_USE_CUFFTW
334 fftwf_plan_with_nthreads(threads);
340 unsigned roflags = flags;
341 if( ! (flags & FFTW_ESTIMATE) )
343 roflags = flags | FFTW_WISDOM_ONLY;
345 PlanType plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
346 if( plan ==
nullptr )
349 if( canDestroyInput )
352 plan = fftwf_plan_dft(rank,n,in,out,sign,flags);
358 for(
int i=0; i<rank; i++ )
363 fftwf_plan_dft(rank,n,din,out,sign,flags);
366 plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
368 #ifndef ITK_USE_CUFFTW
372 itkAssertOrThrowMacro( plan !=
nullptr ,
"PLAN_CREATION_FAILED ");
383 #ifndef ITK_USE_CUFFTW
386 fftwf_destroy_plan(p);
390 #endif // ITK_USE_FFTWF
393 #if defined( ITK_USE_FFTWD )
404 #ifdef ITK_USE_CUFFTW
415 bool canDestroyInput=
false)
417 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
426 bool canDestroyInput=
false)
428 auto * sizes =
new int[2];
431 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
443 bool canDestroyInput=
false)
445 auto * sizes =
new int[3];
449 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
460 bool canDestroyInput=
false)
462 #ifndef ITK_USE_CUFFTW
464 fftw_plan_with_nthreads(threads);
470 unsigned roflags = flags;
471 if( ! (flags & FFTW_ESTIMATE) )
473 roflags = flags | FFTW_WISDOM_ONLY;
475 PlanType plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
476 if( plan ==
nullptr )
479 if( canDestroyInput )
482 plan = fftw_plan_dft_c2r(rank,n,in,out,flags);
488 for(
int i=0; i<rank; i++ )
493 fftw_plan_dft_c2r(rank,n,din,out,flags);
496 plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
498 #ifndef ITK_USE_CUFFTW
502 itkAssertOrThrowMacro( plan !=
nullptr ,
"PLAN_CREATION_FAILED ");
512 bool canDestroyInput=
false)
514 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
523 bool canDestroyInput=
false)
525 auto * sizes =
new int[2];
528 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
540 bool canDestroyInput=
false)
542 auto * sizes =
new int[3];
546 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
557 bool canDestroyInput=
false)
559 #ifndef ITK_USE_CUFFTW
561 fftw_plan_with_nthreads(threads);
567 unsigned roflags = flags;
568 if( ! (flags & FFTW_ESTIMATE) )
570 roflags = flags | FFTW_WISDOM_ONLY;
572 PlanType plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
573 if( plan ==
nullptr )
576 if( canDestroyInput )
579 plan = fftw_plan_dft_r2c(rank,n,in,out,flags);
585 for(
int i=0; i<rank; i++ )
590 fftw_plan_dft_r2c(rank,n,din,out,flags);
593 plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
595 #ifndef ITK_USE_CUFFTW
599 itkAssertOrThrowMacro( plan !=
nullptr ,
"PLAN_CREATION_FAILED ");
609 bool canDestroyInput=
false)
611 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
621 bool canDestroyInput=
false)
623 auto * sizes =
new int[2];
626 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
639 bool canDestroyInput=
false)
641 auto * sizes =
new int[3];
645 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
657 bool canDestroyInput=
false)
659 #ifndef ITK_USE_CUFFTW
661 fftw_plan_with_nthreads(threads);
667 unsigned roflags = flags;
668 if( ! (flags & FFTW_ESTIMATE) )
670 roflags = flags | FFTW_WISDOM_ONLY;
672 PlanType plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
673 if( plan ==
nullptr )
676 if( canDestroyInput )
679 plan = fftw_plan_dft(rank,n,in,out,sign,flags);
685 for(
int i=0; i<rank; i++ )
690 fftw_plan_dft(rank,n,din,out,sign,flags);
693 plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
695 #ifndef ITK_USE_CUFFTW
699 itkAssertOrThrowMacro( plan !=
nullptr ,
"PLAN_CREATION_FAILED ");
710 #ifndef ITK_USE_CUFFTW
713 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 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)
unsigned long SizeValueType
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_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 std::mutex & GetLockMutex()
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)