ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkDiscreteGradientMagnitudeGaussianImageFunction.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkDiscreteGradientMagnitudeGaussianImageFunction_h
00019 #define __itkDiscreteGradientMagnitudeGaussianImageFunction_h
00020 
00021 #include "itkNeighborhoodOperatorImageFunction.h"
00022 #include "itkGaussianDerivativeOperator.h"
00023 
00024 namespace itk
00025 {
00046 template< class TInputImage, class TOutput = double >
00047 class ITK_EXPORT DiscreteGradientMagnitudeGaussianImageFunction:
00048   public ImageFunction< TInputImage, TOutput, TOutput >
00049 {
00050 public:
00051 
00053   typedef DiscreteGradientMagnitudeGaussianImageFunction Self;
00054 
00056   typedef ImageFunction< TInputImage, TOutput, TOutput > Superclass;
00057 
00059   typedef SmartPointer< Self >       Pointer;
00060   typedef SmartPointer< const Self > ConstPointer;
00061 
00063   itkNewMacro(Self);
00064 
00066   itkTypeMacro(DiscreteGradientMagnitudeGaussianImageFunction, ImageFunction);
00067 
00069   typedef typename Superclass::InputImageType      InputImageType;
00070   typedef typename Superclass::InputPixelType      InputPixelType;
00071   typedef typename Superclass::IndexType           IndexType;
00072   typedef typename Superclass::IndexValueType      IndexValueType;
00073   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00074   typedef typename Superclass::PointType           PointType;
00075 
00077   itkStaticConstMacro(ImageDimension2, unsigned int,
00078                       InputImageType::ImageDimension);
00079 
00081   typedef typename Superclass::OutputType OutputType;
00082 
00084   typedef FixedArray< double, itkGetStaticConstMacro(ImageDimension2) >       VarianceArrayType;
00085   typedef FixedArray< unsigned int, itkGetStaticConstMacro(ImageDimension2) > OrderArrayType;
00087 
00088   typedef itk::GaussianDerivativeOperator< TOutput,
00089                                            itkGetStaticConstMacro(ImageDimension2) >    GaussianDerivativeOperatorType;
00090 
00092   typedef FixedArray< GaussianDerivativeOperatorType,
00093                       2 *itkGetStaticConstMacro(ImageDimension2) >            GaussianDerivativeOperatorArrayType;
00094 
00096   typedef Neighborhood< TOutput, itkGetStaticConstMacro(ImageDimension2) > KernelType;
00097 
00100   typedef FixedArray< KernelType, itkGetStaticConstMacro(ImageDimension2) > KernelArrayType;
00101 
00103   typedef NeighborhoodOperatorImageFunction
00104   < InputImageType, TOutput >                           OperatorImageFunctionType;
00105   typedef typename OperatorImageFunctionType::Pointer OperatorImageFunctionPointer;
00106 
00108   enum InterpolationModeType { NearestNeighbourInterpolation, LinearInterpolation };
00109 public:
00110 
00112   virtual OutputType Evaluate(const PointType & point) const;
00113 
00115   virtual OutputType EvaluateAtIndex(const IndexType & index) const;
00116 
00118   virtual OutputType EvaluateAtContinuousIndex(
00119     const ContinuousIndexType & index) const;
00120 
00125   itkSetMacro(Variance, VarianceArrayType);
00126   itkGetConstMacro(Variance, const VarianceArrayType);
00127   itkSetVectorMacro(Variance, double, VarianceArrayType::Length);
00129 
00131   virtual void SetVariance(double variance)
00132   {
00133     m_Variance.Fill(variance);
00134     this->Modified();
00135   }
00137 
00140   void SetSigma(const double sigma)
00141   {
00142     SetVariance(sigma * sigma);
00143   }
00144 
00150   itkSetClampMacro(MaximumError, double, 0.00001, 0.99999);
00151   itkGetConstMacro(MaximumError, double);
00153 
00157   itkSetMacro(NormalizeAcrossScale, bool);
00158   itkGetConstMacro(NormalizeAcrossScale, bool);
00159   itkBooleanMacro(NormalizeAcrossScale);
00161 
00163   itkSetMacro(UseImageSpacing, bool);
00164   itkGetConstMacro(UseImageSpacing, bool);
00165   itkBooleanMacro(UseImageSpacing);
00167 
00172   itkSetMacro(MaximumKernelWidth, unsigned int);
00173   itkGetConstMacro(MaximumKernelWidth, unsigned int);
00175 
00177   itkSetMacro(InterpolationMode, InterpolationModeType);
00178   itkGetConstMacro(InterpolationMode, InterpolationModeType);
00180 
00185   virtual void SetInputImage(const InputImageType *ptr);
00186 
00189   virtual void Initialize() { RecomputeGaussianKernel(); }
00190 protected:
00191 
00192   DiscreteGradientMagnitudeGaussianImageFunction();
00193   DiscreteGradientMagnitudeGaussianImageFunction(const Self &){}
00194 
00195   ~DiscreteGradientMagnitudeGaussianImageFunction(){}
00196 
00197   void operator=(const Self &){}
00198   void PrintSelf(std::ostream & os, Indent indent) const;
00199 
00200   void RecomputeGaussianKernel();
00201 
00202   // void RecomputeContinuousGaussianKernel(
00203   //        const double* offset) const;
00204 private:
00205 
00207   VarianceArrayType m_Variance;
00208 
00211   double m_MaximumError;
00212 
00216   unsigned int m_MaximumKernelWidth;
00217 
00221   GaussianDerivativeOperatorArrayType m_OperatorArray;
00222 
00224   KernelArrayType m_KernelArray;
00225 
00227   OperatorImageFunctionPointer m_OperatorImageFunction;
00228 
00230   bool m_NormalizeAcrossScale;
00231 
00233   bool m_UseImageSpacing;
00234 
00236   InterpolationModeType m_InterpolationMode;
00237 };
00238 } // namespace itk
00239 
00240 #if 0 //HACK:  Not yet implemented
00241 // Define instantiation macro for this template.
00242 #define ITK_TEMPLATE_DiscreteGradientMagnitudeGaussianImageFunction(_, EXPORT, TypeX, TypeY)     \
00243   namespace itk                                                                                  \
00244   {                                                                                              \
00245   _( 2 ( class EXPORT DiscreteGradientMagnitudeGaussianImageFunction< ITK_TEMPLATE_2 TypeX > ) ) \
00246   namespace Templates                                                                            \
00247   {                                                                                              \
00248   typedef DiscreteGradientMagnitudeGaussianImageFunction< ITK_TEMPLATE_2 TypeX >                 \
00249   DiscreteGradientMagnitudeGaussianImageFunction##TypeY;                                       \
00250   }                                                                                              \
00251   }
00252 
00253 #if ITK_TEMPLATE_EXPLICIT
00254 #include "Templates/itkDiscreteGradientMagnitudeGaussianImageFunction+-.h"
00255 #endif
00256 #endif
00257 
00258 #if ITK_TEMPLATE_TXX
00259 #include "itkDiscreteGradientMagnitudeGaussianImageFunction.hxx"
00260 #endif
00261 
00262 #endif
00263