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."
53template <
typename TPixel>
63#if defined(ITK_USE_FFTWF)
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);
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)
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 ");
184 bool canDestroyInput =
false)
186 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
196 bool canDestroyInput =
false)
201 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
213 bool canDestroyInput =
false)
219 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
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)
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)
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 ");
384# ifndef ITK_USE_CUFFTW
387 fftwf_destroy_plan(p);
394#if defined(ITK_USE_FFTWD)
405# ifdef ITK_USE_CUFFTW
417 bool canDestroyInput =
false)
419 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
429 bool canDestroyInput =
false)
434 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
446 bool canDestroyInput =
false)
452 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
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)
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 ");
514 bool canDestroyInput =
false)
516 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
526 bool canDestroyInput =
false)
531 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
543 bool canDestroyInput =
false)
549 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
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)
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)
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 ");
713# ifndef ITK_USE_CUFFTW
716 fftw_destroy_plan(p);
static std::mutex & GetLockMutex()
static void SetNewWisdomAvailable(const bool v)
static PlanType Plan_dft_c2r(int rank, const int *n, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static void Execute(PlanType p)
static PlanType Plan_dft_2d(int nx, int ny, ComplexType *in, ComplexType *out, int sign, unsigned int 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 int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_2d(int nx, int ny, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_1d(int n, ComplexType *in, ComplexType *out, int sign, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_1d(int n, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_3d(int nx, int ny, int nz, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static void DestroyPlan(PlanType p)
static PlanType Plan_dft_c2r_2d(int nx, int ny, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft(int rank, const int *n, ComplexType *in, ComplexType *out, int sign, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_1d(int n, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c(int rank, const int *n, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_3d(int nx, int ny, int nz, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_2d(int nx, int ny, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_2d(int nx, int ny, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_1d(int n, ComplexType *in, ComplexType *out, int sign, unsigned int flags, int threads=1, bool canDestroyInput=false)
fftwf_complex ComplexType
static PlanType Plan_dft(int rank, const int *n, ComplexType *in, ComplexType *out, int sign, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_2d(int nx, int ny, ComplexType *in, ComplexType *out, int sign, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r(int rank, const int *n, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_3d(int nx, int ny, int nz, ComplexType *in, PixelType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c_3d(int nx, int ny, int nz, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_c2r_1d(int n, ComplexType *in, PixelType *out, unsigned int 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 int flags, int threads=1, bool canDestroyInput=false)
static void DestroyPlan(PlanType p)
static void Execute(PlanType p)
static PlanType Plan_dft_r2c_1d(int n, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
static PlanType Plan_dft_r2c(int rank, const int *n, PixelType *in, ComplexType *out, unsigned int flags, int threads=1, bool canDestroyInput=false)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType