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 (ITK)
00004   Module:    $RCSfile: itkFEMImageMetricLoad.h,v $ Language:  C++
00005   Date:      $Date: 2003/08/07 18:56:56 $
00006   Version:   $Revision: 1.23 $
00007 
00008 Copyright (c) 2001 Insight Consortium
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * The name of the Insight Consortium, nor the names of any consortium members,
00022    nor of any contributors, may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025   * Modified source versions must be plainly marked as such, and must not be
00026     misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00040 #ifndef _itkFEMImageMetricLoad_h_
00041 #define _itkFEMImageMetricLoad_h_
00042 
00043 #include "itkFEMLoadElementBase.h"
00044 
00045 #include "itkImage.h"
00046 #include "itkTranslationTransform.h"
00047 
00048 #include "itkImageRegionIteratorWithIndex.h"
00049 #include "itkNeighborhoodIterator.h"
00050 #include "itkNeighborhoodIterator.h"
00051 #include "itkNeighborhoodInnerProduct.h"
00052 #include "itkDerivativeOperator.h"
00053 #include "itkForwardDifferenceOperator.h"
00054 #include "itkLinearInterpolateImageFunction.h"
00055 #include "vnl/vnl_math.h"
00056 
00057 #include <itkMutualInformationImageToImageMetric.h>
00058 #include <itkMattesMutualInformationImageToImageMetric.h>
00059 #include <itkMeanSquaresImageToImageMetric.h>
00060 #include <itkNormalizedCorrelationImageToImageMetric.h>
00061 //#include <itkMeanReciprocalSquareDifferenceImageToImageMetric.h>
00062 
00063 
00064 namespace itk 
00065 {
00066 namespace fem
00067 {
00068 
00092 template<class TMoving,class TFixed> 
00093 class ImageMetricLoad : public LoadElement
00094 {
00095 FEM_CLASS(ImageMetricLoad,LoadElement)
00096 public:
00097 
00098 // Necessary typedefs for dealing with images BEGIN
00099   typedef typename LoadElement::Float Float;
00100 
00101   typedef TMoving MovingType;
00102   typedef typename MovingType::ConstPointer  MovingConstPointer;
00103   typedef MovingType*  MovingPointer;
00104   typedef TFixed       FixedType;
00105   typedef FixedType*  FixedPointer;
00106   typedef typename FixedType::ConstPointer  FixedConstPointer;
00107 
00109   itkStaticConstMacro(ImageDimension, unsigned int,
00110                       MovingType::ImageDimension);
00111 
00112   typedef ImageRegionIteratorWithIndex<MovingType> RefRegionIteratorType; 
00113   typedef ImageRegionIteratorWithIndex<FixedType>    TarRegionIteratorType; 
00114   
00115 
00116   typedef NeighborhoodIterator<MovingType> 
00117                                      MovingNeighborhoodIteratorType; 
00118   typedef typename MovingNeighborhoodIteratorType::IndexType  
00119                                      MovingNeighborhoodIndexType;
00120   typedef typename MovingNeighborhoodIteratorType::RadiusType 
00121                                      MovingRadiusType;
00122   typedef NeighborhoodIterator<FixedType> 
00123                                      FixedNeighborhoodIteratorType; 
00124   typedef typename FixedNeighborhoodIteratorType::IndexType  
00125                                      FixedNeighborhoodIndexType;
00126   typedef typename FixedNeighborhoodIteratorType::RadiusType 
00127                                      FixedRadiusType;
00128 
00129 
00130 // IMAGE DATA
00131   typedef   typename  MovingType::PixelType RefPixelType;
00132   typedef   typename  FixedType::PixelType    TarPixelType;
00133   typedef   Float PixelType;
00134   typedef   Float ComputationType;
00135   typedef   Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) >       RefImageType;
00136   typedef   Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) >       TarImageType;
00137   typedef   Image< PixelType, itkGetStaticConstMacro(ImageDimension) >            ImageType;
00138   typedef   vnl_vector<Float>                             VectorType;
00139 
00140 // Necessary typedefs for dealing with images END
00141  
00142 //------------------------------------------------------------
00143 // Set up the metrics
00144 //------------------------------------------------------------
00145   typedef double                   CoordinateRepresentationType;
00146   typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType;
00147   typedef TranslationTransform<CoordinateRepresentationType,  itkGetStaticConstMacro(ImageDimension) >  DefaultTransformType;
00148 
00150   typedef   ImageToImageMetric<FixedType,MovingType > MetricBaseType;
00151   typedef typename MetricBaseType::Pointer             MetricBaseTypePointer;
00152 
00153   typedef   MutualInformationImageToImageMetric<  MovingType, FixedType   > MutualInformationMetricType;
00154 
00155   typedef   MeanSquaresImageToImageMetric< MovingType, FixedType   > MeanSquaresMetricType;
00156 
00157   typedef   NormalizedCorrelationImageToImageMetric< MovingType, FixedType  > NormalizedCorrelationMetricType;
00158 
00159 //  typedef   MeanReciprocalSquareDifferenceImageToImageMetric<  ReferenceType, TargetType   > MeanReciprocalSquaresMetricType;
00160 
00161 //  typedef  MutualInformationMetricType             DefaultMetricType;
00162 //  typedef  NormalizedCorrelationMetricType             DefaultMetricType;
00163 //  typedef  MeanReciprocalSquaresMetricType             DefaultMetricType;
00164   typedef  MeanSquaresMetricType             DefaultMetricType;
00165   typedef typename DefaultTransformType::ParametersType         ParametersType;
00166   typedef typename DefaultTransformType::JacobianType           JacobianType;
00167 
00168 
00169 //------------------------------------------------------------
00170 // Set up an Interpolator
00171 //------------------------------------------------------------
00172   typedef LinearInterpolateImageFunction< MovingType, double > InterpolatorType;
00173 
00175   typedef float RealType;
00176   typedef CovariantVector<RealType,
00177           itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
00178   typedef Image<GradientPixelType,
00179                itkGetStaticConstMacro(ImageDimension)> GradientImageType;
00180   typedef SmartPointer<GradientImageType>     GradientImagePointer;
00181   typedef GradientRecursiveGaussianImageFilter< ImageType,
00182                                                 GradientImageType >
00183           GradientImageFilterType;  
00184   //  typedef typename GradientImageFilterType::Pointer GradientImageFilterPointer;
00186 
00187 
00188 // FUNCTIONS
00189 
00191   void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; }; 
00192 
00194   void SetMovingImage(MovingType* R)
00195   { 
00196     m_RefImage = R; 
00197     m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00198   };
00200 
00201   void SetMetricMovingImage(MovingType* R)  
00202   { 
00203     m_Metric->SetMovingImage( R ); 
00204     m_RefSize=R->GetLargestPossibleRegion().GetSize(); 
00205   };
00206 
00208   void SetFixedImage(FixedType* T)
00209   { 
00210      m_TarImage=T; 
00211      m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00212   };
00213   void SetMetricFixedImage(FixedType* T)  
00214   { 
00215     m_Metric->SetFixedImage( T ) ; 
00216     m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00217   };
00219 
00220 
00221   MovingPointer GetMovingImage() { return m_RefImage; };
00222   FixedPointer GetFixedImage() { return m_TarImage; };
00223 
00225   void SetMetricRadius(MovingRadiusType T) {m_MetricRadius  = T; };    
00226 
00228   MovingRadiusType GetMetricRadius() { return m_MetricRadius; };       
00229 
00234   void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00235   unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00237 
00241   void SetSign(Float s) {m_Sign=s;}
00242 
00244   void SetTemp(Float s) {m_Temp=s;}
00245 
00246 
00248   void SetGamma(Float s) {m_Gamma=s;}
00249 
00250   void SetSolution(Solution::ConstPointer ptr) {  m_Solution=ptr; }
00251   Solution::ConstPointer GetSolution() {  return m_Solution; }
00252 
00256   Float GetMetric (VectorType  InVec);
00257   VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00259 
00260   VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00261 
00262   // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
00263   Float GetSolution(unsigned int i,unsigned int which=0)
00264   {  
00265     return m_Solution->GetSolutionValue(i,which); 
00266   }
00267   
00268 // define the copy constructor 
00269 //  ImageMetricLoad(const ImageMetricLoad& LMS);
00270 
00271   void InitializeMetric(void);
00272   ImageMetricLoad(); // cannot be private until we always use smart pointers
00273   Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00274  
00278   VectorType Fe1(VectorType);
00279   VectorType Fe(VectorType,VectorType);
00281 
00282   static Baseclass* NewImageMetricLoad(void)
00283   { return new ImageMetricLoad; }
00284 
00285 
00287   //void InitializeGradientImage();
00288   void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;}
00289   GradientImageType* GetMetricGradientImage() { return  m_MetricGradientImage;}
00291 
00292 
00293   void PrintCurrentEnergy(){ std:: cout << " energy " << m_Energy << std::endl;}
00294   double GetCurrentEnergy() { return m_Energy; }
00295   void  SetCurrentEnergy( double e ) { m_Energy=e; }
00296 
00297 protected:
00298 
00299 
00300 private:
00301   GradientImageType*                                  m_MetricGradientImage;
00302   MovingPointer                                    m_RefImage;
00303   FixedPointer                                       m_TarImage;
00305   typename MovingType::SizeType                    m_RefSize;
00306   typename FixedType::SizeType                       m_TarSize;
00307   unsigned int                                        m_NumberOfIntegrationPoints;
00308   unsigned int                                        m_SolutionIndex;
00309   unsigned int                                        m_SolutionIndex2;
00310   Float                                               m_Sign;
00311   Float                                               m_Temp;
00312   Float                                               m_Gamma;
00313 
00314   typename Solution::ConstPointer                     m_Solution;
00315   MetricBaseTypePointer                               m_Metric;
00316   typename TransformBaseType::Pointer                 m_Transform;
00317   typename InterpolatorType::Pointer                  m_Interpolator;
00318 
00319   mutable double                  m_Energy;
00320 private:
00323   static const int DummyCLID;
00324 
00325 };
00326 
00327 
00328 
00329 
00330 }} // end namespace fem/itk
00331 
00332 #ifndef ITK_MANUAL_INSTANTIATION
00333 #include "itkFEMImageMetricLoad.txx"
00334 #endif
00335 
00336 #endif
00337 

Generated at Sat Sep 2 20:24:22 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000