ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
rtkIterativeConeBeamReconstructionFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright RTK Consortium
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
19#ifndef rtkIterativeConeBeamReconstructionFilter_h
20#define rtkIterativeConeBeamReconstructionFilter_h
21
22#include <itkPixelTraits.h>
23
24// Forward projection filters
25#include "rtkConfiguration.h"
28// Back projection filters
31
32#ifdef RTK_USE_CUDA
40#endif
41
42#include <algorithm>
43#include <random>
44
45namespace rtk
46{
47
60template <class TOutputImage, class ProjectionStackType = TOutputImage>
62 : public itk::ImageToImageFilter<TOutputImage, TOutputImage>
63{
64public:
65 ITK_DISALLOW_COPY_AND_MOVE(IterativeConeBeamReconstructionFilter);
66
72
74 using VolumeType = ProjectionStackType;
76 using ForwardProjectionType = enum {
77 FP_JOSEPH = 0,
78 FP_CUDARAYCAST = 2,
79 FP_JOSEPHATTENUATED = 3,
80 FP_ZENG = 4,
81 FP_CUDAWARP = 5,
82 FP_CUDAZENG = 6
83 };
84 using BackProjectionType = enum {
85 BP_VOXELBASED = 0,
86 BP_JOSEPH = 1,
87 BP_CUDAVOXELBASED = 2,
88 BP_CUDARAYCAST = 4,
89 BP_JOSEPHATTENUATED = 5,
90 BP_ZENG = 6,
91 BP_CUDAWARP = 7,
92 BP_CUDAZENG = 8
93 };
94
100
102 itkNewMacro(Self);
103
105 itkOverrideGetNameOfClassMacro(IterativeConeBeamReconstructionFilter);
106
108 virtual void
115 virtual void
122
125 void
126 SetAttenuationMap(const VolumeType * attenuationMap)
127 {
128 // Process object is not const-correct so the const casting is required.
129 this->SetNthInput(2, const_cast<VolumeType *>(attenuationMap));
130 }
131 typename VolumeType::ConstPointer
133 {
134 return static_cast<const VolumeType *>(this->itk::ProcessObject::GetInput(2));
135 }
136
140 void
141 SetInferiorClipImage(const TClipImageType * inferiorClipImage)
142 {
143 // Process object is not const-correct so the const casting is required.
144 this->SetInput("InferiorClipImage", const_cast<TClipImageType *>(inferiorClipImage));
145 }
146 typename TClipImageType::ConstPointer
148 {
149 return static_cast<const TClipImageType *>(this->itk::ProcessObject::GetInput("InferiorClipImage"));
150 }
151
155 void
156 SetSuperiorClipImage(const TClipImageType * superiorClipImage)
157 {
158 // Process object is not const-correct so the const casting is required.
159 this->SetInput("SuperiorClipImage", const_cast<TClipImageType *>(superiorClipImage));
160 }
161 typename TClipImageType::ConstPointer
163 {
164 return static_cast<const TClipImageType *>(this->itk::ProcessObject::GetInput("SuperiorClipImage"));
165 }
166
168 itkGetMacro(SigmaZero, double);
169 itkSetMacro(SigmaZero, double);
170
172 itkGetMacro(AlphaPSF, double);
173 itkSetMacro(AlphaPSF, double);
174
176 itkGetConstMacro(StepSize, double);
177 itkSetMacro(StepSize, double);
178
179protected:
182
187
192
197
200 std::default_random_engine m_DefaultRandomEngine;
201
203 double m_SigmaZero{ 1.5417233052142099 };
204 double m_AlphaPSF{ 0.016241189545787734 };
205
207 double m_StepSize{ 1.0 };
208
212 template <typename ImageType>
214 std::enable_if_t<!std::is_same_v<CPUImageType, ImageType> &&
215 std::is_same_v<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float> &&
219 template <typename ImageType>
221 std::enable_if_t<std::is_same_v<CPUImageType, ImageType> ||
222 !std::is_same_v<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float> ||
226 template <typename ImageType>
228 std::enable_if_t<!std::is_same_v<CPUImageType, ImageType> &&
229 std::is_same_v<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float> &&
231 template <typename ImageType>
233 std::enable_if_t<std::is_same_v<CPUImageType, ImageType> ||
234 !std::is_same_v<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float> ||
236 template <typename ImageType>
237 using EnableVectorType = std::enable_if_t<itk::PixelTraits<typename ImageType::PixelType>::Dimension != 1>;
238 template <typename ImageType>
239 using DisableVectorType = std::enable_if_t<itk::PixelTraits<typename ImageType::PixelType>::Dimension == 1>;
240
241 template <typename ImageType, EnableCudaScalarAndVectorType<ImageType> * = nullptr>
244 {
246#ifdef RTK_USE_CUDA
247 auto cudaFw = CudaForwardProjectionImageFilter<ImageType, ImageType>::New();
248 cudaFw->SetStepSize(m_StepSize);
249 fw = cudaFw;
250#endif
251 return fw;
252 }
253
254
255 template <typename ImageType, DisableCudaScalarAndVectorType<ImageType> * = nullptr>
256 ForwardProjectionPointerType
258 {
259 itkGenericExceptionMacro(
260 << "CudaRayCastBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
261 return nullptr;
262 }
263
264
265 template <typename ImageType, EnableCudaScalarType<ImageType> * = nullptr>
266 ForwardProjectionPointerType
268 {
270#ifdef RTK_USE_CUDA
271 auto cudaWarpFw = CudaWarpForwardProjectionImageFilter::New();
272 cudaWarpFw->SetStepSize(m_StepSize);
273 fw = cudaWarpFw;
274#endif
275 return fw;
276 }
277
278
279 template <typename ImageType, DisableCudaScalarType<ImageType> * = nullptr>
280 ForwardProjectionPointerType
282 {
283 itkGenericExceptionMacro(
284 << "CudaWarpForwardProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
285 return nullptr;
286 }
287
288
289 template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
290 ForwardProjectionPointerType
292 {
293 itkGenericExceptionMacro(<< "JosephForwardAttenuatedProjectionImageFilter only available with scalar pixel types.");
294 return nullptr;
295 }
296
297
298 template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
299 ForwardProjectionPointerType
301 {
303 if (this->GetAttenuationMap().IsNotNull())
304 {
305 josephAttenuatedForward->SetInput(2, this->GetAttenuationMap());
306 }
307 else
308 {
309 itkExceptionMacro(<< "Set Joseph attenuated forward projection filter but no attenuation map is given");
310 return nullptr;
311 }
312 if (this->GetSuperiorClipImage().IsNotNull())
313 {
314 josephAttenuatedForward->SetSuperiorClipImage(this->GetSuperiorClipImage());
315 }
316 if (this->GetInferiorClipImage().IsNotNull())
317 {
318 josephAttenuatedForward->SetInferiorClipImage(this->GetInferiorClipImage());
319 }
320 return josephAttenuatedForward.GetPointer();
321 }
322
323 template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
324 ForwardProjectionPointerType
326 {
327 itkGenericExceptionMacro(<< "JosephForwardAttenuatedProjectionImageFilter only available with scalar pixel types.");
328 return nullptr;
329 }
330
331 template <typename ImageType, EnableCudaScalarType<ImageType> * = nullptr>
332 ForwardProjectionPointerType
334 {
336#ifdef RTK_USE_CUDA
337 auto zeng = CudaZengForwardProjectionImageFilter::New();
338 if (this->GetAttenuationMap().IsNotNull())
339 zeng->SetInput(2, this->GetAttenuationMap());
340 zeng->SetSigmaZero(m_SigmaZero);
341 zeng->SetAlpha(m_AlphaPSF);
342 fw = zeng;
343#endif
344 return fw;
345 }
346
347 template <typename ImageType, DisableCudaScalarType<ImageType> * = nullptr>
348 ForwardProjectionPointerType
350 {
351 itkGenericExceptionMacro(<< "CudaZengForwardProjectionImageFilter only available with 3D CudaImage<float>.");
352 return nullptr;
353 }
354
355
356 template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
357 ForwardProjectionPointerType
359 {
361 if (this->GetAttenuationMap().IsNotNull())
362 {
363 zengForward->SetInput(2, this->GetAttenuationMap());
364 }
365 zengForward->SetSigmaZero(m_SigmaZero);
366 zengForward->SetAlpha(m_AlphaPSF);
367 return zengForward.GetPointer();
368 }
369
370 template <typename ImageType, EnableCudaScalarAndVectorType<ImageType> * = nullptr>
371 BackProjectionPointerType
373 {
375#ifdef RTK_USE_CUDA
376 bp = CudaBackProjectionImageFilter<ImageType>::New();
377#endif
378 return bp;
379 }
380
381
382 template <typename ImageType, DisableCudaScalarAndVectorType<ImageType> * = nullptr>
383 BackProjectionPointerType
385 {
386 itkGenericExceptionMacro(
387 << "CudaBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
388 return nullptr;
389 }
390
391
392 template <typename ImageType, EnableCudaScalarType<ImageType> * = nullptr>
393 BackProjectionPointerType
395 {
397#ifdef RTK_USE_CUDA
398 bp = CudaWarpBackProjectionImageFilter::New();
399#endif
400 return bp;
401 }
402
403
404 template <typename ImageType, DisableCudaScalarType<ImageType> * = nullptr>
405 BackProjectionPointerType
407 {
408 itkGenericExceptionMacro(
409 << "CudaWarpBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
410 return nullptr;
411 }
412
413 template <typename ImageType, EnableCudaScalarType<ImageType> * = nullptr>
414 BackProjectionPointerType
416 {
418#ifdef RTK_USE_CUDA
419 auto cudaRayCastBp = CudaRayCastBackProjectionImageFilter::New();
420 cudaRayCastBp->SetStepSize(m_StepSize);
421 bp = cudaRayCastBp;
422#endif
423 return bp;
424 }
425
426
427 template <typename ImageType, DisableCudaScalarType<ImageType> * = nullptr>
428 BackProjectionPointerType
430 {
431 itkGenericExceptionMacro(<< "CudaRayCastBackProjectionImageFilter only available with 3D CudaImage of float.");
432 return nullptr;
433 }
434
435
436 template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
437 BackProjectionPointerType
439 {
440 itkGenericExceptionMacro(<< "JosephBackAttenuatedProjectionImageFilter only available with scalar pixel types.");
441 return nullptr;
442 }
443
444
445 template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
446 BackProjectionPointerType
448 {
451 if (this->GetAttenuationMap().IsNotNull())
452 {
453 bp->SetInput(2, this->GetAttenuationMap());
454 return bp;
455 }
456 else
457 {
458 itkExceptionMacro(<< "Set Joseph attenuated backprojection filter but no attenuation map is given");
459 return nullptr;
460 }
461 }
462
463 template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
464 BackProjectionPointerType
466 {
467 itkGenericExceptionMacro(<< "JosephBackAttenuatedProjectionImageFilter only available with scalar pixel types.");
468 return nullptr;
469 }
470
471 template <typename ImageType, EnableCudaScalarType<ImageType> * = nullptr>
472 BackProjectionPointerType
474 {
476#ifdef RTK_USE_CUDA
477 auto zeng = CudaZengBackProjectionImageFilter::New();
478 if (this->GetAttenuationMap().IsNotNull())
479 zeng->SetInput(2, this->GetAttenuationMap());
480 zeng->SetSigmaZero(m_SigmaZero);
481 zeng->SetAlpha(m_AlphaPSF);
482 bp = zeng;
483#endif
484 return bp;
485 }
486
487 template <typename ImageType, DisableCudaScalarType<ImageType> * = nullptr>
488 BackProjectionPointerType
490 {
491 itkGenericExceptionMacro(<< "CudaZengBackProjectionImageFilter only available with 3D CudaImage<float>.");
492 return nullptr;
493 }
494
495
496 template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
497 BackProjectionPointerType
499 {
501 if (this->GetAttenuationMap().IsNotNull())
502 {
503 zengBack->SetInput(2, this->GetAttenuationMap());
504 }
505 zengBack->SetSigmaZero(m_SigmaZero);
506 zengBack->SetAlpha(m_AlphaPSF);
507 return zengBack.GetPointer();
508 }
509
510}; // end of class
511
512} // end namespace rtk
513
514#ifndef ITK_MANUAL_INSTANTIATION
515# include "rtkIterativeConeBeamReconstructionFilter.hxx"
516#endif
517
518#endif
Base class for filters that take an image as input and produce an image as output.
virtual void SetInput(const InputImageType *input)
Templated n-dimensional image class.
Definition itkImage.h:89
Traits for a pixel that define the dimension and component type.
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
Implements transparent reference counting.
Base class for forward projection, i.e. accumulation along x-ray lines.
std::enable_if_t< itk::PixelTraits< typename ImageType::PixelType >::Dimension !=1 > EnableVectorType
typename itk::Image< typename TOutputImage::PixelType, TOutputImage::ImageDimension > CPUImageType
std::enable_if_t<!std::is_same_v< CPUImageType, ImageType > &&std::is_same_v< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float > &&(itk::PixelTraits< typename ImageType::PixelType >::Dimension==1||itk::PixelTraits< typename ImageType::PixelType >::Dimension==2||itk::PixelTraits< typename ImageType::PixelType >::Dimension==3)> EnableCudaScalarAndVectorType
virtual void SetForwardProjectionFilter(ForwardProjectionType fwtype)
virtual void SetBackProjectionFilter(BackProjectionType bptype)
rtk::ForwardProjectionImageFilter< VolumeType, TOutputImage > ForwardProjectionFilterType
std::enable_if_t<!std::is_same_v< CPUImageType, ImageType > &&std::is_same_v< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float > &&itk::PixelTraits< typename ImageType::PixelType >::Dimension==1 > EnableCudaScalarType
void SetSuperiorClipImage(const TClipImageType *superiorClipImage)
std::enable_if_t< itk::PixelTraits< typename ImageType::PixelType >::Dimension==1 > DisableVectorType
virtual BackProjectionPointerType InstantiateBackProjectionFilter(int bptype)
enum { FP_JOSEPH=0, FP_CUDARAYCAST=2, FP_JOSEPHATTENUATED=3, FP_ZENG=4, FP_CUDAWARP=5, FP_CUDAZENG=6 } ForwardProjectionType
void SetInferiorClipImage(const TClipImageType *inferiorClipImage)
virtual ForwardProjectionPointerType InstantiateForwardProjectionFilter(int fwtype)
std::enable_if_t< std::is_same_v< CPUImageType, ImageType >||!std::is_same_v< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float >||itk::PixelTraits< typename ImageType::PixelType >::Dimension !=1 > DisableCudaScalarType
enum { BP_VOXELBASED=0, BP_JOSEPH=1, BP_CUDAVOXELBASED=2, BP_CUDARAYCAST=4, BP_JOSEPHATTENUATED=5, BP_ZENG=6, BP_CUDAWARP=7, BP_CUDAZENG=8 } BackProjectionType
~IterativeConeBeamReconstructionFilter() override=default
std::enable_if_t< std::is_same_v< CPUImageType, ImageType >||!std::is_same_v< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float >||(itk::PixelTraits< typename ImageType::PixelType >::Dimension !=1 &&itk::PixelTraits< typename ImageType::PixelType >::Dimension !=2 &&itk::PixelTraits< typename ImageType::PixelType >::Dimension !=3)> DisableCudaScalarAndVectorType
#define itkSetMacro(name, type)