ITK  4.4.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);
150 
151 protected:
153  virtual ~GradientImageFilter();
154  void PrintSelf(std::ostream & os, Indent indent) const;
155 
166  void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
167  ThreadIdType threadId);
168 
169 private:
170  GradientImageFilter(const Self &); //purposely not implemented
171  void operator=(const Self &); //purposely not implemented
172 
173  virtual void GenerateOutputInformation();
174 
175  // An overloaded method which may transform the gradient to a
176  // physical vector and converts to the correct output pixel type.
177  template <class TValueType>
179  {
180  if ( this->m_UseImageDirection )
181  {
182  CovariantVectorType physicalGradient;
183  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, physicalGradient );
184  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), InputImageDimension, false ) );
185  }
186  else
187  {
188  it.Set( OutputPixelType( gradient.GetDataPointer(), InputImageDimension, false ) );
189  }
190  }
191 
192  template <class T >
193  void SetOutputPixel( ImageRegionIterator< T > &it, CovariantVectorType &gradient )
194  {
195  // This uses the more efficient set by reference method
196  if ( this->m_UseImageDirection )
197  {
198  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, it.Value() );
199  }
200  else
201  {
202  it.Value() = gradient;
203  }
204  }
205 
206 
208 
209  // flag to take or not the image direction into account
210  // when computing the derivatives.
212 };
213 } // end namespace itk
214 
215 #ifndef ITK_MANUAL_INSTANTIATION
216 #include "itkGradientImageFilter.hxx"
217 #endif
218 
219 #endif
220