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 #ifdef itkOverrideGetNameOfClassMacro
151  itkOverrideGetNameOfClassMacro(ReconstructionConjugateGradientOperator);
152 #else
154 #endif
155 
156 
159 
162 
165  using AddFilterType = itk::AddImageFilter<TOutputImage>;
166 
167  // If TOutputImage is an itk::Image of floats or double, so are the weights, and a simple Multiply filter is required
168  // If TOutputImage is an itk::Image of itk::Vector<float (or double)>, a BlockDiagonalMatrixVectorMultiply filter
169  // is needed. Thus the meta-programming construct
172  typedef typename std::conditional<std::is_same<TSingleComponentImage, TOutputImage>::value,
175 
176  using OutputImagePointer = typename TOutputImage::Pointer;
177 
179  void
180  SetBackProjectionFilter(const BackProjectionFilterPointer _arg);
181 
183  void
184  SetForwardProjectionFilter(const ForwardProjectionFilterPointer _arg);
185 
187  void
188  SetSupportMask(const TSingleComponentImage * SupportMask);
189  typename TSingleComponentImage::ConstPointer
190  GetSupportMask();
192 
196  void
197  SetLocalRegularizationWeights(const TSingleComponentImage * localRegularizationWeights);
198  typename TSingleComponentImage::ConstPointer
199  GetLocalRegularizationWeights();
201 
203  itkSetConstObjectMacro(Geometry, ThreeDCircularProjectionGeometry);
204 
207  itkSetMacro(Gamma, float);
208  itkGetMacro(Gamma, float);
209  itkSetMacro(Tikhonov, float);
210  itkGetMacro(Tikhonov, float);
212 
213 protected:
215  ~ReconstructionConjugateGradientOperator() override = default;
216 
218  void
219  VerifyPreconditions() const override;
220 
222  void
223  GenerateData() override;
224 
225  template <typename ImageType>
226  typename std::enable_if<std::is_same<TSingleComponentImage, ImageType>::value, ImageType>::type::Pointer
227  ConnectGradientRegularization();
228 
229  template <typename ImageType>
230  typename std::enable_if<!std::is_same<TSingleComponentImage, ImageType>::value, ImageType>::type::Pointer
231  ConnectGradientRegularization();
232 
236 
244  typename AddFilterType::Pointer m_AddLaplacianFilter;
245  typename AddFilterType::Pointer m_AddTikhonovFilter;
247  typename MultiplyWithWeightsFilterType::Pointer m_MultiplyWithWeightsFilter;
248 
251  float m_Gamma{ 0 }; // Strength of the laplacian regularization
252  float m_Tikhonov{ 0 }; // Strength of the Tikhonov regularization
253 
255  typename TOutputImage::Pointer m_FloatingInputPointer, m_FloatingOutputPointer;
256 
259  void
260  VerifyInputInformation() const override
261  {}
262 
264  void
265  GenerateInputRequestedRegion() override;
266  void
267  GenerateOutputInformation() override;
269 
271  typename TOutputImage::ConstPointer
272  GetInputVolume();
273  typename TOutputImage::ConstPointer
274  GetInputProjectionStack();
275  typename TWeightsImage::ConstPointer
276  GetInputWeights();
277 };
278 } // namespace rtk
280 
281 
282 #ifndef ITK_MANUAL_INSTANTIATION
283 # include "rtkReconstructionConjugateGradientOperator.hxx"
284 #endif
285 
286 #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