RTK  2.4.1
Reconstruction Toolkit
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
36 #endif
37 
38 #include <random>
39 #include <algorithm>
40 
41 namespace rtk
42 {
43 
56 template <class TOutputImage, class ProjectionStackType = TOutputImage>
57 class ITK_TEMPLATE_EXPORT IterativeConeBeamReconstructionFilter
58  : public itk::ImageToImageFilter<TOutputImage, TOutputImage>
59 {
60 public:
61  ITK_DISALLOW_COPY_AND_MOVE(IterativeConeBeamReconstructionFilter);
62 
68 
70  using VolumeType = ProjectionStackType;
71  typedef enum
72  {
73  FP_JOSEPH = 0,
74  FP_CUDARAYCAST = 2,
75  FP_JOSEPHATTENUATED = 3,
76  FP_ZENG = 4
77  } ForwardProjectionType;
78  typedef enum
79  {
80  BP_VOXELBASED = 0,
81  BP_JOSEPH = 1,
82  BP_CUDAVOXELBASED = 2,
83  BP_CUDARAYCAST = 4,
84  BP_JOSEPHATTENUATED = 5,
85  BP_ZENG = 6
86  } BackProjectionType;
87 
93 
95  itkNewMacro(Self);
96 
99 
101  virtual void
102  SetForwardProjectionFilter(ForwardProjectionType fwtype);
105  {
106  return m_CurrentForwardProjectionConfiguration;
107  }
108  virtual void
109  SetBackProjectionFilter(BackProjectionType bptype);
110  BackProjectionType
112  {
113  return m_CurrentBackProjectionConfiguration;
114  }
116 
117 protected:
119  ~IterativeConeBeamReconstructionFilter() override = default;
120 
123  virtual BackProjectionPointerType
124  InstantiateBackProjectionFilter(int bptype);
125 
128  virtual ForwardProjectionPointerType
129  InstantiateForwardProjectionFilter(int fwtype);
130 
135 
138  std::default_random_engine m_DefaultRandomEngine = std::default_random_engine{};
139 
141  using CPUImageType =
143  template <typename ImageType>
144  using EnableCudaScalarAndVectorType = typename std::enable_if<
145  !std::is_same<CPUImageType, ImageType>::value &&
146  std::is_same<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float>::value &&
150  template <typename ImageType>
151  using DisableCudaScalarAndVectorType = typename std::enable_if<
152  std::is_same<CPUImageType, ImageType>::value ||
153  !std::is_same<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float>::value ||
157  template <typename ImageType>
158  using EnableCudaScalarType = typename std::enable_if<
159  !std::is_same<CPUImageType, ImageType>::value &&
160  std::is_same<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float>::value &&
162  template <typename ImageType>
163  using DisableCudaScalarType = typename std::enable_if<
164  std::is_same<CPUImageType, ImageType>::value ||
165  !std::is_same<typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float>::value ||
167  template <typename ImageType>
168  using EnableVectorType =
169  typename std::enable_if<itk::PixelTraits<typename ImageType::PixelType>::Dimension != 1>::type;
170  template <typename ImageType>
171  using DisableVectorType =
172  typename std::enable_if<itk::PixelTraits<typename ImageType::PixelType>::Dimension == 1>::type;
174 
175  template <typename ImageType, EnableCudaScalarAndVectorType<ImageType> * = nullptr>
178  {
180 #ifdef RTK_USE_CUDA
181  fw = CudaForwardProjectionImageFilter<ImageType, ImageType>::New();
182 #endif
183  return fw;
184  }
185 
186 
187  template <typename ImageType, DisableCudaScalarAndVectorType<ImageType> * = nullptr>
188  ForwardProjectionPointerType
190  {
191  itkGenericExceptionMacro(
192  << "CudaRayCastBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
193  return nullptr;
194  }
195 
196 
197  template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
198  ForwardProjectionPointerType
200  {
201  itkGenericExceptionMacro(<< "JosephForwardAttenuatedProjectionImageFilter only available with scalar pixel types.");
202  return nullptr;
203  }
204 
205 
206  template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
207  ForwardProjectionPointerType
209  {
212  return fw;
213  }
214 
215  template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
216  ForwardProjectionPointerType
218  {
219  itkGenericExceptionMacro(<< "JosephForwardAttenuatedProjectionImageFilter only available with scalar pixel types.");
220  return nullptr;
221  }
222 
223 
224  template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
225  ForwardProjectionPointerType
227  {
230  return fw;
231  }
232 
233  template <typename ImageType, EnableCudaScalarAndVectorType<ImageType> * = nullptr>
234  BackProjectionPointerType
236  {
238 #ifdef RTK_USE_CUDA
239  bp = CudaBackProjectionImageFilter<ImageType>::New();
240 #endif
241  return bp;
242  }
243 
244 
245  template <typename ImageType, DisableCudaScalarAndVectorType<ImageType> * = nullptr>
246  BackProjectionPointerType
248  {
249  itkGenericExceptionMacro(
250  << "CudaBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
251  return nullptr;
252  }
253 
254 
255  template <typename ImageType, EnableCudaScalarType<ImageType> * = nullptr>
256  BackProjectionPointerType
258  {
260 #ifdef RTK_USE_CUDA
261  bp = CudaRayCastBackProjectionImageFilter::New();
262 #endif
263  return bp;
264  }
265 
266 
267  template <typename ImageType, DisableCudaScalarType<ImageType> * = nullptr>
268  BackProjectionPointerType
270  {
271  itkGenericExceptionMacro(<< "CudaRayCastBackProjectionImageFilter only available with 3D CudaImage of float.");
272  return nullptr;
273  }
274 
275 
276  template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
277  BackProjectionPointerType
279  {
280  itkGenericExceptionMacro(<< "JosephBackAttenuatedProjectionImageFilter only available with scalar pixel types.");
281  return nullptr;
282  }
283 
284 
285  template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
286  BackProjectionPointerType
288  {
291  return bp;
292  }
293 
294  template <typename ImageType, EnableVectorType<ImageType> * = nullptr>
295  BackProjectionPointerType
297  {
298  itkGenericExceptionMacro(<< "JosephBackAttenuatedProjectionImageFilter only available with scalar pixel types.");
299  return nullptr;
300  }
301 
302 
303  template <typename ImageType, DisableVectorType<ImageType> * = nullptr>
304  BackProjectionPointerType
306  {
309  return bp;
310  }
311 
312 }; // end of class
313 
314 } // end namespace rtk
315 
316 #ifndef ITK_MANUAL_INSTANTIATION
317 # include "rtkIterativeConeBeamReconstructionFilter.hxx"
318 #endif
319 
320 #endif
Base class for forward projection, i.e. accumulation along x-ray lines.
typename std::enable_if< itk::PixelTraits< typename ImageType::PixelType >::Dimension==1 >::type DisableVectorType
typename std::enable_if< !std::is_same< CPUImageType, ImageType >::value &&std::is_same< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float >::value &&(itk::PixelTraits< typename ImageType::PixelType >::Dimension==1||itk::PixelTraits< typename ImageType::PixelType >::Dimension==2||itk::PixelTraits< typename ImageType::PixelType >::Dimension==3)>::type EnableCudaScalarAndVectorType
typename std::enable_if< !std::is_same< CPUImageType, ImageType >::value &&std::is_same< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float >::value &&itk::PixelTraits< typename ImageType::PixelType >::Dimension==1 >::type EnableCudaScalarType
Mother class for cone beam reconstruction filters which need runtime selection of their forward and b...
typename std::enable_if< std::is_same< CPUImageType, ImageType >::value||!std::is_same< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float >::value||(itk::PixelTraits< typename ImageType::PixelType >::Dimension !=1 &&itk::PixelTraits< typename ImageType::PixelType >::Dimension !=2 &&itk::PixelTraits< typename ImageType::PixelType >::Dimension !=3)>::type DisableCudaScalarAndVectorType
typename std::enable_if< itk::PixelTraits< typename ImageType::PixelType >::Dimension !=1 >::type EnableVectorType
typename std::enable_if< std::is_same< CPUImageType, ImageType >::value||!std::is_same< typename itk::PixelTraits< typename ImageType::PixelType >::ValueType, float >::value||itk::PixelTraits< typename ImageType::PixelType >::Dimension !=1 >::type DisableCudaScalarType