ITK  4.2.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< class TInputImage,
55  class TOperatorValueType = float,
56  class TOutputValueType = float,
57  class TOutputImageType = Image< CovariantVector< TOutputValueType,
58  TInputImage::ImageDimension >,
59  TInputImage::ImageDimension > >
60 class ITK_EXPORT GradientImageFilter:
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 
73 
75  typedef TInputImage InputImageType;
76  typedef typename InputImageType::Pointer InputImagePointer;
77  typedef TOutputImageType OutputImageType;
78  typedef typename OutputImageType::Pointer OutputImagePointer;
79 
84 
86  itkNewMacro(Self);
87 
90 
92  typedef typename InputImageType::PixelType InputPixelType;
93  typedef TOperatorValueType OperatorValueType;
94  typedef TOutputValueType OutputValueType;
95  typedef typename OutputImageType::PixelType OutputPixelType;
96  typedef CovariantVector<
97  OutputValueType, itkGetStaticConstMacro(OutputImageDimension) >
99  typedef typename OutputImageType::RegionType OutputImageRegionType;
100 
107  virtual void GenerateInputRequestedRegion()
109 
112  void SetUseImageSpacingOn()
113  { this->SetUseImageSpacing(true); }
114 
117  void SetUseImageSpacingOff()
118  { this->SetUseImageSpacing(false); }
119 
122  itkSetMacro(UseImageSpacing, bool);
123  itkGetConstMacro(UseImageSpacing, bool);
125 
126 #ifdef ITK_USE_CONCEPT_CHECKING
127 
128  itkConceptMacro( InputConvertibleToOutputCheck,
130  itkConceptMacro( OutputHasNumericTraitsCheck,
132 
134 #endif
135 
146  itkSetMacro(UseImageDirection, bool);
147  itkGetConstMacro(UseImageDirection, bool);
148  itkBooleanMacro(UseImageDirection);
149 protected:
151  virtual ~GradientImageFilter();
152  void PrintSelf(std::ostream & os, Indent indent) const;
154 
165  void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
166  ThreadIdType threadId);
167 
168 private:
169  GradientImageFilter(const Self &); //purposely not implemented
170  void operator=(const Self &); //purposely not implemented
171 
172  virtual void GenerateOutputInformation();
173 
174  // An overloaded method which may transform the gradient to a
175  // physical vector and converts to the correct output pixel type.
176  template <class TValueType>
178  {
179  if ( this->m_UseImageDirection )
180  {
181  CovariantVectorType physicalGradient;
182  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, physicalGradient );
183  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), InputImageDimension, false ) );
184  }
185  else
186  {
187  it.Set( OutputPixelType( gradient.GetDataPointer(), InputImageDimension, false ) );
188  }
189  }
190 
191  template <class T >
192  void SetOutputPixel( ImageRegionIterator< T > &it, CovariantVectorType &gradient )
193  {
194  // This uses the more efficient set by reference method
195  if ( this->m_UseImageDirection )
196  {
197  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, it.Value() );
198  }
199  else
200  {
201  it.Value() = gradient;
202  }
203  }
204 
205 
207 
208  // flag to take or not the image direction into account
209  // when computing the derivatives.
211 };
212 } // end namespace itk
213 
214 #ifndef ITK_MANUAL_INSTANTIATION
215 #include "itkGradientImageFilter.hxx"
216 #endif
217 
218 #endif
219