RTK  2.5.0
Reconstruction Toolkit
rtkForwardDifferenceGradientImageFilter.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 rtkForwardDifferenceGradientImageFilter_h
20 #define rtkForwardDifferenceGradientImageFilter_h
21 
22 #include <itkImageToImageFilter.h>
23 #include <itkCovariantVector.h>
24 #include <itkImageRegionIterator.h>
25 
26 #include "rtkMacro.h"
27 
28 namespace rtk
29 {
50 template <typename TInputImage,
51  typename TOperatorValueType = float,
52  typename TOuputValue = float,
53  typename TOuputImage =
55 class ITK_TEMPLATE_EXPORT ForwardDifferenceGradientImageFilter
56  : public itk::ImageToImageFilter<TInputImage, TOuputImage>
57 {
58 public:
59  ITK_DISALLOW_COPY_AND_MOVE(ForwardDifferenceGradientImageFilter);
60 
62  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
63  static constexpr unsigned int OutputImageDimension = TOuputImage::ImageDimension;
64 
67 
69  using InputImageType = TInputImage;
70  using InputImagePointer = typename InputImageType::Pointer;
71  using OutputImageType = TOuputImage;
72  using OutputImagePointer = typename OutputImageType::Pointer;
73 
78 
80  itkNewMacro(Self);
81 
83 #ifdef itkOverrideGetNameOfClassMacro
84  itkOverrideGetNameOfClassMacro(ForwardDifferenceGradientImageFilter);
85 #else
87 #endif
88 
89 
91  using OperatorValueType = TOperatorValueType;
92  using OutputValueType = TOuputValue;
93  using InputPixelType = typename InputImageType::PixelType;
94  using CovariantVectorType = typename OutputImageType::PixelType;
95  using OutputImageRegionType = typename OutputImageType::RegionType;
96 
103  void
104  GenerateInputRequestedRegion() override;
105 
108  void
110  {
111  this->SetUseImageSpacing(true);
112  }
113 
116  void
118  {
119  this->SetUseImageSpacing(false);
120  }
121 
124  itkSetMacro(UseImageSpacing, bool);
125  itkGetConstMacro(UseImageSpacing, bool);
127 
131  void
132  SetDimensionsProcessed(bool * DimensionsProcessed);
133 
135  void
136  OverrideBoundaryCondition(itk::ImageBoundaryCondition<TInputImage> * boundaryCondition);
137 
138 #ifdef ITK_USE_CONCEPT_CHECKING
139  // Begin concept checking
142  // End concept checking
143 #endif
144 
155  itkSetMacro(UseImageDirection, bool);
156  itkGetConstMacro(UseImageDirection, bool);
157  itkBooleanMacro(UseImageDirection);
159 
160 protected:
163  void
164  PrintSelf(std::ostream & os, itk::Indent indent) const override;
165 
176  void
177  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
178 
179  void
180  GenerateOutputInformation() override;
181 
182 private:
183  // // An overloaded method which may transform the gradient to a
184  // // physical vector and converts to the correct output pixel type.
185  // template <typename TValue>
186  // void SetOutputPixel( ImageRegionIterator< VectorImage<TValue,OutputImageDimension> > &it, CovariantVectorType
187  // &gradient )
188  // {
189  // if ( this->m_UseImageDirection )
190  // {
191  // CovariantVectorType physicalGradient;
192  // it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, physicalGradient );
193  // it.Set( OutputPixelType( physicalGradient.GetDataPointer(), InputImageDimension, false ) );
194  // }
195  // else
196  // {
197  // it.Set( OutputPixelType( gradient.GetDataPointer(), InputImageDimension, false ) );
198  // }
199  // }
200 
201  template <typename T>
202  void
204  {
205  it.Value() = gradient;
206  }
207 
208 
210 
211  // flag to take or not the image direction into account
212  // when computing the derivatives.
214 
215  // list of the dimensions along which the gradient has
216  // to be computed. The components on other dimensions
217  // are set to zero
218  bool m_DimensionsProcessed[TInputImage::ImageDimension];
219 
222 };
223 } // namespace rtk
224 
225 #ifndef ITK_MANUAL_INSTANTIATION
226 # include "rtkForwardDifferenceGradientImageFilter.hxx"
227 #endif
228 
229 #endif
typename OutputImageType::Pointer OutputImagePointer
itk::ImageBoundaryCondition< TInputImage, TInputImage > * m_BoundaryCondition
#define itkSetMacro(name, type)
Computes the gradient of an image using forward difference.
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
void SetOutputPixel(itk::ImageRegionIterator< T > &it, CovariantVectorType &gradient)
#define itkConceptMacro(name, concept)