ITK  4.10.0
Insight Segmentation and Registration 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 > class VectorImage;
30 
31 
54 template< typename TInputImage,
55  typename TOperatorValueType = float,
56  typename TOutputValueType = float,
57  typename TOutputImageType = Image< CovariantVector< TOutputValueType,
58  TInputImage::ImageDimension >,
59  TInputImage::ImageDimension > >
61  public ImageToImageFilter< TInputImage, TOutputImageType >
62 {
63 public:
65  itkStaticConstMacro(InputImageDimension, unsigned int,
66  TInputImage::ImageDimension);
67  itkStaticConstMacro(OutputImageDimension, unsigned int,
68  TInputImage::ImageDimension);
70 
72  typedef TInputImage InputImageType;
73  typedef typename InputImageType::Pointer InputImagePointer;
74  typedef TOutputImageType OutputImageType;
75  typedef typename OutputImageType::Pointer OutputImagePointer;
76 
82 
84  itkNewMacro(Self);
85 
88 
90  typedef typename InputImageType::PixelType InputPixelType;
91  typedef TOperatorValueType OperatorValueType;
92  typedef TOutputValueType OutputValueType;
93  typedef typename OutputImageType::PixelType OutputPixelType;
94  typedef CovariantVector<
95  OutputValueType, itkGetStaticConstMacro(OutputImageDimension) >
97  typedef typename OutputImageType::RegionType OutputImageRegionType;
98 
105  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
106 
110  { this->SetUseImageSpacing(true); }
111 
115  { this->SetUseImageSpacing(false); }
116 
119  itkSetMacro(UseImageSpacing, bool);
120  itkGetConstMacro(UseImageSpacing, bool);
122 
123 #ifdef ITK_USE_CONCEPT_CHECKING
124  // Begin concept checking
125  itkConceptMacro( InputConvertibleToOutputCheck,
127  itkConceptMacro( OutputHasNumericTraitsCheck,
129  // End concept checking
130 #endif
131 
142  itkSetMacro(UseImageDirection, bool);
143  itkGetConstMacro(UseImageDirection, bool);
144  itkBooleanMacro(UseImageDirection);
146 
147 protected:
149  virtual ~GradientImageFilter();
150  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
151 
162  void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
163  ThreadIdType threadId) ITK_OVERRIDE;
164 
165 private:
166  GradientImageFilter(const Self &) ITK_DELETE_FUNCTION;
167  void operator=(const Self &) ITK_DELETE_FUNCTION;
168 
169  virtual void GenerateOutputInformation() ITK_OVERRIDE;
170 
171  // An overloaded method which may transform the gradient to a
172  // physical vector and converts to the correct output pixel type.
173  template <typename TValue>
175  {
176  if ( this->m_UseImageDirection )
177  {
178  CovariantVectorType physicalGradient;
179  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, physicalGradient );
180  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), InputImageDimension, false ) );
181  }
182  else
183  {
184  it.Set( OutputPixelType( gradient.GetDataPointer(), InputImageDimension, false ) );
185  }
186  }
187 
188  template <typename T >
190  {
191  // This uses the more efficient set by reference method
192  if ( this->m_UseImageDirection )
193  {
194  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, it.Value() );
195  }
196  else
197  {
198  it.Value() = gradient;
199  }
200  }
201 
202 
204 
205  // flag to take or not the image direction into account
206  // when computing the derivatives.
208 };
209 } // end namespace itk
210 
211 #ifndef ITK_MANUAL_INSTANTIATION
212 #include "itkGradientImageFilter.hxx"
213 #endif
214 
215 #endif
InputImageType::Pointer InputImagePointer
void PrintSelf(std::ostream &os, Indent indent) const override
TOperatorValueType OperatorValueType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) override
InputImageType::PixelType InputPixelType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes...
Definition: itkArray.h:30
Templated n-dimensional vector image class.
virtual void GenerateOutputInformation() override
OutputImageType::RegionType OutputImageRegionType
void operator=(const Self &) ITK_DELETE_FUNCTION
void SetOutputPixel(ImageRegionIterator< VectorImage< TValue, OutputImageDimension > > &it, CovariantVectorType &gradient)
OutputImageType::Pointer OutputImagePointer
SmartPointer< const Self > ConstPointer
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
CovariantVector< OutputValueType, itkGetStaticConstMacro(OutputImageDimension) > CovariantVectorType
static const unsigned int OutputImageDimension
SmartPointer< Self > Pointer
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
virtual void SetUseImageSpacing(bool _arg)
OutputImageType::PixelType OutputPixelType
ImageToImageFilter< InputImageType, OutputImageType > Superclass
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void GenerateInputRequestedRegion() override
ValueType * GetDataPointer()
#define itkConceptMacro(name, concept)
static const unsigned int InputImageDimension
A templated class holding a n-Dimensional covariant vector.
A multi-dimensional iterator templated over image type that walks a region of pixels.
const ImageType * GetImage() const
Computes the gradient of an image using directional derivatives.