ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkInvertDisplacementFieldImageFilter.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 __itkInvertDisplacementFieldImageFilter_h
00019 #define __itkInvertDisplacementFieldImageFilter_h
00020 
00021 #include "itkImageToImageFilter.h"
00022 #include "itkVectorInterpolateImageFunction.h"
00023 
00024 namespace itk
00025 {
00026 
00038 template <class TInputImage, class TOutputImage = TInputImage>
00039 class InvertDisplacementFieldImageFilter
00040   : public ImageToImageFilter<TInputImage, TOutputImage>
00041 {
00042 public:
00043   typedef InvertDisplacementFieldImageFilter            Self;
00044   typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
00045   typedef SmartPointer<Self>                            Pointer;
00046   typedef SmartPointer<const Self>                      ConstPointer;
00047 
00049   itkNewMacro( Self );
00050 
00052   itkStaticConstMacro( ImageDimension, unsigned int, TInputImage::ImageDimension );
00053 
00054   typedef TInputImage                          InputFieldType;
00055   typedef TOutputImage                         OutputFieldType;
00056 
00057   typedef InputFieldType                       DisplacementFieldType;
00058   typedef OutputFieldType                      InverseDisplacementFieldType;
00059 
00061   typedef typename OutputFieldType::PixelType     PixelType;
00062   typedef typename OutputFieldType::PixelType     VectorType;
00063   typedef typename OutputFieldType::RegionType    RegionType;
00064   typedef typename OutputFieldType::IndexType     IndexType;
00065 
00066   typedef typename OutputFieldType::PointType     PointType;
00067   typedef typename OutputFieldType::SpacingType   SpacingType;
00068   typedef typename OutputFieldType::PointType     OriginType;
00069   typedef typename OutputFieldType::SizeType      SizeType;
00070   typedef typename OutputFieldType::DirectionType DirectionType;
00071 
00073   typedef typename VectorType::ComponentType                        RealType;
00074   typedef Image<RealType, ImageDimension>                           RealImageType;
00075   typedef VectorInterpolateImageFunction<InputFieldType, RealType>  InterpolatorType;
00076 
00078   itkGetObjectMacro( Interpolator, InterpolatorType );
00079 
00081   void SetDisplacementField( const InputFieldType *field )
00082     {
00083     itkDebugMacro( "setting deformation field to " << field );
00084     if ( field != this->GetInput( 0 ) )
00085       {
00086       this->SetInput( 0, field );
00087       this->Modified();
00088       if( ! this->m_Interpolator.IsNull() )
00089         {
00090         this->m_Interpolator->SetInputImage( field );
00091         }
00092       }
00093     }
00095 
00099   const InputFieldType* GetDisplacementField() const
00100     {
00101     return this->GetInput( 0 );
00102     }
00103 
00104   /* Set the interpolator. */
00105   virtual void SetInterpolator( InterpolatorType* interpolator );
00106 
00107   /* Set/Get the number of iterations */
00108   itkSetMacro( MaximumNumberOfIterations, unsigned int );
00109   itkGetConstMacro( MaximumNumberOfIterations, unsigned int );
00110 
00111   /* Set/Get the mean stopping criterion */
00112   itkSetMacro( MeanErrorToleranceThreshold, RealType );
00113   itkGetConstMacro( MeanErrorToleranceThreshold, RealType );
00114 
00115   /* Set/Get the max stopping criterion */
00116   itkSetMacro( MaxErrorToleranceThreshold, RealType );
00117   itkGetConstMacro( MaxErrorToleranceThreshold, RealType );
00118 
00119   /* Get the max norm */
00120   itkGetConstMacro( MaxErrorNorm, RealType );
00121 
00122   /* Get the mean norm */
00123   itkGetConstMacro( MeanErrorNorm, RealType );
00124 
00125 /* Should we force the boundary to have zero displacement? */
00126   itkSetMacro( EnforceBoundaryCondition, bool );
00127   itkGetMacro( EnforceBoundaryCondition, bool );
00128 
00129 protected:
00130 
00132   InvertDisplacementFieldImageFilter();
00133 
00135   virtual ~InvertDisplacementFieldImageFilter();
00136 
00138   void PrintSelf( std::ostream& os, Indent indent ) const;
00139 
00141   void GenerateData();
00142 
00144   void ThreadedGenerateData( const RegionType &, ThreadIdType );
00145 
00146 private:
00147   InvertDisplacementFieldImageFilter( const Self& ); //purposely not implemented
00148   void operator=( const Self& );                 //purposely not implemented
00149 
00151   typename InterpolatorType::Pointer                m_Interpolator;
00152 
00153   unsigned int                                      m_MaximumNumberOfIterations;
00154 
00155   RealType                                          m_MaxErrorToleranceThreshold;
00156   RealType                                          m_MeanErrorToleranceThreshold;
00157 
00158   // internal ivars necessary for multithreading basic operations
00159 
00160   typename DisplacementFieldType::Pointer           m_ComposedField;
00161   typename RealImageType::Pointer                   m_ScaledNormImage;
00162 
00163   RealType                                          m_MaxErrorNorm;
00164   RealType                                          m_MeanErrorNorm;
00165   RealType                                          m_Epsilon;
00166   SpacingType                                       m_DisplacementFieldSpacing;
00167   bool                                              m_DoThreadedEstimateInverse;
00168   bool                                              m_EnforceBoundaryCondition;
00169 
00170 };
00171 
00172 } // end namespace itk
00173 
00174 #ifndef ITK_MANUAL_INSTANTIATION
00175 #include "itkInvertDisplacementFieldImageFilter.hxx"
00176 #endif
00177 
00178 #endif
00179