ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkResampleImageFilter.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 __itkResampleImageFilter_h
00019 #define __itkResampleImageFilter_h
00020 
00021 #include "itkFixedArray.h"
00022 #include "itkTransform.h"
00023 #include "itkImageRegionIterator.h"
00024 #include "itkImageToImageFilter.h"
00025 #include "itkExtrapolateImageFunction.h"
00026 #include "itkLinearInterpolateImageFunction.h"
00027 #include "itkSize.h"
00028 #include "itkDefaultConvertPixelTraits.h"
00029 
00030 namespace itk
00031 {
00083 template< class TInputImage,
00084           class TOutputImage,
00085           class TInterpolatorPrecisionType = double >
00086 class ITK_EXPORT ResampleImageFilter:
00087   public ImageToImageFilter< TInputImage, TOutputImage >
00088 {
00089 public:
00091   typedef ResampleImageFilter                             Self;
00092   typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00093   typedef SmartPointer< Self >                            Pointer;
00094   typedef SmartPointer< const Self >                      ConstPointer;
00095 
00096   typedef TInputImage                           InputImageType;
00097   typedef TOutputImage                          OutputImageType;
00098   typedef typename InputImageType::Pointer      InputImagePointer;
00099   typedef typename InputImageType::ConstPointer InputImageConstPointer;
00100   typedef typename OutputImageType::Pointer     OutputImagePointer;
00101   typedef typename InputImageType::RegionType   InputImageRegionType;
00102 
00104   itkNewMacro(Self);
00105 
00107   itkTypeMacro(ResampleImageFilter, ImageToImageFilter);
00108 
00110   itkStaticConstMacro(ImageDimension, unsigned int,
00111                       TOutputImage::ImageDimension);
00112   itkStaticConstMacro(InputImageDimension, unsigned int,
00113                       TInputImage::ImageDimension);
00115 
00117   typedef ImageBase< itkGetStaticConstMacro(ImageDimension) > ImageBaseType;
00118 
00122   typedef Transform< TInterpolatorPrecisionType,
00123                      itkGetStaticConstMacro(ImageDimension),
00124                      itkGetStaticConstMacro(ImageDimension) >       TransformType;
00125   typedef typename TransformType::ConstPointer TransformPointerType;
00127 
00129   typedef InterpolateImageFunction< InputImageType,
00130                                     TInterpolatorPrecisionType >     InterpolatorType;
00131   typedef typename InterpolatorType::Pointer InterpolatorPointerType;
00132 
00133   typedef typename InterpolatorType::OutputType InterpolatorOutputType;
00134 
00135   typedef DefaultConvertPixelTraits< InterpolatorOutputType >        InterpolatorConvertType;
00136 
00137   typedef typename InterpolatorConvertType::ComponentType            ComponentType;
00138 
00139   typedef LinearInterpolateImageFunction< InputImageType,
00140                                           TInterpolatorPrecisionType >   LinearInterpolatorType;
00141   typedef typename LinearInterpolatorType::Pointer
00142   LinearInterpolatorPointerType;
00143 
00145   typedef ExtrapolateImageFunction< InputImageType,
00146                                     TInterpolatorPrecisionType >     ExtrapolatorType;
00147   typedef typename ExtrapolatorType::Pointer ExtrapolatorPointerType;
00148 
00150   typedef Size< itkGetStaticConstMacro(ImageDimension) > SizeType;
00151 
00153   typedef typename TOutputImage::IndexType IndexType;
00154 
00156   typedef typename InterpolatorType::PointType PointType;
00157   //typedef typename TOutputImage::PointType            PointType;
00158 
00160   typedef typename TOutputImage::PixelType PixelType;
00161   typedef typename TInputImage::PixelType  InputPixelType;
00162 
00163   typedef DefaultConvertPixelTraits<PixelType> PixelConvertType;
00164 
00165   typedef typename PixelConvertType::ComponentType PixelComponentType;
00166 
00168   typedef ContinuousIndex< TInterpolatorPrecisionType, ImageDimension >
00169                                            ContinuousInputIndexType;
00170 
00172   typedef typename TOutputImage::RegionType OutputImageRegionType;
00173 
00175   typedef typename TOutputImage::SpacingType   SpacingType;
00176   typedef typename TOutputImage::PointType     OriginPointType;
00177   typedef typename TOutputImage::DirectionType DirectionType;
00178 
00186   itkSetConstObjectMacro(Transform, TransformType);
00187 
00189   itkGetConstObjectMacro(Transform, TransformType);
00190 
00198   itkSetObjectMacro(Interpolator, InterpolatorType);
00199 
00201   itkGetConstObjectMacro(Interpolator, InterpolatorType);
00202 
00206   itkSetObjectMacro(Extrapolator, ExtrapolatorType);
00207 
00209   itkGetConstObjectMacro(Extrapolator, ExtrapolatorType);
00210 
00212   itkSetMacro(Size, SizeType);
00213 
00215   itkGetConstReferenceMacro(Size, SizeType);
00216 
00219   itkSetMacro(DefaultPixelValue, PixelType);
00220 
00222   itkGetConstReferenceMacro(DefaultPixelValue, PixelType);
00223 
00225   itkSetMacro(OutputSpacing, SpacingType);
00226   virtual void SetOutputSpacing(const double *values);
00228 
00230   itkGetConstReferenceMacro(OutputSpacing, SpacingType);
00231 
00233   itkSetMacro(OutputOrigin, OriginPointType);
00234   virtual void SetOutputOrigin(const double *values);
00236 
00238   itkGetConstReferenceMacro(OutputOrigin, OriginPointType);
00239 
00241   itkSetMacro(OutputDirection, DirectionType);
00242   itkGetConstReferenceMacro(OutputDirection, DirectionType);
00244 
00246   void SetOutputParametersFromImage(const ImageBaseType *image);
00247 
00250   itkSetMacro(OutputStartIndex, IndexType);
00251 
00253   itkGetConstReferenceMacro(OutputStartIndex, IndexType);
00254 
00260   void SetReferenceImage(const TOutputImage *image);
00261 
00262   const TOutputImage * GetReferenceImage() const;
00263 
00264   itkSetMacro(UseReferenceImage, bool);
00265   itkBooleanMacro(UseReferenceImage);
00266   itkGetConstMacro(UseReferenceImage, bool);
00267 
00273   virtual void GenerateOutputInformation();
00274 
00280   virtual void GenerateInputRequestedRegion();
00281 
00284   virtual void BeforeThreadedGenerateData();
00285 
00288   virtual void AfterThreadedGenerateData();
00289 
00291   unsigned long GetMTime(void) const;
00292 
00293 #ifdef ITK_USE_CONCEPT_CHECKING
00294 
00295   itkConceptMacro( OutputHasNumericTraitsCheck,
00296                    ( Concept::HasNumericTraits< PixelComponentType > ) );
00297 
00299 #endif
00300 protected:
00301   ResampleImageFilter();
00302   ~ResampleImageFilter() {}
00303   void PrintSelf(std::ostream & os, Indent indent) const;
00305 
00306 
00312   virtual void VerifyInputInformation() {}
00313 
00323   virtual void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
00324                             ThreadIdType threadId);
00325 
00328   virtual void NonlinearThreadedGenerateData(const OutputImageRegionType &
00329                                      outputRegionForThread,
00330                                      ThreadIdType threadId);
00331 
00335   virtual void LinearThreadedGenerateData(const OutputImageRegionType &
00336                                   outputRegionForThread,
00337                                   ThreadIdType threadId);
00338 
00339   virtual PixelType CastPixelWithBoundsChecking( const InterpolatorOutputType value,
00340                                                  const ComponentType minComponent,
00341                                                  const ComponentType maxComponent) const;
00342 
00343 private:
00344   ResampleImageFilter(const Self &); //purposely not implemented
00345   void operator=(const Self &);      //purposely not implemented
00346 
00347   SizeType                m_Size;      // Size of the output image
00348   TransformPointerType    m_Transform;         // Transform
00349   InterpolatorPointerType m_Interpolator;      // Image function for
00350                                                // interpolation
00351   ExtrapolatorPointerType m_Extrapolator;      // Image function for
00352                                                // extrapolation
00353   PixelType m_DefaultPixelValue;               // default pixel value
00354                                                // if the point is
00355                                                // outside the image
00356   SpacingType     m_OutputSpacing;             // output image spacing
00357   OriginPointType m_OutputOrigin;              // output image origin
00358   DirectionType   m_OutputDirection;           // output image direction cosines
00359   IndexType       m_OutputStartIndex;          // output image start index
00360   bool            m_UseReferenceImage;
00361 
00362 };
00363 } // end namespace itk
00364 
00365 #ifndef ITK_MANUAL_INSTANTIATION
00366 #include "itkResampleImageFilter.hxx"
00367 #endif
00368 
00369 #endif
00370