RTK  2.6.0
Reconstruction Toolkit
rtkReconstructionConjugateGradientOperator.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 rtkReconstructionConjugateGradientOperator_h
20 #define rtkReconstructionConjugateGradientOperator_h
21 
22 #include <itkMultiplyImageFilter.h>
23 #include <itkAddImageFilter.h>
24 
25 #include "rtkConstantImageSource.h"
26 
30 
34 
35 #ifdef RTK_USE_CUDA
38 #endif
39 
40 namespace rtk
41 {
42 
117 template <typename TOutputImage, typename TSingleComponentImage = TOutputImage, typename TWeightsImage = TOutputImage>
118 class ITK_TEMPLATE_EXPORT ReconstructionConjugateGradientOperator : public ConjugateGradientOperator<TOutputImage>
119 {
120 public:
121  ITK_DISALLOW_COPY_AND_MOVE(ReconstructionConjugateGradientOperator);
122 
127 #ifdef RTK_USE_CUDA
128  using GradientImageType =
129  itk::CudaImage<itk::CovariantVector<typename TOutputImage::PixelType, TOutputImage::ImageDimension>,
130  TOutputImage::ImageDimension>;
131 #else
132  using GradientImageType =
134  TOutputImage::ImageDimension>;
135 #endif
136 
138  itkNewMacro(Self);
139 
141  void
142  SetInputVolume(const TOutputImage * vol);
143  void
144  SetInputProjectionStack(const TOutputImage * projs);
145  void
146  SetInputWeights(const TWeightsImage * weights);
148 
150  itkOverrideGetNameOfClassMacro(ReconstructionConjugateGradientOperator);
151 
154 
157 
160  using AddFilterType = itk::AddImageFilter<TOutputImage>;
161 
162  // If TOutputImage is an itk::Image of floats or double, so are the weights, and a simple Multiply filter is required
163  // If TOutputImage is an itk::Image of itk::Vector<float (or double)>, a BlockDiagonalMatrixVectorMultiply filter
164  // is needed. Thus the meta-programming construct
167  typedef typename std::conditional<std::is_same<TSingleComponentImage, TOutputImage>::value,
170 
171  using OutputImagePointer = typename TOutputImage::Pointer;
172 
174  void
175  SetBackProjectionFilter(BackProjectionFilterType * _arg);
176 
178  void
179  SetForwardProjectionFilter(ForwardProjectionFilterType * _arg);
180 
182  void
183  SetSupportMask(const TSingleComponentImage * SupportMask);
184  typename TSingleComponentImage::ConstPointer
185  GetSupportMask();
187 
191  void
192  SetLocalRegularizationWeights(const TSingleComponentImage * localRegularizationWeights);
193  typename TSingleComponentImage::ConstPointer
194  GetLocalRegularizationWeights();
196 
198  itkSetConstObjectMacro(Geometry, ThreeDCircularProjectionGeometry);
199 
202  itkSetMacro(Gamma, float);
203  itkGetMacro(Gamma, float);
204  itkSetMacro(Tikhonov, float);
205  itkGetMacro(Tikhonov, float);
207 
208 protected:
210  ~ReconstructionConjugateGradientOperator() override = default;
211 
213  void
214  VerifyPreconditions() const override;
215 
217  void
218  GenerateData() override;
219 
220  template <typename ImageType>
221  typename std::enable_if<std::is_same<TSingleComponentImage, ImageType>::value, ImageType>::type::Pointer
222  ConnectGradientRegularization();
223 
224  template <typename ImageType>
225  typename std::enable_if<!std::is_same<TSingleComponentImage, ImageType>::value, ImageType>::type::Pointer
226  ConnectGradientRegularization();
227 
231 
239  typename AddFilterType::Pointer m_AddLaplacianFilter;
240  typename AddFilterType::Pointer m_AddTikhonovFilter;
242  typename MultiplyWithWeightsFilterType::Pointer m_MultiplyWithWeightsFilter;
243 
246  float m_Gamma{ 0 }; // Strength of the laplacian regularization
247  float m_Tikhonov{ 0 }; // Strength of the Tikhonov regularization
248 
250  typename TOutputImage::Pointer m_FloatingInputPointer, m_FloatingOutputPointer;
251 
254  void
255  VerifyInputInformation() const override
256  {}
257 
259  void
260  GenerateInputRequestedRegion() override;
261  void
262  GenerateOutputInformation() override;
264 
266  typename TOutputImage::ConstPointer
267  GetInputVolume();
268  typename TOutputImage::ConstPointer
269  GetInputProjectionStack();
270  typename TWeightsImage::ConstPointer
271  GetInputWeights();
272 };
273 } // namespace rtk
275 
276 
277 #ifndef ITK_MANUAL_INSTANTIATION
278 # include "rtkReconstructionConjugateGradientOperator.hxx"
279 #endif
280 
281 #endif
typename OutputImageType::Pointer OutputImagePointer
Implements the operator A used in conjugate gradient reconstruction.
Generate an n-dimensional image with constant pixel values.
std::conditional< std::is_same< TSingleComponentImage, TOutputImage >::value, PlainMultiplyFilterType, MatrixVectorMultiplyFilterType >::type MultiplyWithWeightsFilterType
typename BackProjectionFilterType::Pointer BackProjectionFilterPointer
Projection geometry for a source and a 2-D flat panel.
#define itkSetMacro(name, type)
typename ForwardProjectionFilterType::Pointer ForwardProjectionFilterPointer
itk::ImageToImageFilter< TOutputImage, TOutputImage >::Pointer m_LaplacianFilter