ITK  4.2.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 
00105   itkSetInputMacro( InverseFieldInitialEstimate, InverseDisplacementFieldType );
00106   itkGetInputMacro( InverseFieldInitialEstimate, InverseDisplacementFieldType );
00108 
00109   /* Set the interpolator. */
00110   virtual void SetInterpolator( InterpolatorType* interpolator );
00111 
00112   /* Set/Get the number of iterations */
00113   itkSetMacro( MaximumNumberOfIterations, unsigned int );
00114   itkGetConstMacro( MaximumNumberOfIterations, unsigned int );
00115 
00116   /* Set/Get the mean stopping criterion */
00117   itkSetMacro( MeanErrorToleranceThreshold, RealType );
00118   itkGetConstMacro( MeanErrorToleranceThreshold, RealType );
00119 
00120   /* Set/Get the max stopping criterion */
00121   itkSetMacro( MaxErrorToleranceThreshold, RealType );
00122   itkGetConstMacro( MaxErrorToleranceThreshold, RealType );
00123 
00124   /* Get the max norm */
00125   itkGetConstMacro( MaxErrorNorm, RealType );
00126 
00127   /* Get the mean norm */
00128   itkGetConstMacro( MeanErrorNorm, RealType );
00129 
00130 /* Should we force the boundary to have zero displacement? */
00131   itkSetMacro( EnforceBoundaryCondition, bool );
00132   itkGetMacro( EnforceBoundaryCondition, bool );
00133 
00134 protected:
00135 
00137   InvertDisplacementFieldImageFilter();
00138 
00140   virtual ~InvertDisplacementFieldImageFilter();
00141 
00143   void PrintSelf( std::ostream& os, Indent indent ) const;
00144 
00146   void GenerateData();
00147 
00149   void ThreadedGenerateData( const RegionType &, ThreadIdType );
00150 
00151 private:
00152   InvertDisplacementFieldImageFilter( const Self& ); //purposely not implemented
00153   void operator=( const Self& );                 //purposely not implemented
00154 
00156   typename InterpolatorType::Pointer                m_Interpolator;
00157 
00158   unsigned int                                      m_MaximumNumberOfIterations;
00159 
00160   RealType                                          m_MaxErrorToleranceThreshold;
00161   RealType                                          m_MeanErrorToleranceThreshold;
00162 
00163   // internal ivars necessary for multithreading basic operations
00164 
00165   typename DisplacementFieldType::Pointer           m_ComposedField;
00166   typename RealImageType::Pointer                   m_ScaledNormImage;
00167 
00168   RealType                                          m_MaxErrorNorm;
00169   RealType                                          m_MeanErrorNorm;
00170   RealType                                          m_Epsilon;
00171   SpacingType                                       m_DisplacementFieldSpacing;
00172   bool                                              m_DoThreadedEstimateInverse;
00173   bool                                              m_EnforceBoundaryCondition;
00174 
00175 };
00176 
00177 } // end namespace itk
00178 
00179 #ifndef ITK_MANUAL_INSTANTIATION
00180 #include "itkInvertDisplacementFieldImageFilter.hxx"
00181 #endif
00182 
00183 #endif
00184