RTK  2.0.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  * http://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"
27 // Back projection filters
29 
30 #ifdef RTK_USE_CUDA
34 #endif
35 
36 #include <random>
37 #include <algorithm>
38 
39 namespace rtk
40 {
41 
54 template<class TOutputImage,
55  class ProjectionStackType=TOutputImage>
57  public itk::ImageToImageFilter<TOutputImage, TOutputImage>
58 {
59 public:
60  ITK_DISALLOW_COPY_AND_ASSIGN(IterativeConeBeamReconstructionFilter);
61 
67 
69  using VolumeType = ProjectionStackType;
70  typedef enum {FP_UNKNOWN=-1,
71  FP_JOSEPH=0,
72  FP_CUDARAYCAST=2,
73  FP_JOSEPHATTENUATED=3} ForwardProjectionType;
74  typedef enum {BP_UNKNOWN=-1,
75  BP_VOXELBASED=0,
76  BP_JOSEPH=1,
77  BP_CUDAVOXELBASED=2,
78  BP_CUDARAYCAST=4,
79  BP_JOSEPHATTENUATED=5} BackProjectionType;
80 
86 
88  itkNewMacro(Self)
89 
90 
92 
94  virtual void SetForwardProjectionFilter (ForwardProjectionType fwtype);
95  ForwardProjectionType GetForwardProjectionFilter () { return m_CurrentForwardProjectionConfiguration; }
96  virtual void SetBackProjectionFilter (BackProjectionType bptype);
97  BackProjectionType GetBackProjectionFilter () { return m_CurrentBackProjectionConfiguration; }
99 
100 protected:
102  ~IterativeConeBeamReconstructionFilter() override = default;
103 
106  virtual BackProjectionPointerType InstantiateBackProjectionFilter (int bptype);
107 
110  virtual ForwardProjectionPointerType InstantiateForwardProjectionFilter (int fwtype);
111 
116 
119  std::default_random_engine m_DefaultRandomEngine = std::default_random_engine{};
120 
123  template < typename ImageType >
124  using EnableCudaScalarAndVectorType = typename std::enable_if< !std::is_same< CPUImageType, ImageType >::value &&
125  std::is_same< typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float >::value &&
127  itk::PixelTraits<typename ImageType::PixelType>::Dimension == 2 ||
128  itk::PixelTraits<typename ImageType::PixelType>::Dimension == 3 ) >::type;
129  template < typename ImageType >
130  using DisableCudaScalarAndVectorType = typename std::enable_if< std::is_same< CPUImageType, ImageType >::value ||
131  !std::is_same< typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float >::value ||
132  ( itk::PixelTraits<typename ImageType::PixelType>::Dimension != 1 &&
133  itk::PixelTraits<typename ImageType::PixelType>::Dimension != 2 &&
134  itk::PixelTraits<typename ImageType::PixelType>::Dimension != 3 ) >::type;
135  template < typename ImageType >
136  using EnableCudaScalarType = typename std::enable_if< !std::is_same< CPUImageType, ImageType >::value &&
137  std::is_same< typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float >::value &&
138  itk::PixelTraits<typename ImageType::PixelType>::Dimension == 1 >::type;
139  template < typename ImageType >
140  using DisableCudaScalarType = typename std::enable_if< std::is_same< CPUImageType, ImageType >::value ||
141  !std::is_same< typename itk::PixelTraits<typename ImageType::PixelType>::ValueType, float >::value ||
142  itk::PixelTraits<typename ImageType::PixelType>::Dimension != 1 >::type;
143  template < typename ImageType >
144  using EnableVectorType = typename std::enable_if< itk::PixelTraits<typename ImageType::PixelType>::Dimension != 1 >::type;
145  template < typename ImageType >
146  using DisableVectorType = typename std::enable_if< itk::PixelTraits<typename ImageType::PixelType>::Dimension == 1 >::type;
148 
149  template < typename ImageType, EnableCudaScalarAndVectorType<ImageType>* = nullptr >
151  {
153 #ifdef RTK_USE_CUDA
154  fw = CudaForwardProjectionImageFilter<ImageType, ImageType>::New();
155 #endif
156  return fw;
157  }
158 
159 
160  template < typename ImageType, DisableCudaScalarAndVectorType<ImageType>* = nullptr >
162  {
163  itkGenericExceptionMacro(<< "CudaRayCastBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
164  return nullptr;
165  }
166 
167 
168  template < typename ImageType, EnableVectorType<ImageType>* = nullptr >
170  {
171  itkGenericExceptionMacro(<< "JosephForwardAttenuatedProjectionImageFilter only available with scalar pixel types.");
172  return nullptr;
173  }
174 
175 
176  template < typename ImageType, DisableVectorType<ImageType>* = nullptr >
178  {
181  return fw;
182  }
183 
184 
185  template < typename ImageType, EnableCudaScalarAndVectorType<ImageType>* = nullptr >
187  {
189 #ifdef RTK_USE_CUDA
190  bp = CudaBackProjectionImageFilter<ImageType>::New();
191 #endif
192  return bp;
193  }
194 
195 
196  template < typename ImageType, DisableCudaScalarAndVectorType<ImageType>* = nullptr >
198  {
199  itkGenericExceptionMacro(<< "CudaBackProjectionImageFilter only available with 3D CudaImage of float or itk::Vector<float,3>.");
200  return nullptr;
201  }
202 
203 
204  template < typename ImageType, EnableCudaScalarType<ImageType>* = nullptr >
206  {
208 #ifdef RTK_USE_CUDA
209  bp = CudaRayCastBackProjectionImageFilter::New();
210 #endif
211  return bp;
212  }
213 
214 
215  template < typename ImageType, DisableCudaScalarType<ImageType>* = nullptr >
217  {
218  itkGenericExceptionMacro(<< "CudaRayCastBackProjectionImageFilter only available with 3D CudaImage of float.");
219  return nullptr;
220  }
221 
222 
223  template < typename ImageType, EnableVectorType<ImageType>* = nullptr >
225  {
226  itkGenericExceptionMacro(<< "JosephBackAttenuatedProjectionImageFilter only available with scalar pixel types.");
227  return nullptr;
228  }
229 
230 
231  template < typename ImageType, DisableVectorType<ImageType>* = nullptr >
233  {
236  return bp;
237  }
238 
239 }; // end of class
240 
241 } // end namespace rtk
242 
243 #ifndef ITK_MANUAL_INSTANTIATION
244 #include "rtkIterativeConeBeamReconstructionFilter.hxx"
245 #endif
246 
247 #endif
Base class for forward projection, i.e. accumulation along x-ray lines.
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
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 itk::Image< typename TOutputImage::PixelType, TOutputImage::ImageDimension > CPUImageType
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
Mother class for cone beam reconstruction filters which need runtime selection of their forward and b...
typename std::enable_if< itk::PixelTraits< typename ImageType::PixelType >::Dimension==1 >::type DisableVectorType