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/10/11 01:16:49 $
00006   Version:   $Revision: 1.18 $
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 "itkSmartNeighborhoodIterator.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 ReferenceType*  ReferencePointer;
00102   typedef TTarget       TargetType;
00103   typedef TargetType*  TargetPointer;
00104 
00106   itkStaticConstMacro(ImageDimension, unsigned int,
00107                       ReferenceType::ImageDimension);
00108 
00109   typedef ImageRegionIteratorWithIndex<ReferenceType> RefRegionIteratorType; 
00110   typedef ImageRegionIteratorWithIndex<TargetType>    TarRegionIteratorType; 
00111   
00112   typedef SmartNeighborhoodIterator<ReferenceType> 
00113                                      ReferenceNeighborhoodIteratorType; 
00114   typedef typename ReferenceNeighborhoodIteratorType::IndexType  
00115                                      ReferenceNeighborhoodIndexType;
00116   typedef typename ReferenceNeighborhoodIteratorType::RadiusType 
00117                                      ReferenceRadiusType;
00118   typedef SmartNeighborhoodIterator<TargetType> 
00119                                      TargetNeighborhoodIteratorType; 
00120   typedef typename TargetNeighborhoodIteratorType::IndexType  
00121                                      TargetNeighborhoodIndexType;
00122   typedef typename TargetNeighborhoodIteratorType::RadiusType 
00123                                      TargetRadiusType;
00124 
00125 // IMAGE DATA
00126   typedef   typename  ReferenceType::PixelType RefPixelType;
00127   typedef   typename  TargetType::PixelType    TarPixelType;
00128   typedef   Float PixelType;
00129   typedef   Float ComputationType;
00130   typedef   CovariantVector< PixelType, itkGetStaticConstMacro(ImageDimension) >  CovariantVectorType;
00131   typedef   Image< CovariantVectorType, itkGetStaticConstMacro(ImageDimension) >  CovariantVectorImageType;
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 
00171  
00172 // FUNCTIONS
00173 
00175   void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; }; 
00176   
00178   void SetReferenceImage(ReferenceType* R)
00179   { 
00180     m_RefImage = R; 
00181     m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00182   };
00183 
00184   void SetMetricReferenceImage(ReferenceType* R)  
00185   { 
00186     m_Metric->SetMovingImage( R ); 
00187     m_RefSize=R->GetLargestPossibleRegion().GetSize(); 
00188   };
00189 
00191   void SetTargetImage(TargetType* T)
00192   { 
00193      m_TarImage=T; 
00194      m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00195   };
00196   void SetMetricTargetImage(TargetType* T)  
00197   { 
00198     m_Metric->SetFixedImage( T ) ; 
00199     m_TarSize=T->GetLargestPossibleRegion().GetSize(); 
00200   };
00201 
00202 
00203   ReferencePointer GetReferenceImage() { return m_RefImage; };
00204   TargetPointer GetTargetImage() { return m_TarImage; };
00205 
00207   void SetMetricRadius(ReferenceRadiusType T) {m_MetricRadius  = T; };    
00209   ReferenceRadiusType GetMetricRadius() { return m_MetricRadius; };       
00210   
00215   void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00216   unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00217 
00221   void SetSign(Float s) {m_Sign=s;}
00222   
00224   void SetTemp(Float s) {m_Temp=s;}
00225 
00226 
00228   void SetGamma(Float s) {m_Gamma=s;}
00229 
00230   void SetSolution(Solution::ConstPointer ptr) {  m_Solution=ptr; }
00231   Solution::ConstPointer GetSolution() {  return m_Solution; }
00232 
00236   Float GetMetric (VectorType  InVec);
00237   
00238   // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
00239   Float GetSolution(unsigned int i,unsigned int which=0)
00240   {  
00241     return m_Solution->GetSolutionValue(i,which); 
00242   }
00243   
00244 // define the copy constructor 
00245 //  ImageMetricLoad(const ImageMetricLoad& LMS);
00246 
00247   void InitializeMetric(void);
00248   ImageMetricLoad(); // cannot be private until we always use smart pointers
00249   Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00250  
00254   VectorType Fe1(VectorType);
00255   VectorType Fe(VectorType,VectorType);
00256  
00257   static Baseclass* NewImageMetricLoad(void)
00258   { return new ImageMetricLoad; }
00259 
00260 
00261 protected:
00262 
00263 private:
00264 
00265   typename CovariantVectorImageType::Pointer          m_DerivativeImage;
00266   ReferencePointer                                    m_RefImage;
00267   TargetPointer                                       m_TarImage;
00268   ReferenceRadiusType                                 m_MetricRadius; 
00269   typename ReferenceType::SizeType                    m_RefSize;
00270   typename TargetType::SizeType                       m_TarSize;
00271   unsigned int                                        m_NumberOfIntegrationPoints;
00272   unsigned int                                        m_SolutionIndex;
00273   unsigned int                                        m_SolutionIndex2;
00274   Float                                               m_Sign;
00275   Float                                               m_Temp;
00276   Float                                               m_Gamma;
00277 
00278   typename Solution::ConstPointer                     m_Solution;
00279   MetricBaseTypePointer                               m_Metric;
00280   typename TransformBaseType::Pointer                 m_Transform;
00281   typename InterpolatorType::Pointer                  m_Interpolator;
00282 
00283 private:
00286   static const int DummyCLID;
00287 
00288 };
00289 
00290 
00291 
00292 
00293 }} // end namespace fem/itk
00294 
00295 #ifndef ITK_MANUAL_INSTANTIATION
00296 #include "itkFEMImageMetricLoad.txx"
00297 #endif
00298 
00299 #endif

Generated at Wed Mar 12 01:12:55 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000