18 #ifndef __itkFFTWCommon_h
19 #define __itkFFTWCommon_h
22 #if defined( USE_FFTWF ) || defined( USE_FFTWD )
26 #if !defined(FFTW_WISDOM_ONLY)
29 #error "FFTW 3.3.2 or later is required so that FFTW_WISDOM_ONLY is defined."
48 template<
typename TPixel >
58 #if defined( USE_FFTWF )
74 bool canDestroyInput=
false)
76 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
85 bool canDestroyInput=
false)
87 int * sizes =
new int[2];
90 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
102 bool canDestroyInput=
false)
104 int * sizes =
new int[3];
108 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
119 bool canDestroyInput=
false)
122 fftwf_plan_with_nthreads(threads);
125 unsigned roflags = flags;
126 if( ! (flags & FFTW_ESTIMATE) )
128 roflags = flags | FFTW_WISDOM_ONLY;
130 PlanType plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
134 if( canDestroyInput )
137 plan = fftwf_plan_dft_c2r(rank,n,in,out,flags);
143 for(
int i=0; i<rank; i++ )
148 fftwf_plan_dft_c2r(rank,n,din,out,flags);
151 plan = fftwf_plan_dft_c2r(rank,n,in,out,roflags);
156 assert( plan !=
NULL );
166 bool canDestroyInput=
false)
168 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
177 bool canDestroyInput=
false)
179 int * sizes =
new int[2];
182 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
194 bool canDestroyInput=
false)
196 int * sizes =
new int[3];
200 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
211 bool canDestroyInput=
false)
214 fftwf_plan_with_nthreads(threads);
217 unsigned roflags = flags;
218 if( ! (flags & FFTW_ESTIMATE) )
220 roflags = flags | FFTW_WISDOM_ONLY;
222 PlanType plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
226 if( canDestroyInput )
229 plan = fftwf_plan_dft_r2c(rank,n,in,out,flags);
235 for(
int i=0; i<rank; i++ )
240 fftwf_plan_dft_r2c(rank,n,din,out,flags);
243 plan = fftwf_plan_dft_r2c(rank,n,in,out,roflags);
248 assert( plan !=
NULL );
258 bool canDestroyInput=
false)
260 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
270 bool canDestroyInput=
false)
272 int * sizes =
new int[2];
275 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
288 bool canDestroyInput=
false)
290 int * sizes =
new int[3];
294 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
306 bool canDestroyInput=
false)
309 fftwf_plan_with_nthreads(threads);
312 unsigned roflags = flags;
313 if( ! (flags & FFTW_ESTIMATE) )
315 roflags = flags | FFTW_WISDOM_ONLY;
317 PlanType plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
321 if( canDestroyInput )
324 plan = fftwf_plan_dft(rank,n,in,out,sign,flags);
330 for(
int i=0; i<rank; i++ )
335 fftwf_plan_dft(rank,n,din,out,sign,flags);
338 plan = fftwf_plan_dft(rank,n,in,out,sign,roflags);
343 assert( plan !=
NULL );
354 fftwf_destroy_plan(p);
361 #if defined( USE_FFTWD )
376 bool canDestroyInput=
false)
378 return Plan_dft_c2r(1, &n, in, out, flags, threads, canDestroyInput);
387 bool canDestroyInput=
false)
389 int * sizes =
new int[2];
392 PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
404 bool canDestroyInput=
false)
406 int * sizes =
new int[3];
410 PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
421 bool canDestroyInput=
false)
424 fftw_plan_with_nthreads(threads);
427 unsigned roflags = flags;
428 if( ! (flags & FFTW_ESTIMATE) )
430 roflags = flags | FFTW_WISDOM_ONLY;
432 PlanType plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
436 if( canDestroyInput )
439 plan = fftw_plan_dft_c2r(rank,n,in,out,flags);
445 for(
int i=0; i<rank; i++ )
450 fftw_plan_dft_c2r(rank,n,din,out,flags);
453 plan = fftw_plan_dft_c2r(rank,n,in,out,roflags);
458 assert( plan !=
NULL );
468 bool canDestroyInput=
false)
470 return Plan_dft_r2c(1, &n, in, out, flags, threads, canDestroyInput);
479 bool canDestroyInput=
false)
481 int * sizes =
new int[2];
484 PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
496 bool canDestroyInput=
false)
498 int * sizes =
new int[3];
502 PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
513 bool canDestroyInput=
false)
516 fftw_plan_with_nthreads(threads);
519 unsigned roflags = flags;
520 if( ! (flags & FFTW_ESTIMATE) )
522 roflags = flags | FFTW_WISDOM_ONLY;
524 PlanType plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
528 if( canDestroyInput )
531 plan = fftw_plan_dft_r2c(rank,n,in,out,flags);
537 for(
int i=0; i<rank; i++ )
542 fftw_plan_dft_r2c(rank,n,din,out,flags);
545 plan = fftw_plan_dft_r2c(rank,n,in,out,roflags);
550 assert( plan !=
NULL );
560 bool canDestroyInput=
false)
562 return Plan_dft(1, &n, in, out,sign , flags, threads, canDestroyInput);
572 bool canDestroyInput=
false)
574 int * sizes =
new int[2];
577 PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
590 bool canDestroyInput=
false)
592 int * sizes =
new int[3];
596 PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
608 bool canDestroyInput=
false)
611 fftw_plan_with_nthreads(threads);
614 unsigned roflags = flags;
615 if( ! (flags & FFTW_ESTIMATE) )
617 roflags = flags | FFTW_WISDOM_ONLY;
619 PlanType plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
623 if( canDestroyInput )
626 plan = fftw_plan_dft(rank,n,in,out,sign,flags);
632 for(
int i=0; i<rank; i++ )
637 fftw_plan_dft(rank,n,din,out,sign,flags);
640 plan = fftw_plan_dft(rank,n,in,out,sign,roflags);
645 assert( plan !=
NULL );
656 fftw_destroy_plan(p);