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);
72
74 static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
75 static constexpr unsigned int OutputImageDimension = TOutputImageType::ImageDimension;
76
78 using InputImageType = TInputImage;
79 using InputImagePointer = typename InputImageType::Pointer;
80 using OutputImageType = TOutputImageType;
81 using OutputImagePointer = typename OutputImageType::Pointer;
82
88
90 itkNewMacro(Self);
91
93 itkOverrideGetNameOfClassMacro(GradientImageFilter);
94
96 using InputPixelType = typename InputImageType::PixelType;
97 using OperatorValueType = TOperatorValueType;
98 using OutputValueType = TOutputValueType;
99 using OutputPixelType = typename OutputImageType::PixelType;
101 using OutputImageRegionType = typename OutputImageType::RegionType;
102
109 void
111
118 itkSetMacro(UseImageSpacing, bool);
119 itkGetConstMacro(UseImageSpacing, bool);
120 itkBooleanMacro(UseImageSpacing);
122#if !defined(ITK_FUTURE_LEGACY_REMOVE)
126 void
127 SetUseImageSpacingOn()
128 {
129 this->SetUseImageSpacing(true);
130 }
131
135 void
136 SetUseImageSpacingOff()
137 {
138 this->SetUseImageSpacing(false);
139 }
140#endif
141
143
147 void
148 SetBoundaryCondition(std::unique_ptr<BoundaryConditionType> boundaryCondition);
149
151 [[nodiscard]] const BoundaryConditionType *
153 {
154 return m_BoundaryCondition.get();
155 }
156
158 void
160 {
161 m_BoundaryCondition = std::make_unique<ZeroFluxNeumannBoundaryCondition<TInputImage>>();
162 this->Modified();
163 }
164
165#if !defined(ITK_FUTURE_LEGACY_REMOVE)
169 void
170 OverrideBoundaryCondition(ImageBoundaryCondition<TInputImage> * boundaryCondition);
171#endif
172
174 itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputValueType>));
175
187 itkSetMacro(UseImageDirection, bool);
188 itkGetConstMacro(UseImageDirection, bool);
189 itkBooleanMacro(UseImageDirection);
191protected:
193 ~GradientImageFilter() override = default;
194 void
195 PrintSelf(std::ostream & os, Indent indent) const override;
196
207 void
208 DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
209
210
211private:
212 void
214
215 // An overloaded method which may transform the gradient to a
216 // physical vector and converts to the correct output pixel type.
217 template <typename TValue>
218 void
220 {
221 if (this->m_UseImageDirection)
222 {
223 CovariantVectorType physicalGradient;
224 it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient);
225 it.Set(OutputPixelType(physicalGradient.GetDataPointer(), InputImageDimension, false));
226 }
227 else
228 {
229 it.Set(OutputPixelType(gradient.GetDataPointer(), InputImageDimension, false));
230 }
231 }
232
233 template <typename T>
234 void
236 {
237 // This uses the more efficient set by reference method
238 if (this->m_UseImageDirection)
239 {
240 it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value());
241 }
242 else
243 {
244 it.Value() = gradient;
245 }
246 }
247
248
249 bool m_UseImageSpacing{ true };
250
251 // flag to take or not the image direction into account
252 // when computing the derivatives.
254
255 // allow setting the m_BoundaryCondition
256 std::unique_ptr<ImageBoundaryCondition<TInputImage, TInputImage>> m_BoundaryCondition{
257 std::make_unique<ZeroFluxNeumannBoundaryCondition<TInputImage>>()
258 };
259};
260} // end namespace itk
261
262#ifndef ITK_MANUAL_INSTANTIATION
263# include "itkGradientImageFilter.hxx"
264#endif
265
266#endif
A templated class holding a n-Dimensional covariant vector.
ValueType * GetDataPointer()
ImageBoundaryCondition< TInputImage, TInputImage > BoundaryConditionType
TOperatorValueType OperatorValueType
typename OutputImageType::Pointer OutputImagePointer
const BoundaryConditionType * GetBoundaryCondition() const
void GenerateInputRequestedRegion() override
std::unique_ptr< ImageBoundaryCondition< TInputImage, TInputImage > > m_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
void SetBoundaryCondition(std::unique_ptr< BoundaryConditionType > boundaryCondition)
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:51
virtual void Modified() const
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....