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 (ITK)
00004   Module:    $RCSfile: itkFEMFiniteDifferenceFunctionLoad.h,v $ Language:  C++
00005   Date:      $Date: 2005/03/12 13:25:29 $
00006   Version:   $Revision: 1.3 $
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 _itkFEMFiniteDifferenceFunctionLoad_h_
00041 #define _itkFEMFiniteDifferenceFunctionLoad_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 "itkDemonsRegistrationFunction.h"
00058 #include "itkMeanSquareRegistrationFunction.h"
00059 #include "itkNCCRegistrationFunction.h"
00060 #include "itkMIRegistrationFunction.h"
00061 
00062 namespace itk 
00063 {
00064 namespace fem
00065 {
00066 
00086 template<class TMoving,class TFixed> 
00087 class FiniteDifferenceFunctionLoad : public LoadElement
00088 {
00089 FEM_CLASS(FiniteDifferenceFunctionLoad,LoadElement)
00090 public:
00091 
00092 // Necessary typedefs for dealing with images BEGIN
00093   typedef typename LoadElement::Float Float;
00094 
00095   typedef TMoving MovingImageType;
00096   typedef typename MovingImageType::ConstPointer  MovingConstPointer;
00097   typedef MovingImageType*  MovingPointer;
00098   typedef TFixed       FixedImageType;
00099   typedef FixedImageType*  FixedPointer;
00100   typedef typename FixedImageType::ConstPointer  FixedConstPointer;
00101 
00103   itkStaticConstMacro(ImageDimension, unsigned int,
00104                       MovingImageType::ImageDimension);
00105 
00106   typedef ImageRegionIteratorWithIndex<MovingImageType> MovingRegionIteratorType; 
00107   typedef ImageRegionIteratorWithIndex<FixedImageType>    FixedRegionIteratorType; 
00108   
00109 
00110   typedef NeighborhoodIterator<MovingImageType> 
00111                                      MovingNeighborhoodIteratorType; 
00112   typedef typename MovingNeighborhoodIteratorType::IndexType  
00113                                      MovingNeighborhoodIndexType;
00114   typedef typename MovingNeighborhoodIteratorType::RadiusType 
00115                                      MovingRadiusType;
00116   typedef typename MovingNeighborhoodIteratorType::RadiusType 
00117                                      RadiusType;
00118   typedef NeighborhoodIterator<FixedImageType> 
00119                                      FixedNeighborhoodIteratorType; 
00120   typedef typename FixedNeighborhoodIteratorType::IndexType  
00121                                      FixedNeighborhoodIndexType;
00122   typedef typename FixedNeighborhoodIteratorType::RadiusType 
00123                                      FixedRadiusType;
00124 
00125 
00126 // IMAGE DATA
00127   typedef   typename  MovingImageType::PixelType   MovingPixelType;
00128   typedef   typename  FixedImageType::PixelType    FixedPixelType;
00129   typedef   Float PixelType;
00130   typedef   Float ComputationType;
00131   typedef   Image< PixelType, itkGetStaticConstMacro(ImageDimension) >            ImageType;
00132   typedef   itk::Vector<float,itkGetStaticConstMacro(ImageDimension)>             VectorType;
00133   typedef   vnl_vector<Float>             FEMVectorType;
00134   typedef   Image< VectorType, itkGetStaticConstMacro(ImageDimension) >           DeformationFieldType;
00135   typedef   typename DeformationFieldType::Pointer    DeformationFieldTypePointer;
00136 
00137 
00138   typedef NeighborhoodIterator<DeformationFieldType> 
00139                                      FieldIteratorType; 
00140 
00141 // Necessary typedefs for dealing with images END
00142 
00144   typedef PDEDeformableRegistrationFunction<FixedImageType,MovingImageType,
00145     DeformationFieldType>  FiniteDifferenceFunctionType;
00146   typedef typename FiniteDifferenceFunctionType::Pointer FiniteDifferenceFunctionTypePointer;
00147   typedef typename FiniteDifferenceFunctionType::TimeStepType TimeStepType;
00148  
00149   typedef MeanSquareRegistrationFunction<FixedImageType,MovingImageType,
00150     DeformationFieldType>  MeanSquareRegistrationFunctionType;
00151 
00152   typedef DemonsRegistrationFunction<FixedImageType,MovingImageType,
00153     DeformationFieldType>  DemonsRegistrationFunctionType;
00154   
00155   typedef NCCRegistrationFunction<FixedImageType,MovingImageType,
00156     DeformationFieldType>  NCCRegistrationFunctionType;
00157   
00158   typedef MIRegistrationFunction<FixedImageType,MovingImageType,
00159     DeformationFieldType>  MIRegistrationFunctionType;
00160   
00161 // FUNCTIONS
00162 
00163   /* This method sets the pointer to a FiniteDifferenceFunction object that
00164    * will be used by the filter to calculate updates at image pixels.
00165    * \returns A FiniteDifferenceObject pointer. */
00166   void SetDifferenceFunction( FiniteDifferenceFunctionTypePointer drfp)
00167   { 
00168     drfp->SetFixedImage(m_FixedImage);
00169     drfp->SetMovingImage(m_MovingImage);
00170     drfp->SetRadius(m_MetricRadius);
00171     drfp->SetDeformationField(m_DeformationField);
00172     drfp->InitializeIteration();
00173     this->m_DifferenceFunction=drfp; 
00174   }
00175 
00176   void SetMetric( FiniteDifferenceFunctionTypePointer drfp )
00177   {
00178     this->SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
00179     drfp.GetPointer() ) );
00180 
00181     m_FixedSize=m_DeformationField->GetLargestPossibleRegion().GetSize();
00182   }
00183 
00184 
00185 
00187   void SetMovingImage(MovingImageType* R)
00188   { 
00189     m_MovingImage = R; 
00190     m_MovingSize=m_MovingImage->GetLargestPossibleRegion().GetSize();
00191     if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetMovingImage(m_MovingImage);
00192 //     this->InitializeIteration();   
00193   };
00194 
00195 
00197   void SetFixedImage(FixedImageType* T)
00198   { 
00199      m_FixedImage=T; 
00200      m_FixedSize=T->GetLargestPossibleRegion().GetSize();
00201      if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetFixedImage(m_MovingImage); 
00202 //     this->InitializeIteration();   
00203   };
00204 
00205 
00206   MovingPointer GetMovingImage() { return m_MovingImage; };
00207   FixedPointer GetFixedImage() { return m_FixedImage; };
00208 
00210   void SetMetricRadius(MovingRadiusType T) {m_MetricRadius  = T; };    
00212   MovingRadiusType GetMetricRadius() { return m_MetricRadius; };       
00213   
00218   void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00219   unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00220 
00224   void SetSign(Float s) {m_Sign=s;}
00225   
00227   void SetTemp(Float s) {m_Temp=s;}
00228 
00229 
00231   void SetGamma(Float s) {m_Gamma=s;}
00232 
00233   void SetSolution(Solution::ConstPointer ptr) {  m_Solution=ptr; }
00234   Solution::ConstPointer GetSolution() {  return m_Solution; }
00235 
00236   // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
00237   Float GetSolution(unsigned int i,unsigned int which=0)
00238   {  
00239     return m_Solution->GetSolutionValue(i,which); 
00240   }
00241 
00242   FiniteDifferenceFunctionLoad(); // cannot be private until we always use smart pointers
00243   Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00244  
00248   VectorType Fe1(VectorType);
00249   FEMVectorType Fe(FEMVectorType,FEMVectorType);
00250  
00251   static Baseclass* NewFiniteDifferenceFunctionLoad(void)
00252   { return new FiniteDifferenceFunctionLoad; }
00253 
00254 
00256   void SetDeformationField( DeformationFieldTypePointer df)
00257     { m_DeformationField=df;}
00258 
00260   DeformationFieldTypePointer GetDeformationField() { return m_DeformationField;}
00261   void InitializeIteration();
00262   void InitializeMetric();
00263 
00264   void PrintCurrentEnergy();
00265   double GetCurrentEnergy();
00266   void  SetCurrentEnergy( double e = 0.0);
00267 
00268 protected:
00269 
00270 
00271 private:
00272   MovingPointer                                      m_MovingImage;
00273   FixedPointer                                       m_FixedImage;
00274   MovingRadiusType                                   m_MetricRadius; 
00275   typename MovingImageType::SizeType                 m_MovingSize;
00276   typename FixedImageType::SizeType                  m_FixedSize;
00277   unsigned int                                       m_NumberOfIntegrationPoints;
00278   unsigned int                                       m_SolutionIndex;
00279   unsigned int                                       m_SolutionIndex2;
00280   Float                                              m_Temp;
00281   Float                                              m_Gamma;
00282   typename Solution::ConstPointer                    m_Solution;
00283   
00284   float                                              m_GradSigma;
00285   float                                              m_Sign;
00286   float                                              m_WhichMetric;
00287   FiniteDifferenceFunctionTypePointer                m_DifferenceFunction;
00288 
00289   typename DeformationFieldType::Pointer             m_DeformationField;
00292   static const int DummyCLID;
00293 
00294 };
00295 
00296 
00297 
00298 
00299 }} // end namespace fem/itk
00300 
00301 #ifndef ITK_MANUAL_INSTANTIATION
00302 #include "itkFEMFiniteDifferenceFunctionLoad.txx"
00303 #endif
00304 
00305 #endif

Generated at Wed May 24 23:07:47 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000