ITK  4.5.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 
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 
113  { this->SetUseImageSpacing(true); }
114 
118  { this->SetUseImageSpacing(false); }
119 
122  itkSetMacro(UseImageSpacing, bool);
123  itkGetConstMacro(UseImageSpacing, bool);
125 
126 #ifdef ITK_USE_CONCEPT_CHECKING
127  // Begin concept checking
128  itkConceptMacro( InputConvertibleToOutputCheck,
130  itkConceptMacro( OutputHasNumericTraitsCheck,
132  // End concept checking
133 #endif
134 
145  itkSetMacro(UseImageDirection, bool);
146  itkGetConstMacro(UseImageDirection, bool);
147  itkBooleanMacro(UseImageDirection);
149 
150 protected:
152  virtual ~GradientImageFilter();
153  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 <typename 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 <typename T >
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
virtual void GenerateInputRequestedRegion()
Light weight base class for most itk classes.
InputImageType::Pointer InputImagePointer
TOperatorValueType OperatorValueType
void SetOutputPixel(ImageRegionIterator< VectorImage< TValueType, OutputImageDimension > > &it, CovariantVectorType &gradient)
InputImageType::PixelType InputPixelType
Templated n-dimensional vector image class.
virtual void GenerateOutputInformation()
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId)
OutputImageType::RegionType OutputImageRegionType
ValueType * GetDataPointer()
OutputImageType::Pointer OutputImagePointer
SmartPointer< const Self > ConstPointer
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
CovariantVector< OutputValueType, itkGetStaticConstMacro(OutputImageDimension) > CovariantVectorType
void operator=(const Self &)
static const unsigned int OutputImageDimension
void PrintSelf(std::ostream &os, Indent indent) const
SmartPointer< Self > Pointer
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
#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
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
Computes the gradient of an image using directional derivatives.