ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkWarpImageFilter.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 __itkWarpImageFilter_h
00019 #define __itkWarpImageFilter_h
00020 #include "itkImageBase.h"
00021 #include "itkImageToImageFilter.h"
00022 #include "itkLinearInterpolateImageFunction.h"
00023 
00024 namespace itk
00025 {
00083 template<
00084   class TInputImage,
00085   class TOutputImage,
00086   class TDisplacementField
00087   >
00088 class ITK_EXPORT WarpImageFilter:
00089   public ImageToImageFilter< TInputImage, TOutputImage >
00090 {
00091 public:
00093   typedef WarpImageFilter                                 Self;
00094   typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00095   typedef SmartPointer< Self >                            Pointer;
00096   typedef SmartPointer< const Self >                      ConstPointer;
00097 
00099   itkNewMacro(Self);
00100 
00102   itkTypeMacro(WarpImageFilter, ImageToImageFilter);
00103 
00105   typedef typename TOutputImage::RegionType OutputImageRegionType;
00106 
00108   typedef typename Superclass::InputImageType         InputImageType;
00109   typedef typename Superclass::InputImagePointer      InputImagePointer;
00110   typedef typename Superclass::OutputImageType        OutputImageType;
00111   typedef typename Superclass::OutputImagePointer     OutputImagePointer;
00112   typedef typename Superclass::InputImageConstPointer InputImageConstPointer;
00113   typedef typename OutputImageType::IndexType         IndexType;
00114   typedef typename OutputImageType::IndexValueType    IndexValueType;
00115   typedef typename OutputImageType::SizeType          SizeType;
00116   typedef typename OutputImageType::PixelType         PixelType;
00117   typedef typename OutputImageType::SpacingType       SpacingType;
00118 
00120   itkStaticConstMacro(ImageDimension, unsigned int,
00121                       TOutputImage::ImageDimension);
00122   itkStaticConstMacro(InputImageDimension, unsigned int,
00123                       TInputImage::ImageDimension);
00124   itkStaticConstMacro(DisplacementFieldDimension, unsigned int,
00125                       TDisplacementField::ImageDimension);
00126 
00128   typedef ImageBase< itkGetStaticConstMacro(ImageDimension) > ImageBaseType;
00129 
00131   typedef TDisplacementField                        DisplacementFieldType;
00132   typedef typename DisplacementFieldType::Pointer   DisplacementFieldPointer;
00133   typedef typename DisplacementFieldType::PixelType DisplacementType;
00134 
00135 #ifdef ITKV3_COMPATIBILITY
00136   typedef TDisplacementField                       DeformationFieldType;
00137   typedef typename DeformationFieldType::Pointer   DeformationFieldPointer;
00138   typedef typename DeformationFieldType::PixelType DeformationType;
00139 #endif
00140 
00142   typedef double                                                   CoordRepType;
00143   typedef InterpolateImageFunction< InputImageType, CoordRepType > InterpolatorType;
00144   typedef typename InterpolatorType::Pointer                       InterpolatorPointer;
00145   typedef LinearInterpolateImageFunction< InputImageType, CoordRepType >
00146   DefaultInterpolatorType;
00147 
00149   typedef Point< CoordRepType, itkGetStaticConstMacro(ImageDimension) > PointType;
00150 
00152   typedef typename TOutputImage::DirectionType DirectionType;
00153 
00155   void SetDisplacementField(const DisplacementFieldType *field);
00156 
00158   DisplacementFieldType * GetDisplacementField(void);
00159 
00160 #ifdef ITKV3_COMPATIBILITY
00161   void SetDeformationField(const DisplacementFieldType *field)
00162   {
00163     this->SetDisplacementField(field);
00164   }
00165   DeformationFieldType * GetDeformationField(void)
00166   {
00167     return static_cast<DeformationFieldType *> (GetDisplacementField());
00168   }
00169 #endif
00170 
00172   itkSetObjectMacro(Interpolator, InterpolatorType);
00173 
00175   itkGetObjectMacro(Interpolator, InterpolatorType);
00176 
00178   itkSetMacro(OutputSpacing, SpacingType);
00179   virtual void SetOutputSpacing(const double *values);
00181 
00183   itkGetConstReferenceMacro(OutputSpacing, SpacingType);
00184 
00186   itkSetMacro(OutputOrigin, PointType);
00187   virtual void SetOutputOrigin(const double *values);
00189 
00191   itkGetConstReferenceMacro(OutputOrigin, PointType);
00192 
00194   itkSetMacro(OutputDirection, DirectionType);
00195   itkGetConstReferenceMacro(OutputDirection, DirectionType);
00197 
00199   void SetOutputParametersFromImage(const ImageBaseType *image);
00200 
00203   itkSetMacro(OutputStartIndex, IndexType);
00204 
00206   itkGetConstReferenceMacro(OutputStartIndex, IndexType);
00207 
00209   itkSetMacro(OutputSize, SizeType);
00210 
00212   itkGetConstReferenceMacro(OutputSize, SizeType);
00213 
00215   itkSetMacro(EdgePaddingValue, PixelType);
00216 
00218   itkGetConstMacro(EdgePaddingValue, PixelType);
00219 
00225   virtual void GenerateOutputInformation();
00226 
00233   virtual void GenerateInputRequestedRegion();
00234 
00237   virtual void BeforeThreadedGenerateData();
00238 
00241   virtual void AfterThreadedGenerateData();
00242 
00243 #ifdef ITK_USE_CONCEPT_CHECKING
00244 
00245   itkConceptMacro( SameDimensionCheck1,
00246                    ( Concept::SameDimension< ImageDimension, InputImageDimension > ) );
00247   itkConceptMacro( SameDimensionCheck2,
00248                    ( Concept::SameDimension< ImageDimension, DisplacementFieldDimension > ) );
00249   itkConceptMacro( InputHasNumericTraitsCheck,
00250                    ( Concept::HasNumericTraits< typename TInputImage::PixelType > ) );
00251   itkConceptMacro( DisplacementFieldHasNumericTraitsCheck,
00252                    ( Concept::HasNumericTraits< typename TDisplacementField::PixelType::ValueType > ) );
00253 
00255 #endif
00256 protected:
00257   WarpImageFilter();
00258   // ~WarpImageFilter() {} default implementation is ok
00259 
00260   void PrintSelf(std::ostream & os, Indent indent) const;
00261 
00265   void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
00266                             ThreadIdType threadId);
00267 
00273   virtual void VerifyInputInformation() {}
00274 
00275 private:
00276   WarpImageFilter(const Self &); //purposely not implemented
00277   void operator=(const Self &);  //purposely not implemented
00278 
00282   DisplacementType EvaluateDisplacementAtPhysicalPoint(const PointType & p);
00283 
00284   PixelType     m_EdgePaddingValue;
00285   SpacingType   m_OutputSpacing;
00286   PointType     m_OutputOrigin;
00287   DirectionType m_OutputDirection;
00288 
00289   InterpolatorPointer m_Interpolator;
00290   SizeType            m_OutputSize;               // Size of the output image
00291   IndexType           m_OutputStartIndex;         // output image start index
00292   bool                m_DefFieldSizeSame;
00293   // variables for deffield interpoator
00294   IndexType m_StartIndex, m_EndIndex;
00295 };
00296 } // end namespace itk
00297 
00298 #ifndef ITK_MANUAL_INSTANTIATION
00299 #include "itkWarpImageFilter.hxx"
00300 #endif
00301 
00302 #endif
00303