ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkWindowedSincInterpolateImageFunction.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 __itkWindowedSincInterpolateImageFunction_h
00019 #define __itkWindowedSincInterpolateImageFunction_h
00020 
00021 #include "itkConstNeighborhoodIterator.h"
00022 #include "itkConstantBoundaryCondition.h"
00023 #include "itkInterpolateImageFunction.h"
00024 
00025 namespace itk
00026 {
00027 namespace Function
00028 {
00036 template< unsigned int VRadius,
00037           class TInput = double, class TOutput = double >
00038 class CosineWindowFunction
00039 {
00040 public:
00041   inline TOutput operator()(const TInput & A) const
00042   { return (TOutput)vcl_cos(A * m_Factor); }
00043 private:
00044 
00046   static const double m_Factor;
00047 };
00048 
00056 template< unsigned int VRadius,
00057           class TInput = double, class TOutput = double >
00058 class HammingWindowFunction
00059 {
00060 public:
00061   inline TOutput operator()(const TInput & A) const
00062   { return (TOutput)0.54 + 0.46 * vcl_cos(A * m_Factor); }
00063 private:
00064 
00066   static const double m_Factor;
00067 };
00068 
00076 template< unsigned int VRadius,
00077           class TInput = double, class TOutput = double >
00078 class WelchWindowFunction
00079 {
00080 public:
00081   inline TOutput operator()(const TInput & A) const
00082   { return (TOutput)( 1.0 - A * m_Factor * A ); }
00083 private:
00084 
00086   static const double m_Factor;
00087 };
00088 
00098 template< unsigned int VRadius,
00099           class TInput = double, class TOutput = double >
00100 class LanczosWindowFunction
00101 {
00102 public:
00103   inline TOutput operator()(const TInput & A) const
00104   {
00105     if ( A == 0.0 ) { return (TOutput)1.0; }
00106     double z = m_Factor * A;
00107     return (TOutput)( vcl_sin(z) / z );
00108   }
00110 
00111 private:
00113   static const double m_Factor;
00114 };
00115 
00123 template< unsigned int VRadius,
00124           class TInput = double, class TOutput = double >
00125 class BlackmanWindowFunction
00126 {
00127 public:
00128   inline TOutput operator()(const TInput & A) const
00129   {
00130     return (TOutput)
00131            ( 0.42 + 0.5 * vcl_cos(A * m_Factor1) + 0.08 * vcl_cos(A * m_Factor2) );
00132   }
00134 
00135 private:
00137   static const double m_Factor1;
00138 
00140   static const double m_Factor2;
00141 };
00142 } // namespace Function
00143 
00254 template<
00255   class TInputImage,
00256   unsigned int VRadius,
00257   class TWindowFunction = Function::HammingWindowFunction< VRadius >,
00258   class TBoundaryCondition = ConstantBoundaryCondition< TInputImage >,
00259   class TCoordRep = double >
00260 class ITK_EXPORT WindowedSincInterpolateImageFunction:
00261   public InterpolateImageFunction< TInputImage, TCoordRep >
00262 {
00263 public:
00264 
00266   typedef WindowedSincInterpolateImageFunction               Self;
00267   typedef InterpolateImageFunction< TInputImage, TCoordRep > Superclass;
00268 
00269   typedef SmartPointer< Self >       Pointer;
00270   typedef SmartPointer< const Self > ConstPointer;
00271 
00273   itkTypeMacro(WindowedSincInterpolateImageFunction,
00274                InterpolateImageFunction);
00275 
00277   itkNewMacro(Self);
00278 
00280   typedef typename Superclass::OutputType OutputType;
00281 
00283   typedef typename Superclass::InputImageType InputImageType;
00284 
00286   typedef typename Superclass::RealType RealType;
00287 
00289   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00290 
00292   typedef typename Superclass::IndexType      IndexType;
00293   typedef typename Superclass::IndexValueType IndexValueType;
00294 
00296   typedef TInputImage ImageType;
00297 
00299   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00300 
00301   virtual void SetInputImage(const ImageType *image);
00302 
00309   virtual OutputType EvaluateAtContinuousIndex(
00310     const ContinuousIndexType & index) const;
00311 
00312 protected:
00313   WindowedSincInterpolateImageFunction();
00314   virtual ~WindowedSincInterpolateImageFunction();
00315   void PrintSelf(std::ostream & os, Indent indent) const;
00316 
00317 private:
00318   WindowedSincInterpolateImageFunction(const Self &); //not implemented
00319   void operator=(const Self &);                       //purposely not
00320                                                       // implemented
00321 
00322   // Internal typedefs
00323   typedef ConstNeighborhoodIterator<
00324     ImageType, TBoundaryCondition > IteratorType;
00325 
00326   // Constant to store twice the radius
00327   static const unsigned int m_WindowSize;
00328 
00330   TWindowFunction m_WindowFunction;
00331 
00334   unsigned int *m_OffsetTable;
00335 
00337   unsigned int m_OffsetTableSize;
00338 
00340   unsigned int **m_WeightOffsetTable;
00341 
00343   inline double Sinc(double x) const
00344   {
00345     double px = vnl_math::pi * x;
00346 
00347     return ( x == 0.0 ) ? 1.0 : vcl_sin(px) / px;
00348   }
00349 };
00350 } // namespace itk
00351 
00352 #ifndef ITK_MANUAL_INSTANTIATION
00353 #include "itkWindowedSincInterpolateImageFunction.hxx"
00354 #endif
00355 
00356 #endif // _itkWindowedSincInterpolateImageFunction_h
00357