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."
53 template <
typename TPixel>
63 #if defined(ITK_USE_FFTWF)
75 # ifdef ITK_USE_CUFFTW
87 bool canDestroyInput =
false)
89 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
99 bool canDestroyInput =
false)
104 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
116 bool canDestroyInput =
false)
122 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
133 bool canDestroyInput =
false)
135 # ifndef ITK_USE_CUFFTW
137 fftwf_plan_with_nthreads(threads);
143 unsigned int roflags = flags;
144 if (!(flags & FFTW_ESTIMATE))
146 roflags = flags | FFTW_WISDOM_ONLY;
148 PlanType plan = fftwf_plan_dft_c2r(rank, n, in, out, roflags);
155 plan = fftwf_plan_dft_c2r(rank, n, in, out, flags);
161 for (
int i = 0; i < rank; ++i)
166 fftwf_plan_dft_c2r(rank, n, din, out, flags);
169 plan = fftwf_plan_dft_c2r(rank, n, in, out, roflags);
171 # ifndef ITK_USE_CUFFTW
175 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
186 bool canDestroyInput =
false)
188 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
198 bool canDestroyInput =
false)
203 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
215 bool canDestroyInput =
false)
221 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
232 bool canDestroyInput =
false)
235 # ifndef ITK_USE_CUFFTW
237 fftwf_plan_with_nthreads(threads);
243 unsigned int roflags = flags;
244 if (!(flags & FFTW_ESTIMATE))
246 roflags = flags | FFTW_WISDOM_ONLY;
248 PlanType plan = fftwf_plan_dft_r2c(rank, n, in, out, roflags);
255 plan = fftwf_plan_dft_r2c(rank, n, in, out, flags);
261 for (
int i = 0; i < rank; ++i)
266 fftwf_plan_dft_r2c(rank, n, din, out, flags);
269 plan = fftwf_plan_dft_r2c(rank, n, in, out, roflags);
271 # ifndef ITK_USE_CUFFTW
275 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
286 bool canDestroyInput =
false)
288 return Plan_dft(1, &n, in, out, sign, flags, threads, canDestroyInput);
299 bool canDestroyInput =
false)
304 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
317 bool canDestroyInput =
false)
323 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
335 bool canDestroyInput =
false)
337 # ifndef ITK_USE_CUFFTW
339 fftwf_plan_with_nthreads(threads);
345 unsigned int roflags = flags;
346 if (!(flags & FFTW_ESTIMATE))
348 roflags = flags | FFTW_WISDOM_ONLY;
350 PlanType plan = fftwf_plan_dft(rank, n, in, out, sign, roflags);
357 plan = fftwf_plan_dft(rank, n, in, out, sign, flags);
363 for (
int i = 0; i < rank; ++i)
368 fftwf_plan_dft(rank, n, din, out, sign, flags);
371 plan = fftwf_plan_dft(rank, n, in, out, sign, roflags);
373 # ifndef ITK_USE_CUFFTW
377 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
390 # ifndef ITK_USE_CUFFTW
393 fftwf_destroy_plan(p);
397 #endif // ITK_USE_FFTWF
400 #if defined(ITK_USE_FFTWD)
411 # ifdef ITK_USE_CUFFTW
423 bool canDestroyInput =
false)
425 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
435 bool canDestroyInput =
false)
440 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
452 bool canDestroyInput =
false)
458 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
469 bool canDestroyInput =
false)
471 # ifndef ITK_USE_CUFFTW
473 fftw_plan_with_nthreads(threads);
479 unsigned int roflags = flags;
480 if (!(flags & FFTW_ESTIMATE))
482 roflags = flags | FFTW_WISDOM_ONLY;
484 PlanType plan = fftw_plan_dft_c2r(rank, n, in, out, roflags);
491 plan = fftw_plan_dft_c2r(rank, n, in, out, flags);
497 for (
int i = 0; i < rank; ++i)
502 fftw_plan_dft_c2r(rank, n, din, out, flags);
505 plan = fftw_plan_dft_c2r(rank, n, in, out, roflags);
507 # ifndef ITK_USE_CUFFTW
511 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
522 bool canDestroyInput =
false)
524 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
534 bool canDestroyInput =
false)
539 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
551 bool canDestroyInput =
false)
557 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
568 bool canDestroyInput =
false)
570 # ifndef ITK_USE_CUFFTW
572 fftw_plan_with_nthreads(threads);
578 unsigned int roflags = flags;
579 if (!(flags & FFTW_ESTIMATE))
581 roflags = flags | FFTW_WISDOM_ONLY;
583 PlanType plan = fftw_plan_dft_r2c(rank, n, in, out, roflags);
590 plan = fftw_plan_dft_r2c(rank, n, in, out, flags);
596 for (
int i = 0; i < rank; ++i)
601 fftw_plan_dft_r2c(rank, n, din, out, flags);
604 plan = fftw_plan_dft_r2c(rank, n, in, out, roflags);
606 # ifndef ITK_USE_CUFFTW
610 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
621 bool canDestroyInput =
false)
623 return Plan_dft(1, &n, in, out, sign, flags, threads, canDestroyInput);
634 bool canDestroyInput =
false)
639 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
652 bool canDestroyInput =
false)
658 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
670 bool canDestroyInput =
false)
672 # ifndef ITK_USE_CUFFTW
674 fftw_plan_with_nthreads(threads);
680 unsigned int roflags = flags;
681 if (!(flags & FFTW_ESTIMATE))
683 roflags = flags | FFTW_WISDOM_ONLY;
685 PlanType plan = fftw_plan_dft(rank, n, in, out, sign, roflags);
692 plan = fftw_plan_dft(rank, n, in, out, sign, flags);
698 for (
int i = 0; i < rank; ++i)
703 fftw_plan_dft(rank, n, din, out, sign, flags);
706 plan = fftw_plan_dft(rank, n, in, out, sign, roflags);
708 # ifndef ITK_USE_CUFFTW
712 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
725 # ifndef ITK_USE_CUFFTW
728 fftw_destroy_plan(p);