ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
Remote/Ultrasound/include/itkFFTWCommonExtended.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkFFTWCommonExtended_h
19#define itkFFTWCommonExtended_h
20
21#if defined(ITK_USE_FFTWF) || defined(ITK_USE_FFTWD)
22# if defined(ITK_USE_CUFFTW)
23# include "cufftw.h"
24# else
26# include "fftw3.h"
27# endif
28#endif
29
30#include <mutex>
31
32namespace itk
33{
34
35namespace fftw
36{
43template <typename TPixel>
44class ComplexToComplexProxy
45{
46 // empty -- only double and float specializations work
47protected:
50};
51
52#if defined(ITK_USE_FFTWF)
53
54template <>
55class ComplexToComplexProxy<float>
56{
57public:
58 using PixelType = float;
59 using ComplexType = fftwf_complex;
60 using PlanType = fftwf_plan;
62
63 static PlanType
64 Plan_dft_c2r_1d(int n, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
65 {
66# ifndef ITK_USE_CUFFTW
67 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
68 fftwf_plan_with_nthreads(threads);
69# else
70 (void)threads;
71# endif
72 PlanType plan = fftwf_plan_dft_c2r_1d(n, in, out, flags);
73 return plan;
74 }
75 static PlanType
76 Plan_dft_c2r_2d(int nx, int ny, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
77 {
78# ifndef ITK_USE_CUFFTW
79 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
80 fftwf_plan_with_nthreads(threads);
81# else
82 (void)threads;
83# endif
84 PlanType plan = fftwf_plan_dft_c2r_2d(nx, ny, in, out, flags);
85 return plan;
86 }
87 static PlanType
88 Plan_dft_c2r_3d(int nx, int ny, int nz, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
89 {
90# ifndef ITK_USE_CUFFTW
91 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
92 fftwf_plan_with_nthreads(threads);
93# else
94 (void)threads;
95# endif
96 PlanType plan = fftwf_plan_dft_c2r_3d(nx, ny, nz, in, out, flags);
97 return plan;
98 }
99 static PlanType
100 Plan_dft_c2r(int rank, const int * n, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
101 {
102# ifndef ITK_USE_CUFFTW
103 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
104 fftwf_plan_with_nthreads(threads);
105# else
106 (void)threads;
107# endif
108 PlanType plan = fftwf_plan_dft_c2r(rank, n, in, out, flags);
109 return plan;
110 }
111
112 static PlanType
113 Plan_dft_r2c_1d(int n, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
114 {
115# ifndef ITK_USE_CUFFTW
116 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
117 fftwf_plan_with_nthreads(threads);
118# else
119 (void)threads;
120# endif
121 PlanType plan = fftwf_plan_dft_r2c_1d(n, in, out, flags);
122 return plan;
123 }
124 static PlanType
125 Plan_dft_r2c_2d(int nx, int ny, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
126 {
127# ifndef ITK_USE_CUFFTW
128 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
129 fftwf_plan_with_nthreads(threads);
130# else
131 (void)threads;
132# endif
133 PlanType plan = fftwf_plan_dft_r2c_2d(nx, ny, in, out, flags);
134 return plan;
135 }
136 static PlanType
137 Plan_dft_r2c_3d(int nx, int ny, int nz, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
138 {
139# ifndef ITK_USE_CUFFTW
140 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
141 fftwf_plan_with_nthreads(threads);
142# else
143 (void)threads;
144# endif
145 PlanType plan = fftwf_plan_dft_r2c_3d(nx, ny, nz, in, out, flags);
146 return plan;
147 }
148 static PlanType
149 Plan_dft_r2c(int rank, const int * n, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
150 {
151# ifndef ITK_USE_CUFFTW
152 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
153 fftwf_plan_with_nthreads(threads);
154# else
155 (void)threads;
156# endif
157 PlanType plan = fftwf_plan_dft_r2c(rank, n, in, out, flags);
158 return plan;
159 }
160 static PlanType
161 Plan_dft_1d(const int n, ComplexType * in, ComplexType * out, int sign, unsigned flags, int threads = 1)
162 {
163# ifndef ITK_USE_CUFFTW
164 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
165 fftwf_plan_with_nthreads(threads);
166# else
167 (void)threads;
168# endif
169 PlanType plan = fftwf_plan_dft_1d(n, in, out, sign, flags);
170 return plan;
171 }
172
173
174 static void
175 Execute(PlanType p)
176 {
177 fftwf_execute(p);
178 }
179 static void
180 DestroyPlan(PlanType p)
181 {
182 fftwf_destroy_plan(p);
183 }
184};
185
186#endif // USE_FFTWF
187
188
189#if defined(ITK_USE_FFTWD)
190template <>
191class ComplexToComplexProxy<double>
192{
193public:
194 using PixelType = double;
195 using ComplexType = fftw_complex;
196 using PlanType = fftw_plan;
198
199 static PlanType
200 Plan_dft_c2r_1d(int n, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
201 {
202# ifndef ITK_USE_CUFFTW
203 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
204 fftw_plan_with_nthreads(threads);
205# else
206 (void)threads;
207# endif
208 PlanType plan = fftw_plan_dft_c2r_1d(n, in, out, flags);
209 return plan;
210 }
211 static PlanType
212 Plan_dft_c2r_2d(int nx, int ny, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
213 {
214# ifndef ITK_USE_CUFFTW
215 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
216 fftw_plan_with_nthreads(threads);
217# else
218 (void)threads;
219# endif
220 PlanType plan = fftw_plan_dft_c2r_2d(nx, ny, in, out, flags);
221 return plan;
222 }
223 static PlanType
224 Plan_dft_c2r_3d(int nx, int ny, int nz, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
225 {
226# ifndef ITK_USE_CUFFTW
227 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
228 fftw_plan_with_nthreads(threads);
229# else
230 (void)threads;
231# endif
232 PlanType plan = fftw_plan_dft_c2r_3d(nx, ny, nz, in, out, flags);
233 return plan;
234 }
235 static PlanType
236 Plan_dft_c2r(int rank, const int * n, ComplexType * in, PixelType * out, unsigned flags, int threads = 1)
237 {
238# ifndef ITK_USE_CUFFTW
239 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
240 fftw_plan_with_nthreads(threads);
241# else
242 (void)threads;
243# endif
244 PlanType plan = fftw_plan_dft_c2r(rank, n, in, out, flags);
245 return plan;
246 }
247
248 static PlanType
249 Plan_dft_r2c_1d(int n, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
250 {
251# ifndef ITK_USE_CUFFTW
252 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
253 fftw_plan_with_nthreads(threads);
254# else
255 (void)threads;
256# endif
257 PlanType plan = fftw_plan_dft_r2c_1d(n, in, out, flags);
258 return plan;
259 }
260
261 static PlanType
262 Plan_dft_r2c_2d(int nx, int ny, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
263 {
264# ifndef ITK_USE_CUFFTW
265 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
266 fftw_plan_with_nthreads(threads);
267# else
268 (void)threads;
269# endif
270 PlanType plan = fftw_plan_dft_r2c_2d(nx, ny, in, out, flags);
271 return plan;
272 }
273
274 static PlanType
275 Plan_dft_r2c_3d(int nx, int ny, int nz, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
276 {
277# ifndef ITK_USE_CUFFTW
278 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
279 fftw_plan_with_nthreads(threads);
280# else
281 (void)threads;
282# endif
283 PlanType plan = fftw_plan_dft_r2c_3d(nx, ny, nz, in, out, flags);
284 return plan;
285 }
286
287 static PlanType
288 Plan_dft_r2c(int rank, const int * n, PixelType * in, ComplexType * out, unsigned flags, int threads = 1)
289 {
290# ifndef ITK_USE_CUFFTW
291 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
292 fftw_plan_with_nthreads(threads);
293# else
294 (void)threads;
295# endif
296 PlanType plan = fftw_plan_dft_r2c(rank, n, in, out, flags);
297 return plan;
298 }
299 static PlanType
300 Plan_dft_1d(const int n, ComplexType * in, ComplexType * out, int sign, unsigned flags, int threads = 1)
301 {
302# ifndef ITK_USE_CUFFTW
303 std::lock_guard<FFTWGlobalConfiguration::MutexType> lock(FFTWGlobalConfiguration::GetLockMutex());
304 fftw_plan_with_nthreads(threads);
305# else
306 (void)threads;
307# endif
308 PlanType plan = fftw_plan_dft_1d(n, in, out, sign, flags);
309 return plan;
310 }
311
312 static void
313 Execute(PlanType p)
314 {
315 fftw_execute(p);
316 }
317 static void
318 DestroyPlan(PlanType p)
319 {
320 fftw_destroy_plan(p);
321 }
322};
323
324#endif
325} // namespace fftw
326} // namespace itk
327#endif
static std::mutex & GetLockMutex()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....