ITK  5.1.0
Insight Toolkit
itkGradientImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software 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 #ifndef itkGradientImageFilter_h
19 #define itkGradientImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkCovariantVector.h"
23 #include "itkImageRegionIterator.h"
24 
25 namespace itk
26 {
27 
28 
29 template <typename TPixelType, unsigned int VImageDimension>
30 class VectorImage;
31 
32 
60 template <typename TInputImage,
61  typename TOperatorValueType = float,
62  typename TOutputValueType = float,
63  typename TOutputImageType =
64  Image<CovariantVector<TOutputValueType, TInputImage::ImageDimension>, TInputImage::ImageDimension>>
65 class ITK_TEMPLATE_EXPORT GradientImageFilter : public ImageToImageFilter<TInputImage, TOutputImageType>
66 {
67 public:
68  ITK_DISALLOW_COPY_AND_ASSIGN(GradientImageFilter);
69 
71  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
72  static constexpr unsigned int OutputImageDimension = TOutputImageType::ImageDimension;
73 
75  using InputImageType = TInputImage;
76  using InputImagePointer = typename InputImageType::Pointer;
77  using OutputImageType = TOutputImageType;
78  using OutputImagePointer = typename OutputImageType::Pointer;
79 
85 
87  itkNewMacro(Self);
88 
91 
93  using InputPixelType = typename InputImageType::PixelType;
94  using OperatorValueType = TOperatorValueType;
95  using OutputValueType = TOutputValueType;
96  using OutputPixelType = typename OutputImageType::PixelType;
99 
106  void
107  GenerateInputRequestedRegion() override;
108 
111  void
113  {
114  this->SetUseImageSpacing(true);
115  }
116 
119  void
121  {
122  this->SetUseImageSpacing(false);
123  }
124 
127  itkSetMacro(UseImageSpacing, bool);
128  itkGetConstMacro(UseImageSpacing, bool);
129  itkBooleanMacro(UseImageSpacing);
130 
132  void
133  OverrideBoundaryCondition(ImageBoundaryCondition<TInputImage> * boundaryCondition);
134 
135 #ifdef ITK_USE_CONCEPT_CHECKING
136  // Begin concept checking
138  itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputValueType>));
139  // End concept checking
140 #endif
141 
152  itkSetMacro(UseImageDirection, bool);
153  itkGetConstMacro(UseImageDirection, bool);
154  itkBooleanMacro(UseImageDirection);
156 
157 protected:
159  ~GradientImageFilter() override;
160  void
161  PrintSelf(std::ostream & os, Indent indent) const override;
162 
173  void
174  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
175 
176 
177 private:
178  void
179  GenerateOutputInformation() override;
180 
181  // An overloaded method which may transform the gradient to a
182  // physical vector and converts to the correct output pixel type.
183  template <typename TValue>
184  void
186  {
187  if (this->m_UseImageDirection)
188  {
189  CovariantVectorType physicalGradient;
190  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient);
191  it.Set(OutputPixelType(physicalGradient.GetDataPointer(), InputImageDimension, false));
192  }
193  else
194  {
195  it.Set(OutputPixelType(gradient.GetDataPointer(), InputImageDimension, false));
196  }
197  }
198 
199  template <typename T>
200  void
202  {
203  // This uses the more efficient set by reference method
204  if (this->m_UseImageDirection)
205  {
206  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value());
207  }
208  else
209  {
210  it.Value() = gradient;
211  }
212  }
213 
214 
216 
217  // flag to take or not the image direction into account
218  // when computing the derivatives.
220 
221  // allow setting the the m_BoundaryCondition
223 };
224 } // end namespace itk
225 
226 #ifndef ITK_MANUAL_INSTANTIATION
227 # include "itkGradientImageFilter.hxx"
228 #endif
229 
230 #endif
itk::GradientImageFilter::SetUseImageSpacingOn
void SetUseImageSpacingOn()
Definition: itkGradientImageFilter.h:112
itk::GradientImageFilter::m_UseImageDirection
bool m_UseImageDirection
Definition: itkGradientImageFilter.h:219
itk::GradientImageFilter::InputImageType
TInputImage InputImageType
Definition: itkGradientImageFilter.h:75
itk::GradientImageFilter::SetUseImageSpacingOff
void SetUseImageSpacingOff()
Definition: itkGradientImageFilter.h:120
itk::GradientImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkGradientImageFilter.h:76
itkCovariantVector.h
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:712
itk::GradientImageFilter::OutputImageType
TOutputImageType OutputImageType
Definition: itkGradientImageFilter.h:77
itk::VectorImage
Templated n-dimensional vector image class.
Definition: itkImageAlgorithm.h:29
itk::ImageConstIterator::GetImage
const ImageType * GetImage() const
Definition: itkImageConstIterator.h:336
itk::GradientImageFilter::m_UseImageSpacing
bool m_UseImageSpacing
Definition: itkGradientImageFilter.h:215
itk::SmartPointer< Self >
itkImageRegionIterator.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::GradientImageFilter::m_BoundaryCondition
ImageBoundaryCondition< TInputImage, TInputImage > * m_BoundaryCondition
Definition: itkGradientImageFilter.h:222
itk::FixedArray::GetDataPointer
ValueType * GetDataPointer()
Definition: itkFixedArray.h:313
itk::ImageBoundaryCondition
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
Definition: itkImageBoundaryCondition.h:52
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:78
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::GradientImageFilter::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkGradientImageFilter.h:98
itkImageToImageFilter.h
itk::GradientImageFilter
Computes the gradient of an image using directional derivatives.
Definition: itkGradientImageFilter.h:65
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:68
itk::GradientImageFilter::OutputValueType
TOutputValueType OutputValueType
Definition: itkGradientImageFilter.h:95
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Concept::Convertible
Definition: itkConceptChecking.h:214
itk::GradientImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkGradientImageFilter.h:93
itk::GradientImageFilter::SetOutputPixel
void SetOutputPixel(ImageRegionIterator< VectorImage< TValue, OutputImageDimension >> &it, CovariantVectorType &gradient)
Definition: itkGradientImageFilter.h:185
itk::GradientImageFilter::SetOutputPixel
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
Definition: itkGradientImageFilter.h:201
itk::GradientImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkGradientImageFilter.h:96
itk::GradientImageFilter::OperatorValueType
TOperatorValueType OperatorValueType
Definition: itkGradientImageFilter.h:94
itk::ImageRegionIterator::Value
PixelType & Value()
Definition: itkImageRegionIterator.h:123
itk::GradientImageFilter::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkGradientImageFilter.h:78