53template <
typename TPixel>
63#if defined(ITK_USE_FFTWF)
69 using PixelType = float;
70 using ComplexType = fftwf_complex;
71 using PlanType = fftwf_plan;
82 Plan_dft_c2r_1d(
int n,
87 bool canDestroyInput =
false)
89 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
93 Plan_dft_c2r_2d(
int nx,
99 bool canDestroyInput =
false)
104 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
109 Plan_dft_c2r_3d(
int nx,
116 bool canDestroyInput =
false)
122 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
127 Plan_dft_c2r(
int rank,
132 [[maybe_unused]]
int threads = 1,
133 bool canDestroyInput =
false)
135# ifndef ITK_USE_CUFFTW
137 fftwf_plan_with_nthreads(threads);
141 unsigned int roflags = flags;
142 if (!(flags & FFTW_ESTIMATE))
144 roflags = flags | FFTW_WISDOM_ONLY;
146 PlanType plan = fftwf_plan_dft_c2r(rank, n, in, out, roflags);
153 plan = fftwf_plan_dft_c2r(rank, n, in, out, flags);
159 for (
int i = 0; i < rank; ++i)
163 auto * din =
new ComplexType[total];
164 fftwf_plan_dft_c2r(rank, n, din, out, flags);
167 plan = fftwf_plan_dft_c2r(rank, n, in, out, roflags);
169# ifndef ITK_USE_CUFFTW
173 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
179 Plan_dft_r2c_1d(
int n,
184 bool canDestroyInput =
false)
186 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
190 Plan_dft_r2c_2d(
int nx,
196 bool canDestroyInput =
false)
201 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
206 Plan_dft_r2c_3d(
int nx,
213 bool canDestroyInput =
false)
219 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
224 Plan_dft_r2c(
int rank,
229 [[maybe_unused]]
int threads = 1,
230 bool canDestroyInput =
false)
233# ifndef ITK_USE_CUFFTW
235 fftwf_plan_with_nthreads(threads);
239 unsigned int roflags = flags;
240 if (!(flags & FFTW_ESTIMATE))
242 roflags = flags | FFTW_WISDOM_ONLY;
244 PlanType plan = fftwf_plan_dft_r2c(rank, n, in, out, roflags);
251 plan = fftwf_plan_dft_r2c(rank, n, in, out, flags);
257 for (
int i = 0; i < rank; ++i)
261 auto * din =
new PixelType[total];
262 fftwf_plan_dft_r2c(rank, n, din, out, flags);
265 plan = fftwf_plan_dft_r2c(rank, n, in, out, roflags);
267# ifndef ITK_USE_CUFFTW
271 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
282 bool canDestroyInput =
false)
284 return Plan_dft(1, &n, in, out, sign, flags, threads, canDestroyInput);
295 bool canDestroyInput =
false)
300 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
313 bool canDestroyInput =
false)
319 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
330 [[maybe_unused]]
int threads = 1,
331 bool canDestroyInput =
false)
333# ifndef ITK_USE_CUFFTW
335 fftwf_plan_with_nthreads(threads);
339 unsigned int roflags = flags;
340 if (!(flags & FFTW_ESTIMATE))
342 roflags = flags | FFTW_WISDOM_ONLY;
344 PlanType plan = fftwf_plan_dft(rank, n, in, out, sign, roflags);
351 plan = fftwf_plan_dft(rank, n, in, out, sign, flags);
357 for (
int i = 0; i < rank; ++i)
361 auto * din =
new ComplexType[total];
362 fftwf_plan_dft(rank, n, din, out, sign, flags);
365 plan = fftwf_plan_dft(rank, n, in, out, sign, roflags);
367# ifndef ITK_USE_CUFFTW
371 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
381 const fftw_r2r_kind * kind,
383 [[maybe_unused]]
int threads = 1,
384 bool canDestroyInput =
false)
386# ifndef ITK_USE_CUFFTW
388 fftwf_plan_with_nthreads(threads);
390 unsigned int roflags = flags;
391 if (!(flags & FFTW_ESTIMATE))
393 roflags = flags | FFTW_WISDOM_ONLY;
395 PlanType plan = fftwf_plan_r2r(rank, n, in, out, kind, roflags);
400 plan = fftwf_plan_r2r(rank, n, in, out, kind, flags);
405 for (
int i = 0; i < rank; ++i)
409 auto * din =
new PixelType[total];
410 fftwf_plan_r2r(rank, n, din, out, kind, flags);
412 plan = fftwf_plan_r2r(rank, n, in, out, kind, roflags);
414# ifndef ITK_USE_CUFFTW
418 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
428 DestroyPlan(PlanType p)
430# ifndef ITK_USE_CUFFTW
433 fftwf_destroy_plan(p);
440#if defined(ITK_USE_FFTWD)
445 using PixelType = double;
446 using ComplexType = fftw_complex;
447 using PlanType = fftw_plan;
451# ifdef ITK_USE_CUFFTW
458 Plan_dft_c2r_1d(
int n,
463 bool canDestroyInput =
false)
465 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
469 Plan_dft_c2r_2d(
int nx,
475 bool canDestroyInput =
false)
480 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
485 Plan_dft_c2r_3d(
int nx,
492 bool canDestroyInput =
false)
498 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
503 Plan_dft_c2r(
int rank,
508 [[maybe_unused]]
int threads = 1,
509 bool canDestroyInput =
false)
511# ifndef ITK_USE_CUFFTW
513 fftw_plan_with_nthreads(threads);
517 unsigned int roflags = flags;
518 if (!(flags & FFTW_ESTIMATE))
520 roflags = flags | FFTW_WISDOM_ONLY;
522 PlanType plan = fftw_plan_dft_c2r(rank, n, in, out, roflags);
529 plan = fftw_plan_dft_c2r(rank, n, in, out, flags);
535 for (
int i = 0; i < rank; ++i)
539 auto * din =
new ComplexType[total];
540 fftw_plan_dft_c2r(rank, n, din, out, flags);
543 plan = fftw_plan_dft_c2r(rank, n, in, out, roflags);
545# ifndef ITK_USE_CUFFTW
549 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
555 Plan_dft_r2c_1d(
int n,
560 bool canDestroyInput =
false)
562 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
566 Plan_dft_r2c_2d(
int nx,
572 bool canDestroyInput =
false)
577 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
582 Plan_dft_r2c_3d(
int nx,
589 bool canDestroyInput =
false)
595 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
600 Plan_dft_r2c(
int rank,
605 [[maybe_unused]]
int threads = 1,
606 bool canDestroyInput =
false)
608# ifndef ITK_USE_CUFFTW
610 fftw_plan_with_nthreads(threads);
614 unsigned int roflags = flags;
615 if (!(flags & FFTW_ESTIMATE))
617 roflags = flags | FFTW_WISDOM_ONLY;
619 PlanType plan = fftw_plan_dft_r2c(rank, n, in, out, roflags);
626 plan = fftw_plan_dft_r2c(rank, n, in, out, flags);
632 for (
int i = 0; i < rank; ++i)
636 auto * din =
new PixelType[total];
637 fftw_plan_dft_r2c(rank, n, din, out, flags);
640 plan = fftw_plan_dft_r2c(rank, n, in, out, roflags);
642# ifndef ITK_USE_CUFFTW
646 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
657 bool canDestroyInput =
false)
659 return Plan_dft(1, &n, in, out, sign, flags, threads, canDestroyInput);
670 bool canDestroyInput =
false)
675 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
688 bool canDestroyInput =
false)
694 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
705 [[maybe_unused]]
int threads = 1,
706 bool canDestroyInput =
false)
708# ifndef ITK_USE_CUFFTW
710 fftw_plan_with_nthreads(threads);
714 unsigned int roflags = flags;
715 if (!(flags & FFTW_ESTIMATE))
717 roflags = flags | FFTW_WISDOM_ONLY;
719 PlanType plan = fftw_plan_dft(rank, n, in, out, sign, roflags);
726 plan = fftw_plan_dft(rank, n, in, out, sign, flags);
732 for (
int i = 0; i < rank; ++i)
736 auto * din =
new ComplexType[total];
737 fftw_plan_dft(rank, n, din, out, sign, flags);
740 plan = fftw_plan_dft(rank, n, in, out, sign, roflags);
742# ifndef ITK_USE_CUFFTW
746 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
756 const fftw_r2r_kind * kind,
758 [[maybe_unused]]
int threads = 1,
759 bool canDestroyInput =
false)
761# ifndef ITK_USE_CUFFTW
763 fftw_plan_with_nthreads(threads);
765 unsigned int roflags = flags;
766 if (!(flags & FFTW_ESTIMATE))
768 roflags = flags | FFTW_WISDOM_ONLY;
770 PlanType plan = fftw_plan_r2r(rank, n, in, out, kind, roflags);
775 plan = fftw_plan_r2r(rank, n, in, out, kind, flags);
780 for (
int i = 0; i < rank; ++i)
784 auto * din =
new PixelType[total];
785 fftw_plan_r2r(rank, n, din, out, kind, flags);
787 plan = fftw_plan_r2r(rank, n, in, out, kind, roflags);
789# ifndef ITK_USE_CUFFTW
793 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
803 DestroyPlan(PlanType p)
805# ifndef ITK_USE_CUFFTW
808 fftw_destroy_plan(p);