ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkFFTConvolutionImageFilter.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 __itkFFTConvolutionImageFilter_h
00019 #define __itkFFTConvolutionImageFilter_h
00020 
00021 #include "itkConvolutionImageFilterBase.h"
00022 
00023 #include "itkProgressAccumulator.h"
00024 #include "itkHalfHermitianToRealInverseFFTImageFilter.h"
00025 #include "itkRealToHalfHermitianForwardFFTImageFilter.h"
00026 #include "itkZeroFluxNeumannBoundaryCondition.h"
00027 
00028 namespace itk
00029 {
00053 template< class TInputImage, class TKernelImage = TInputImage, class TOutputImage = TInputImage, class TInternalPrecision=double >
00054 class ITK_EXPORT FFTConvolutionImageFilter :
00055   public ConvolutionImageFilterBase< TInputImage, TKernelImage, TOutputImage >
00056 
00057 {
00058 public:
00059   typedef FFTConvolutionImageFilter                       Self;
00060   typedef ConvolutionImageFilterBase< TInputImage,
00061                                       TKernelImage,
00062                                       TOutputImage >
00063                                                           Superclass;
00064   typedef SmartPointer< Self >                            Pointer;
00065   typedef SmartPointer< const Self >                      ConstPointer;
00066 
00068   itkNewMacro(Self);
00069 
00071   itkTypeMacro(FFTConvolutionImageFilter, ConvolutionImageFilterBase);
00072 
00074   itkStaticConstMacro(ImageDimension, unsigned int,
00075                       TInputImage::ImageDimension);
00076 
00077   typedef TInputImage                           InputImageType;
00078   typedef TOutputImage                          OutputImageType;
00079   typedef TKernelImage                          KernelImageType;
00080   typedef typename InputImageType::PixelType    InputPixelType;
00081   typedef typename OutputImageType::PixelType   OutputPixelType;
00082   typedef typename KernelImageType::PixelType   KernelPixelType;
00083   typedef typename InputImageType::IndexType    InputIndexType;
00084   typedef typename OutputImageType::IndexType   OutputIndexType;
00085   typedef typename KernelImageType::IndexType   KernelIndexType;
00086   typedef typename InputImageType::SizeType     InputSizeType;
00087   typedef typename OutputImageType::SizeType    OutputSizeType;
00088   typedef typename KernelImageType::SizeType    KernelSizeType;
00089   typedef typename InputSizeType::SizeValueType SizeValueType;
00090   typedef typename InputImageType::RegionType   InputRegionType;
00091   typedef typename OutputImageType::RegionType  OutputRegionType;
00092   typedef typename KernelImageType::RegionType  KernelRegionType;
00093 
00095   typedef Image< TInternalPrecision, TInputImage::ImageDimension >  InternalImageType;
00096   typedef typename InternalImageType::Pointer                       InternalImagePointerType;
00097   typedef std::complex< TInternalPrecision >                        InternalComplexType;
00098   typedef Image< InternalComplexType, TInputImage::ImageDimension > InternalComplexImageType;
00099   typedef typename InternalComplexImageType::Pointer                InternalComplexImagePointerType;
00100 
00102   typedef typename Superclass::BoundaryConditionType        BoundaryConditionType;
00103   typedef typename Superclass::BoundaryConditionPointerType BoundaryConditionPointerType;
00104 
00105 protected:
00106   FFTConvolutionImageFilter();
00107   ~FFTConvolutionImageFilter() {}
00108 
00111   typedef RealToHalfHermitianForwardFFTImageFilter< InternalImageType,
00112                                                     InternalComplexImageType >
00113     FFTFilterType;
00114   typedef HalfHermitianToRealInverseFFTImageFilter< InternalComplexImageType,
00115                                                     InternalImageType >
00116     IFFTFilterType;
00117 
00125   void GenerateInputRequestedRegion();
00126 
00128   void GenerateData();
00129 
00134   void PrepareInputs(const InputImageType * input,
00135                      const KernelImageType * kernel,
00136                      InternalComplexImagePointerType & preparedInput,
00137                      InternalComplexImagePointerType & preparedKernel,
00138                      ProgressAccumulator * progress, float progressWeight);
00139 
00142   void PrepareInput(const InputImageType * input,
00143                     InternalComplexImagePointerType & preparedInput,
00144                     ProgressAccumulator * progress, float progressWeight);
00145 
00147   void PadInput(const InputImageType * input,
00148                 InternalImagePointerType & paddedInput,
00149                 ProgressAccumulator * progress, float progressWeight);
00150 
00152   void TransformPaddedInput(const InternalImageType * paddedInput,
00153                             InternalComplexImagePointerType & transformedInput,
00154                             ProgressAccumulator * progress, float progressWeight);
00155 
00159   void PrepareKernel(const KernelImageType * kernel,
00160                      InternalComplexImagePointerType & preparedKernel,
00161                      ProgressAccumulator * progress, float progressWeight);
00162 
00164   void ProduceOutput(InternalComplexImageType * paddedOutput,
00165                      ProgressAccumulator * progress,
00166                      float progressWeight);
00167 
00169   void CropOutput(InternalImageType * paddedOutput,
00170                   ProgressAccumulator * progress,
00171                   float progressWeight);
00172 
00179   InputSizeType GetPadLowerBound() const;
00180 
00182   InputSizeType GetPadSize() const;
00183 
00185   bool GetXDimensionIsOdd() const;
00186 
00187 private:
00188   FFTConvolutionImageFilter(const Self &); //purposely not implemented
00189   void operator=(const Self &);         //purposely not implemented
00190 };
00191 }
00192 
00193 #ifndef ITK_MANUAL_INSTANTIATION
00194 #include "itkFFTConvolutionImageFilter.hxx"
00195 #endif
00196 
00197 #endif
00198