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

itkFEMImageMetricLoad.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkFEMImageMetricLoad.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006-09-25 22:40:28 $
00007   Version:   $Revision: 1.24 $
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 _itkFEMImageMetricLoad_h_
00018 #define _itkFEMImageMetricLoad_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 <itkMutualInformationImageToImageMetric.h>
00035 #include <itkMattesMutualInformationImageToImageMetric.h>
00036 #include <itkMeanSquaresImageToImageMetric.h>
00037 #include <itkNormalizedCorrelationImageToImageMetric.h>
00038 //#include <itkMeanReciprocalSquareDifferenceImageToImageMetric.h>
00039 
00040 
00041 namespace itk 
00042 {
00043 namespace fem
00044 {
00045 
00069 template<class TMoving,class TFixed> 
00070 class ImageMetricLoad : public LoadElement
00071 {
00072 FEM_CLASS(ImageMetricLoad,LoadElement)
00073 public:
00074 
00075 // Necessary typedefs for dealing with images BEGIN
00076   typedef typename LoadElement::Float Float;
00077 
00078   typedef TMoving MovingType;
00079   typedef typename MovingType::ConstPointer  MovingConstPointer;
00080   typedef MovingType*  MovingPointer;
00081   typedef TFixed       FixedType;
00082   typedef FixedType*  FixedPointer;
00083   typedef typename FixedType::ConstPointer  FixedConstPointer;
00084 
00086   itkStaticConstMacro(ImageDimension, unsigned int,
00087                       MovingType::ImageDimension);
00088 
00089   typedef ImageRegionIteratorWithIndex<MovingType> RefRegionIteratorType; 
00090   typedef ImageRegionIteratorWithIndex<FixedType>    TarRegionIteratorType; 
00091   
00092 
00093   typedef NeighborhoodIterator<MovingType> 
00094                                      MovingNeighborhoodIteratorType; 
00095   typedef typename MovingNeighborhoodIteratorType::IndexType  
00096                                      MovingNeighborhoodIndexType;
00097   typedef typename MovingNeighborhoodIteratorType::RadiusType 
00098                                      MovingRadiusType;
00099   typedef NeighborhoodIterator<FixedType> 
00100                                      FixedNeighborhoodIteratorType; 
00101   typedef typename FixedNeighborhoodIteratorType::IndexType  
00102                                      FixedNeighborhoodIndexType;
00103   typedef typename FixedNeighborhoodIteratorType::RadiusType 
00104                                      FixedRadiusType;
00105 
00106 
00107 // IMAGE DATA
00108   typedef   typename  MovingType::PixelType RefPixelType;
00109   typedef   typename  FixedType::PixelType    TarPixelType;
00110   typedef   Float PixelType;
00111   typedef   Float ComputationType;
00112   typedef   Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) >       RefImageType;
00113   typedef   Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) >       TarImageType;
00114   typedef   Image< PixelType, itkGetStaticConstMacro(ImageDimension) >            ImageType;
00115   typedef   vnl_vector<Float>                             VectorType;
00116 
00117 // Necessary typedefs for dealing with images END
00118  
00119 //------------------------------------------------------------
00120 // Set up the metrics
00121 //------------------------------------------------------------
00122   typedef double                   CoordinateRepresentationType;
00123   typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType;
00124   typedef TranslationTransform<CoordinateRepresentationType,  itkGetStaticConstMacro(ImageDimension) >  DefaultTransformType;
00125 
00127   typedef   ImageToImageMetric<FixedType,MovingType > MetricBaseType;
00128   typedef typename MetricBaseType::Pointer             MetricBaseTypePointer;
00129 
00130   typedef   MutualInformationImageToImageMetric<  MovingType, FixedType   > MutualInformationMetricType;
00131 
00132   typedef   MeanSquaresImageToImageMetric< MovingType, FixedType   > MeanSquaresMetricType;
00133 
00134   typedef   NormalizedCorrelationImageToImageMetric< MovingType, FixedType  > NormalizedCorrelationMetricType;
00135 
00136 //  typedef   MeanReciprocalSquareDifferenceImageToImageMetric<  ReferenceType, TargetType   > MeanReciprocalSquaresMetricType;
00137 
00138 //  typedef  MutualInformationMetricType             DefaultMetricType;
00139 //  typedef  NormalizedCorrelationMetricType             DefaultMetricType;
00140 //  typedef  MeanReciprocalSquaresMetricType             DefaultMetricType;
00141   typedef  MeanSquaresMetricType             DefaultMetricType;
00142   typedef typename DefaultTransformType::ParametersType         ParametersType;
00143   typedef typename DefaultTransformType::JacobianType           JacobianType;
00144 
00145 
00146 //------------------------------------------------------------
00147 // Set up an Interpolator
00148 //------------------------------------------------------------
00149   typedef LinearInterpolateImageFunction< MovingType, double > InterpolatorType;
00150 
00152   typedef float RealType;
00153   typedef CovariantVector<RealType,
00154           itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
00155   typedef Image<GradientPixelType,
00156                itkGetStaticConstMacro(ImageDimension)> GradientImageType;
00157   typedef SmartPointer<GradientImageType>     GradientImagePointer;
00158   typedef GradientRecursiveGaussianImageFilter< ImageType,
00159                                                 GradientImageType >
00160           GradientImageFilterType;  
00161   //  typedef typename GradientImageFilterType::Pointer GradientImageFilterPointer;
00163 
00164 
00165 // FUNCTIONS
00166 
00168   void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; }; 
00169 
00171   void SetMovingImage(MovingType* R)
00172   { 
00173     m_RefImage = R; 
00174     m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00175   };
00177 
00178   void SetMetricMovingImage(MovingType* R)  
00179   { 
00180     m_Metric->SetMovingImage( R ); 
00181     m_RefSize=R->GetLargestPossibleRegion().GetSize(); 
00182   };
00183 
00185   void SetFixedImage(FixedType* T)
00186   { 
00187      m_TarImage=T; 
00188      m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00189   };
00190   void SetMetricFixedImage(FixedType* T)  
00191   { 
00192     m_Metric->SetFixedImage( T ) ; 
00193     m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00194   };
00196 
00197 
00198   MovingPointer GetMovingImage() { return m_RefImage; };
00199   FixedPointer GetFixedImage() { return m_TarImage; };
00200 
00202   void SetMetricRadius(MovingRadiusType T) {m_MetricRadius  = T; };    
00203 
00205   MovingRadiusType GetMetricRadius() { return m_MetricRadius; };       
00206 
00211   void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00212   unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00214 
00218   void SetSign(Float s) {m_Sign=s;}
00219 
00221   void SetTemp(Float s) {m_Temp=s;}
00222 
00223 
00225   void SetGamma(Float s) {m_Gamma=s;}
00226 
00227   void SetSolution(Solution::ConstPointer ptr) {  m_Solution=ptr; }
00228   Solution::ConstPointer GetSolution() {  return m_Solution; }
00229 
00233   Float GetMetric (VectorType  InVec);
00234   VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00236 
00237   VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00238 
00239   // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
00240   Float GetSolution(unsigned int i,unsigned int which=0)
00241   {  
00242     return m_Solution->GetSolutionValue(i,which); 
00243   }
00244   
00245 // define the copy constructor 
00246 //  ImageMetricLoad(const ImageMetricLoad& LMS);
00247 
00248   void InitializeMetric(void);
00249   ImageMetricLoad(); // cannot be private until we always use smart pointers
00250   Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00251  
00255   VectorType Fe1(VectorType);
00256   VectorType Fe(VectorType,VectorType);
00258 
00259   static Baseclass* NewImageMetricLoad(void)
00260   { return new ImageMetricLoad; }
00261 
00262 
00264   //void InitializeGradientImage();
00265   void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;}
00266   GradientImageType* GetMetricGradientImage() { return  m_MetricGradientImage;}
00268 
00269 
00270   void PrintCurrentEnergy(){ std:: cout << " energy " << m_Energy << std::endl;}
00271   double GetCurrentEnergy() { return m_Energy; }
00272   void  SetCurrentEnergy( double e ) { m_Energy=e; }
00273 
00274 protected:
00275 
00276 
00277 private:
00278   GradientImageType*                                  m_MetricGradientImage;
00279   MovingPointer                                    m_RefImage;
00280   FixedPointer                                       m_TarImage;
00282   typename MovingType::SizeType                    m_RefSize;
00283   typename FixedType::SizeType                       m_TarSize;
00284   unsigned int                                        m_NumberOfIntegrationPoints;
00285   unsigned int                                        m_SolutionIndex;
00286   unsigned int                                        m_SolutionIndex2;
00287   Float                                               m_Sign;
00288   Float                                               m_Temp;
00289   Float                                               m_Gamma;
00290 
00291   typename Solution::ConstPointer                     m_Solution;
00292   MetricBaseTypePointer                               m_Metric;
00293   typename TransformBaseType::Pointer                 m_Transform;
00294   typename InterpolatorType::Pointer                  m_Interpolator;
00295 
00296   mutable double                  m_Energy;
00297 private:
00300   static const int DummyCLID;
00301 
00302 };
00303 
00304 
00305 
00306 
00307 }} // end namespace fem/itk
00308 
00309 #ifndef ITK_MANUAL_INSTANTIATION
00310 #include "itkFEMImageMetricLoad.txx"
00311 #endif
00312 
00313 #endif
00314 

Generated at Mon Apr 14 12:23:49 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000