ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkGradientImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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#ifndef itkGradientImageFilter_h
19#define itkGradientImageFilter_h
20
22#include "itkCovariantVector.h"
25#include <memory> // For unique_ptr.
26
27namespace itk
28{
29
30
31template <typename TPixelType, unsigned int VImageDimension>
32class VectorImage;
33
34
63template <typename TInputImage,
64 typename TOperatorValueType = float,
65 typename TOutputValueType = float,
66 typename TOutputImageType =
68class ITK_TEMPLATE_EXPORT GradientImageFilter : public ImageToImageFilter<TInputImage, TOutputImageType>
69{
70public:
71 ITK_DISALLOW_COPY_AND_MOVE(GradientImageFilter);
73
75 static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
76 static constexpr unsigned int OutputImageDimension = TOutputImageType::ImageDimension;
77
79 using InputImageType = TInputImage;
80 using InputImagePointer = typename InputImageType::Pointer;
81 using OutputImageType = TOutputImageType;
82 using OutputImagePointer = typename OutputImageType::Pointer;
83
89
91 itkNewMacro(Self);
92
94 itkOverrideGetNameOfClassMacro(GradientImageFilter);
95
97 using InputPixelType = typename InputImageType::PixelType;
98 using OperatorValueType = TOperatorValueType;
99 using OutputValueType = TOutputValueType;
100 using OutputPixelType = typename OutputImageType::PixelType;
102 using OutputImageRegionType = typename OutputImageType::RegionType;
103
110 void
112
118 itkSetMacro(UseImageSpacing, bool);
119 itkGetConstMacro(UseImageSpacing, bool);
120 itkBooleanMacro(UseImageSpacing);
122
123#if !defined(ITK_FUTURE_LEGACY_REMOVE)
127 void
128 SetUseImageSpacingOn()
129 {
130 this->SetUseImageSpacing(true);
131 }
132
136 void
137 SetUseImageSpacingOff()
138 {
139 this->SetUseImageSpacing(false);
140 }
141#endif
142
144 void
146
148 itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputValueType>));
149
160 itkSetMacro(UseImageDirection, bool);
161 itkGetConstMacro(UseImageDirection, bool);
162 itkBooleanMacro(UseImageDirection);
164
165protected:
167 ~GradientImageFilter() override = default;
168 void
169 PrintSelf(std::ostream & os, Indent indent) const override;
170
181 void
182 DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
183
184
185private:
186 void
188
189 // An overloaded method which may transform the gradient to a
190 // physical vector and converts to the correct output pixel type.
191 template <typename TValue>
192 void
194 {
195 if (this->m_UseImageDirection)
196 {
197 CovariantVectorType physicalGradient;
198 it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient);
199 it.Set(OutputPixelType(physicalGradient.GetDataPointer(), InputImageDimension, false));
200 }
201 else
202 {
203 it.Set(OutputPixelType(gradient.GetDataPointer(), InputImageDimension, false));
204 }
205 }
206
207 template <typename T>
208 void
210 {
211 // This uses the more efficient set by reference method
212 if (this->m_UseImageDirection)
213 {
214 it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value());
215 }
216 else
217 {
218 it.Value() = gradient;
219 }
220 }
221
222
223 bool m_UseImageSpacing{ true };
224
225 // flag to take or not the image direction into account
226 // when computing the derivatives.
228
229 // allow setting the the m_BoundaryCondition
230 std::unique_ptr<ImageBoundaryCondition<TInputImage, TInputImage>> m_BoundaryCondition{
231 std::make_unique<ZeroFluxNeumannBoundaryCondition<TInputImage>>()
232 };
233};
234} // end namespace itk
235
236#ifndef ITK_MANUAL_INSTANTIATION
237# include "itkGradientImageFilter.hxx"
238#endif
239
240#endif
A templated class holding a n-Dimensional covariant vector.
ValueType * GetDataPointer()
TOperatorValueType OperatorValueType
typename OutputImageType::Pointer OutputImagePointer
void GenerateInputRequestedRegion() override
std::unique_ptr< ImageBoundaryCondition< TInputImage, TInputImage > > m_BoundaryCondition
void OverrideBoundaryCondition(ImageBoundaryCondition< TInputImage > *boundaryCondition)
typename OutputImageType::RegionType OutputImageRegionType
typename OutputImageType::PixelType OutputPixelType
void PrintSelf(std::ostream &os, Indent indent) const override
CovariantVector< OutputValueType, Self::OutputImageDimension > CovariantVectorType
virtual void SetUseImageSpacing(bool _arg)
ImageToImageFilter< InputImageType, OutputImageType > Superclass
SmartPointer< const Self > ConstPointer
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void GenerateOutputInformation() override
typename InputImageType::PixelType InputPixelType
~GradientImageFilter() override=default
static constexpr unsigned int InputImageDimension
void SetOutputPixel(ImageRegionIterator< VectorImage< TValue, OutputImageDimension > > &it, CovariantVectorType &gradient)
static constexpr unsigned int OutputImageDimension
typename InputImageType::Pointer InputImagePointer
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
const ImageType * GetImage() const
A multi-dimensional iterator templated over image type that walks a region of pixels.
Templated n-dimensional image class.
Definition itkImage.h:89
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
Templated n-dimensional vector image class.
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....