Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkFEMFiniteDifferenceFunctionLoad.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkFEMFiniteDifferenceFunctionLoad.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-05-12 17:26:20 $
00007   Version:   $Revision: 1.6 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkFEMFiniteDifferenceFunctionLoad_h
00018 #define __itkFEMFiniteDifferenceFunctionLoad_h
00019 
00020 #include "itkFEMLoadElementBase.h"
00021 
00022 #include "itkImage.h"
00023 #include "itkTranslationTransform.h"
00024 
00025 #include "itkImageRegionIteratorWithIndex.h"
00026 #include "itkNeighborhoodIterator.h"
00027 #include "itkNeighborhoodIterator.h"
00028 #include "itkNeighborhoodInnerProduct.h"
00029 #include "itkDerivativeOperator.h"
00030 #include "itkForwardDifferenceOperator.h"
00031 #include "itkLinearInterpolateImageFunction.h"
00032 #include "vnl/vnl_math.h"
00033 
00034 #include "itkDemonsRegistrationFunction.h"
00035 #include "itkMeanSquareRegistrationFunction.h"
00036 #include "itkNCCRegistrationFunction.h"
00037 #include "itkMIRegistrationFunction.h"
00038 
00039 namespace itk 
00040 {
00041 namespace fem
00042 {
00043 
00063 template<class TMoving,class TFixed> 
00064 class ITK_EXPORT FiniteDifferenceFunctionLoad : public LoadElement
00065 {
00066   FEM_CLASS(FiniteDifferenceFunctionLoad,LoadElement)
00067 public:
00068 
00069   // Necessary typedefs for dealing with images BEGIN
00070   typedef typename LoadElement::Float Float;
00071 
00072   typedef TMoving                                 MovingImageType;
00073   typedef typename MovingImageType::ConstPointer  MovingConstPointer;
00074   typedef MovingImageType*                        MovingPointer;
00075   typedef TFixed                                  FixedImageType;
00076   typedef FixedImageType*                         FixedPointer;
00077   typedef typename FixedImageType::ConstPointer   FixedConstPointer;
00078 
00080   itkStaticConstMacro(ImageDimension, unsigned int,
00081                       MovingImageType::ImageDimension);
00082 
00083   typedef ImageRegionIteratorWithIndex<MovingImageType> MovingRegionIteratorType; 
00084   typedef ImageRegionIteratorWithIndex<FixedImageType>  FixedRegionIteratorType; 
00085   
00086 
00087   typedef NeighborhoodIterator<MovingImageType> 
00088                                      MovingNeighborhoodIteratorType; 
00089   typedef typename MovingNeighborhoodIteratorType::IndexType  
00090                                      MovingNeighborhoodIndexType;
00091   typedef typename MovingNeighborhoodIteratorType::RadiusType 
00092                                      MovingRadiusType;
00093   typedef typename MovingNeighborhoodIteratorType::RadiusType 
00094                                      RadiusType;
00095   typedef NeighborhoodIterator<FixedImageType> 
00096                                      FixedNeighborhoodIteratorType; 
00097   typedef typename FixedNeighborhoodIteratorType::IndexType  
00098                                      FixedNeighborhoodIndexType;
00099   typedef typename FixedNeighborhoodIteratorType::RadiusType 
00100                                      FixedRadiusType;
00101 
00102 
00103 // IMAGE DATA
00104   typedef   typename  MovingImageType::PixelType   MovingPixelType;
00105   typedef   typename  FixedImageType::PixelType    FixedPixelType;
00106   typedef   Float                                  PixelType;
00107   typedef   Float                                  ComputationType;
00108   typedef   Image< PixelType, itkGetStaticConstMacro(ImageDimension) >
00109                                                    ImageType;
00110   typedef   itk::Vector<float,itkGetStaticConstMacro(ImageDimension)> 
00111                                                    VectorType;
00112   typedef   vnl_vector<Float>                      FEMVectorType;
00113   typedef   Image< VectorType, itkGetStaticConstMacro(ImageDimension) >
00114                                                    DeformationFieldType;
00115   typedef   typename DeformationFieldType::Pointer DeformationFieldTypePointer;
00116 
00117 
00118   typedef NeighborhoodIterator<DeformationFieldType> 
00119                                      FieldIteratorType; 
00120 
00121 // Necessary typedefs for dealing with images END
00122 
00124   typedef PDEDeformableRegistrationFunction<FixedImageType,MovingImageType,
00125     DeformationFieldType>                                FiniteDifferenceFunctionType;
00126   typedef typename FiniteDifferenceFunctionType::Pointer FiniteDifferenceFunctionTypePointer;
00127 
00128 
00129   typedef typename FiniteDifferenceFunctionType::TimeStepType TimeStepType;
00130  
00131   typedef MeanSquareRegistrationFunction<FixedImageType,MovingImageType,
00132     DeformationFieldType>  MeanSquareRegistrationFunctionType;
00133 
00134   typedef DemonsRegistrationFunction<FixedImageType,MovingImageType,
00135     DeformationFieldType>  DemonsRegistrationFunctionType;
00136   
00137   typedef NCCRegistrationFunction<FixedImageType,MovingImageType,
00138     DeformationFieldType>  NCCRegistrationFunctionType;
00139   
00140   typedef MIRegistrationFunction<FixedImageType,MovingImageType,
00141     DeformationFieldType>  MIRegistrationFunctionType;
00142   
00143 // FUNCTIONS
00144 
00145   /* This method sets the pointer to a FiniteDifferenceFunction object that
00146    * will be used by the filter to calculate updates at image pixels.
00147    * \returns A FiniteDifferenceObject pointer. */
00148   void SetDifferenceFunction( FiniteDifferenceFunctionTypePointer drfp)
00149     { 
00150     drfp->SetFixedImage(m_FixedImage);
00151     drfp->SetMovingImage(m_MovingImage);
00152     drfp->SetRadius(m_MetricRadius);
00153     drfp->SetDeformationField(m_DeformationField);
00154     drfp->InitializeIteration();
00155     this->m_DifferenceFunction=drfp; 
00156     }
00157 
00158   void SetMetric( FiniteDifferenceFunctionTypePointer drfp )
00159     {
00160     this->SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
00161     drfp.GetPointer() ) );
00162 
00163     m_FixedSize=m_DeformationField->GetLargestPossibleRegion().GetSize();
00164     }
00165 
00167   void SetMovingImage(MovingImageType* R)
00168     { 
00169     m_MovingImage = R; 
00170     m_MovingSize=m_MovingImage->GetLargestPossibleRegion().GetSize();
00171     if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetMovingImage(m_MovingImage);
00172     };
00174 
00175 
00177   void SetFixedImage(FixedImageType* T)
00178     { 
00179     m_FixedImage=T; 
00180     m_FixedSize=T->GetLargestPossibleRegion().GetSize();
00181     if (this->m_DifferenceFunction)
00182       {
00183       this->m_DifferenceFunction->SetFixedImage(m_MovingImage); 
00184       }
00185     }
00187 
00188   MovingPointer GetMovingImage()
00189     {
00190     return m_MovingImage;
00191     }
00192 
00193   FixedPointer GetFixedImage()
00194     {
00195     return m_FixedImage;
00196     }
00197 
00199   void SetMetricRadius(MovingRadiusType T)
00200     {
00201     m_MetricRadius  = T;
00202     }
00203 
00205   MovingRadiusType GetMetricRadius()
00206     {
00207     return m_MetricRadius;
00208     }
00209 
00214   void SetNumberOfIntegrationPoints(unsigned int i)
00215     {
00216     m_NumberOfIntegrationPoints=i;
00217     }
00218   unsigned int GetNumberOfIntegrationPoints()
00219     {
00220     return m_NumberOfIntegrationPoints;
00221     }
00223 
00227   void SetSign(Float s)
00228     {
00229     m_Sign=s;
00230     }
00231 
00233   void SetTemp(Float s)
00234     {
00235     m_Temp=s;
00236     }
00237 
00238 
00240   void SetGamma(Float s)
00241     {
00242     m_Gamma=s;
00243     }
00244 
00245   void SetSolution(Solution::ConstPointer ptr)
00246     {
00247     m_Solution=ptr;
00248     }
00249   Solution::ConstPointer GetSolution()
00250     {
00251     return m_Solution;
00252     }
00253 
00254   // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
00255   Float GetSolution(unsigned int i,unsigned int which=0)
00256     {  
00257     return m_Solution->GetSolutionValue(i,which); 
00258     }
00259 
00260   FiniteDifferenceFunctionLoad(); // cannot be private until we always use smart pointers
00261   Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00262  
00266   VectorType Fe1(VectorType);
00267   FEMVectorType Fe(FEMVectorType,FEMVectorType);
00269 
00270   static Baseclass* NewFiniteDifferenceFunctionLoad(void)
00271   { return new FiniteDifferenceFunctionLoad; }
00272 
00273 
00275   void SetDeformationField( DeformationFieldTypePointer df)
00276     { m_DeformationField=df;}
00277 
00279   DeformationFieldTypePointer GetDeformationField() { return m_DeformationField;}
00280   void InitializeIteration();
00281   void InitializeMetric();
00283 
00284   void PrintCurrentEnergy();
00285   double GetCurrentEnergy();
00286   void  SetCurrentEnergy( double e = 0.0);
00287 
00288 protected:
00289 
00290 
00291 private:
00292   MovingPointer                                      m_MovingImage;
00293   FixedPointer                                       m_FixedImage;
00295   typename MovingImageType::SizeType                 m_MovingSize;
00296   typename FixedImageType::SizeType                  m_FixedSize;
00297   unsigned int                                       m_NumberOfIntegrationPoints;
00298   unsigned int                                       m_SolutionIndex;
00299   unsigned int                                       m_SolutionIndex2;
00300   Float                                              m_Temp;
00301   Float                                              m_Gamma;
00302   typename Solution::ConstPointer                    m_Solution;
00303 
00304   float                                              m_GradSigma;
00305   float                                              m_Sign;
00306   float                                              m_WhichMetric;
00307   FiniteDifferenceFunctionTypePointer                m_DifferenceFunction;
00308 
00309   typename DeformationFieldType::Pointer             m_DeformationField;
00312   static const int m_DummyCLID;
00313 
00314 };
00315 
00316 }
00317 } // end namespace fem/itk
00318 
00319 #ifndef ITK_MANUAL_INSTANTIATION
00320 #include "itkFEMFiniteDifferenceFunctionLoad.txx"
00321 #endif
00322 
00323 #endif
00324 

Generated at Tue Sep 15 02:55:22 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000