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 ");
382 DestroyPlan(PlanType p)
384# ifndef ITK_USE_CUFFTW
387 fftwf_destroy_plan(p);
394#if defined(ITK_USE_FFTWD)
399 using PixelType = double;
400 using ComplexType = fftw_complex;
401 using PlanType = fftw_plan;
405# ifdef ITK_USE_CUFFTW
412 Plan_dft_c2r_1d(
int n,
417 bool canDestroyInput =
false)
419 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
423 Plan_dft_c2r_2d(
int nx,
429 bool canDestroyInput =
false)
434 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
439 Plan_dft_c2r_3d(
int nx,
446 bool canDestroyInput =
false)
452 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
457 Plan_dft_c2r(
int rank,
462 [[maybe_unused]]
int threads = 1,
463 bool canDestroyInput =
false)
465# ifndef ITK_USE_CUFFTW
467 fftw_plan_with_nthreads(threads);
471 unsigned int roflags = flags;
472 if (!(flags & FFTW_ESTIMATE))
474 roflags = flags | FFTW_WISDOM_ONLY;
476 PlanType plan = fftw_plan_dft_c2r(rank, n, in, out, roflags);
483 plan = fftw_plan_dft_c2r(rank, n, in, out, flags);
489 for (
int i = 0; i < rank; ++i)
493 auto * din =
new ComplexType[total];
494 fftw_plan_dft_c2r(rank, n, din, out, flags);
497 plan = fftw_plan_dft_c2r(rank, n, in, out, roflags);
499# ifndef ITK_USE_CUFFTW
503 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
509 Plan_dft_r2c_1d(
int n,
514 bool canDestroyInput =
false)
516 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
520 Plan_dft_r2c_2d(
int nx,
526 bool canDestroyInput =
false)
531 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
536 Plan_dft_r2c_3d(
int nx,
543 bool canDestroyInput =
false)
549 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
554 Plan_dft_r2c(
int rank,
559 [[maybe_unused]]
int threads = 1,
560 bool canDestroyInput =
false)
562# ifndef ITK_USE_CUFFTW
564 fftw_plan_with_nthreads(threads);
568 unsigned int roflags = flags;
569 if (!(flags & FFTW_ESTIMATE))
571 roflags = flags | FFTW_WISDOM_ONLY;
573 PlanType plan = fftw_plan_dft_r2c(rank, n, in, out, roflags);
580 plan = fftw_plan_dft_r2c(rank, n, in, out, flags);
586 for (
int i = 0; i < rank; ++i)
590 auto * din =
new PixelType[total];
591 fftw_plan_dft_r2c(rank, n, din, out, flags);
594 plan = fftw_plan_dft_r2c(rank, n, in, out, roflags);
596# ifndef ITK_USE_CUFFTW
600 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
611 bool canDestroyInput =
false)
613 return Plan_dft(1, &n, in, out, sign, flags, threads, canDestroyInput);
624 bool canDestroyInput =
false)
629 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
642 bool canDestroyInput =
false)
648 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
659 [[maybe_unused]]
int threads = 1,
660 bool canDestroyInput =
false)
662# ifndef ITK_USE_CUFFTW
664 fftw_plan_with_nthreads(threads);
668 unsigned int roflags = flags;
669 if (!(flags & FFTW_ESTIMATE))
671 roflags = flags | FFTW_WISDOM_ONLY;
673 PlanType plan = fftw_plan_dft(rank, n, in, out, sign, roflags);
680 plan = fftw_plan_dft(rank, n, in, out, sign, flags);
686 for (
int i = 0; i < rank; ++i)
690 auto * din =
new ComplexType[total];
691 fftw_plan_dft(rank, n, din, out, sign, flags);
694 plan = fftw_plan_dft(rank, n, in, out, sign, roflags);
696# ifndef ITK_USE_CUFFTW
700 itkAssertOrThrowMacro(plan !=
nullptr,
"PLAN_CREATION_FAILED ");
711 DestroyPlan(PlanType p)
713# ifndef ITK_USE_CUFFTW
716 fftw_destroy_plan(p);