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: 2002/12/17 17:50:35 $
00006   Version:   $Revision: 1.21 $
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 <itkMeanSquaresImageToImageMetric.h>
00059 #include <itkNormalizedCorrelationImageToImageMetric.h>
00060 #include <itkPatternIntensityImageToImageMetric.h>
00061 
00062 
00063 namespace itk 
00064 {
00065 namespace fem
00066 {
00067 
00091 template<class TReference,class TTarget> 
00092 class ImageMetricLoad : public LoadElement
00093 {
00094 FEM_CLASS(ImageMetricLoad,LoadElement)
00095 public:
00096 
00097 // Necessary typedefs for dealing with images BEGIN
00098   typedef typename LoadElement::Float Float;
00099 
00100   typedef TReference ReferenceType;
00101   typedef typename ReferenceType::ConstPointer  ReferenceConstPointer;
00102   typedef ReferenceType*  ReferencePointer;
00103   typedef TTarget       TargetType;
00104   typedef TargetType*  TargetPointer;
00105   typedef typename TargetType::ConstPointer  TargetConstPointer;
00106 
00108   itkStaticConstMacro(ImageDimension, unsigned int,
00109                       ReferenceType::ImageDimension);
00110 
00111   typedef ImageRegionIteratorWithIndex<ReferenceType> RefRegionIteratorType; 
00112   typedef ImageRegionIteratorWithIndex<TargetType>    TarRegionIteratorType; 
00113   
00114   typedef NeighborhoodIterator<ReferenceType> 
00115                                      ReferenceNeighborhoodIteratorType; 
00116   typedef typename ReferenceNeighborhoodIteratorType::IndexType  
00117                                      ReferenceNeighborhoodIndexType;
00118   typedef typename ReferenceNeighborhoodIteratorType::RadiusType 
00119                                      ReferenceRadiusType;
00120   typedef NeighborhoodIterator<TargetType> 
00121                                      TargetNeighborhoodIteratorType; 
00122   typedef typename TargetNeighborhoodIteratorType::IndexType  
00123                                      TargetNeighborhoodIndexType;
00124   typedef typename TargetNeighborhoodIteratorType::RadiusType 
00125                                      TargetRadiusType;
00126 
00127 // IMAGE DATA
00128   typedef   typename  ReferenceType::PixelType RefPixelType;
00129   typedef   typename  TargetType::PixelType    TarPixelType;
00130   typedef   Float PixelType;
00131   typedef   Float ComputationType;
00132   typedef   Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) >       RefImageType;
00133   typedef   Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) >       TarImageType;
00134   typedef   Image< PixelType, itkGetStaticConstMacro(ImageDimension) >            ImageType;
00135   typedef   vnl_vector<Float>                             VectorType;
00136 
00137 // Necessary typedefs for dealing with images END
00138  
00139 //------------------------------------------------------------
00140 // Set up the metrics
00141 //------------------------------------------------------------
00142   typedef double                   CoordinateRepresentationType;
00143   typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType;
00144   typedef TranslationTransform<CoordinateRepresentationType,  itkGetStaticConstMacro(ImageDimension) >  DefaultTransformType;
00145 
00147   typedef   ImageToImageMetric<TargetType,ReferenceType > MetricBaseType;
00148   typedef typename MetricBaseType::Pointer             MetricBaseTypePointer;
00149 
00150   typedef   MutualInformationImageToImageMetric<  ReferenceType, TargetType   > MutualInformationMetricType;
00151 
00152   typedef   MeanSquaresImageToImageMetric< ReferenceType, TargetType   > MeanSquaresMetricType;
00153 
00154   typedef   NormalizedCorrelationImageToImageMetric< ReferenceType, TargetType  > NormalizedCorrelationMetricType;
00155 
00156   typedef   PatternIntensityImageToImageMetric<  ReferenceType, TargetType   > PatternIntensityMetricType;
00157 
00158 //  typedef  MutualInformationMetricType             DefaultMetricType;
00159 //  typedef  NormalizedCorrelationMetricType             DefaultMetricType;
00160 //  typedef  PatternIntensityMetricType             DefaultMetricType;
00161   typedef  MeanSquaresMetricType             DefaultMetricType;
00162   typedef typename DefaultTransformType::ParametersType         ParametersType;
00163   typedef typename DefaultTransformType::JacobianType           JacobianType;
00164 
00165 
00166 //------------------------------------------------------------
00167 // Set up an Interpolator
00168 //------------------------------------------------------------
00169   typedef LinearInterpolateImageFunction< ReferenceType, double > InterpolatorType;
00170 
00172   typedef float RealType;
00173   typedef CovariantVector<RealType,
00174           itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
00175   typedef Image<GradientPixelType,
00176                itkGetStaticConstMacro(ImageDimension)> GradientImageType;
00177   typedef SmartPointer<GradientImageType>     GradientImagePointer;
00178   typedef GradientRecursiveGaussianImageFilter< ImageType,
00179                                                 GradientImageType >
00180           GradientImageFilterType;  
00181   //  typedef typename GradientImageFilterType::Pointer GradientImageFilterPointer;
00182 
00183 
00184 // FUNCTIONS
00185 
00187   void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; }; 
00188   
00190   void SetReferenceImage(ReferenceType* R)
00191   { 
00192     m_RefImage = R; 
00193     m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00194   };
00195 
00196   void SetMetricReferenceImage(ReferenceType* R)  
00197   { 
00198     m_Metric->SetMovingImage( R ); 
00199     m_RefSize=R->GetLargestPossibleRegion().GetSize(); 
00200   };
00201 
00203   void SetTargetImage(TargetType* T)
00204   { 
00205      m_TarImage=T; 
00206      m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00207   };
00208   void SetMetricTargetImage(TargetType* T)  
00209   { 
00210     m_Metric->SetFixedImage( T ) ; 
00211     m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00212   };
00213 
00214 
00215   ReferencePointer GetReferenceImage() { return m_RefImage; };
00216   TargetPointer GetTargetImage() { return m_TarImage; };
00217 
00219   void SetMetricRadius(ReferenceRadiusType T) {m_MetricRadius  = T; };    
00221   ReferenceRadiusType GetMetricRadius() { return m_MetricRadius; };       
00222   
00227   void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00228   unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00229 
00233   void SetSign(Float s) {m_Sign=s;}
00234   
00236   void SetTemp(Float s) {m_Temp=s;}
00237 
00238 
00240   void SetGamma(Float s) {m_Gamma=s;}
00241 
00242   void SetSolution(Solution::ConstPointer ptr) {  m_Solution=ptr; }
00243   Solution::ConstPointer GetSolution() {  return m_Solution; }
00244 
00248   Float GetMetric (VectorType  InVec);
00249   VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00250 
00251   VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00252 
00253   // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
00254   Float GetSolution(unsigned int i,unsigned int which=0)
00255   {  
00256     return m_Solution->GetSolutionValue(i,which); 
00257   }
00258   
00259 // define the copy constructor 
00260 //  ImageMetricLoad(const ImageMetricLoad& LMS);
00261 
00262   void InitializeMetric(void);
00263   ImageMetricLoad(); // cannot be private until we always use smart pointers
00264   Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00265  
00269   VectorType Fe1(VectorType);
00270   VectorType Fe(VectorType,VectorType);
00271  
00272   static Baseclass* NewImageMetricLoad(void)
00273   { return new ImageMetricLoad; }
00274 
00275 
00277   //void InitializeGradientImage();
00278   void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;}
00279   GradientImageType* GetMetricGradientImage() { return  m_MetricGradientImage;}
00280 
00281 
00282 protected:
00283 
00284 
00285 private:
00286   GradientImageType*                                  m_MetricGradientImage;
00287   ReferencePointer                                    m_RefImage;
00288   TargetPointer                                       m_TarImage;
00289   ReferenceRadiusType                                 m_MetricRadius; 
00290   typename ReferenceType::SizeType                    m_RefSize;
00291   typename TargetType::SizeType                       m_TarSize;
00292   unsigned int                                        m_NumberOfIntegrationPoints;
00293   unsigned int                                        m_SolutionIndex;
00294   unsigned int                                        m_SolutionIndex2;
00295   Float                                               m_Sign;
00296   Float                                               m_Temp;
00297   Float                                               m_Gamma;
00298 
00299   typename Solution::ConstPointer                     m_Solution;
00300   MetricBaseTypePointer                               m_Metric;
00301   typename TransformBaseType::Pointer                 m_Transform;
00302   typename InterpolatorType::Pointer                  m_Interpolator;
00303 
00304 private:
00307   static const int DummyCLID;
00308 
00309 };
00310 
00311 
00312 
00313 
00314 }} // end namespace fem/itk
00315 
00316 #ifndef ITK_MANUAL_INSTANTIATION
00317 #include "itkFEMImageMetricLoad.txx"
00318 #endif
00319 
00320 #endif

Generated at Fri May 21 01:14:43 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000