00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _itkFEMFiniteDifferenceFunctionLoad_h_
00018 #define _itkFEMFiniteDifferenceFunctionLoad_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 "itkDemonsRegistrationFunction.h"
00035 #include "itkMeanSquareRegistrationFunction.h"
00036 #include "itkNCCRegistrationFunction.h"
00037 #include "itkMIRegistrationFunction.h"
00038
00039 namespace itk
00040 {
00041 namespace fem
00042 {
00043
00063 template<class TMoving,class TFixed>
00064 class FiniteDifferenceFunctionLoad : public LoadElement
00065 {
00066 FEM_CLASS(FiniteDifferenceFunctionLoad,LoadElement)
00067 public:
00068
00069
00070 typedef typename LoadElement::Float Float;
00071
00072 typedef TMoving MovingImageType;
00073 typedef typename MovingImageType::ConstPointer MovingConstPointer;
00074 typedef MovingImageType* MovingPointer;
00075 typedef TFixed FixedImageType;
00076 typedef FixedImageType* FixedPointer;
00077 typedef typename FixedImageType::ConstPointer FixedConstPointer;
00078
00080 itkStaticConstMacro(ImageDimension, unsigned int,
00081 MovingImageType::ImageDimension);
00082
00083 typedef ImageRegionIteratorWithIndex<MovingImageType> MovingRegionIteratorType;
00084 typedef ImageRegionIteratorWithIndex<FixedImageType> FixedRegionIteratorType;
00085
00086
00087 typedef NeighborhoodIterator<MovingImageType>
00088 MovingNeighborhoodIteratorType;
00089 typedef typename MovingNeighborhoodIteratorType::IndexType
00090 MovingNeighborhoodIndexType;
00091 typedef typename MovingNeighborhoodIteratorType::RadiusType
00092 MovingRadiusType;
00093 typedef typename MovingNeighborhoodIteratorType::RadiusType
00094 RadiusType;
00095 typedef NeighborhoodIterator<FixedImageType>
00096 FixedNeighborhoodIteratorType;
00097 typedef typename FixedNeighborhoodIteratorType::IndexType
00098 FixedNeighborhoodIndexType;
00099 typedef typename FixedNeighborhoodIteratorType::RadiusType
00100 FixedRadiusType;
00101
00102
00103
00104 typedef typename MovingImageType::PixelType MovingPixelType;
00105 typedef typename FixedImageType::PixelType FixedPixelType;
00106 typedef Float PixelType;
00107 typedef Float ComputationType;
00108 typedef Image< PixelType, itkGetStaticConstMacro(ImageDimension) > ImageType;
00109 typedef itk::Vector<float,itkGetStaticConstMacro(ImageDimension)> VectorType;
00110 typedef vnl_vector<Float> FEMVectorType;
00111 typedef Image< VectorType, itkGetStaticConstMacro(ImageDimension) > DeformationFieldType;
00112 typedef typename DeformationFieldType::Pointer DeformationFieldTypePointer;
00113
00114
00115 typedef NeighborhoodIterator<DeformationFieldType>
00116 FieldIteratorType;
00117
00118
00119
00121 typedef PDEDeformableRegistrationFunction<FixedImageType,MovingImageType,
00122 DeformationFieldType> FiniteDifferenceFunctionType;
00123 typedef typename FiniteDifferenceFunctionType::Pointer FiniteDifferenceFunctionTypePointer;
00124 typedef typename FiniteDifferenceFunctionType::TimeStepType TimeStepType;
00125
00126 typedef MeanSquareRegistrationFunction<FixedImageType,MovingImageType,
00127 DeformationFieldType> MeanSquareRegistrationFunctionType;
00128
00129 typedef DemonsRegistrationFunction<FixedImageType,MovingImageType,
00130 DeformationFieldType> DemonsRegistrationFunctionType;
00131
00132 typedef NCCRegistrationFunction<FixedImageType,MovingImageType,
00133 DeformationFieldType> NCCRegistrationFunctionType;
00134
00135 typedef MIRegistrationFunction<FixedImageType,MovingImageType,
00136 DeformationFieldType> MIRegistrationFunctionType;
00137
00138
00139
00140
00141
00142
00143 void SetDifferenceFunction( FiniteDifferenceFunctionTypePointer drfp)
00144 {
00145 drfp->SetFixedImage(m_FixedImage);
00146 drfp->SetMovingImage(m_MovingImage);
00147 drfp->SetRadius(m_MetricRadius);
00148 drfp->SetDeformationField(m_DeformationField);
00149 drfp->InitializeIteration();
00150 this->m_DifferenceFunction=drfp;
00151 }
00152
00153 void SetMetric( FiniteDifferenceFunctionTypePointer drfp )
00154 {
00155 this->SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
00156 drfp.GetPointer() ) );
00157
00158 m_FixedSize=m_DeformationField->GetLargestPossibleRegion().GetSize();
00159 }
00160
00161
00162
00164 void SetMovingImage(MovingImageType* R)
00165 {
00166 m_MovingImage = R;
00167 m_MovingSize=m_MovingImage->GetLargestPossibleRegion().GetSize();
00168 if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetMovingImage(m_MovingImage);
00169
00170 };
00172
00173
00175 void SetFixedImage(FixedImageType* T)
00176 {
00177 m_FixedImage=T;
00178 m_FixedSize=T->GetLargestPossibleRegion().GetSize();
00179 if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetFixedImage(m_MovingImage);
00180
00181 };
00183
00184
00185 MovingPointer GetMovingImage() { return m_MovingImage; };
00186 FixedPointer GetFixedImage() { return m_FixedImage; };
00187
00189 void SetMetricRadius(MovingRadiusType T) {m_MetricRadius = T; };
00190
00192 MovingRadiusType GetMetricRadius() { return m_MetricRadius; };
00193
00198 void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00199 unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00201
00205 void SetSign(Float s) {m_Sign=s;}
00206
00208 void SetTemp(Float s) {m_Temp=s;}
00209
00210
00212 void SetGamma(Float s) {m_Gamma=s;}
00213
00214 void SetSolution(Solution::ConstPointer ptr) { m_Solution=ptr; }
00215 Solution::ConstPointer GetSolution() { return m_Solution; }
00216
00217
00218 Float GetSolution(unsigned int i,unsigned int which=0)
00219 {
00220 return m_Solution->GetSolutionValue(i,which);
00221 }
00222
00223 FiniteDifferenceFunctionLoad();
00224 Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00225
00229 VectorType Fe1(VectorType);
00230 FEMVectorType Fe(FEMVectorType,FEMVectorType);
00232
00233 static Baseclass* NewFiniteDifferenceFunctionLoad(void)
00234 { return new FiniteDifferenceFunctionLoad; }
00235
00236
00238 void SetDeformationField( DeformationFieldTypePointer df)
00239 { m_DeformationField=df;}
00240
00242 DeformationFieldTypePointer GetDeformationField() { return m_DeformationField;}
00243 void InitializeIteration();
00244 void InitializeMetric();
00246
00247 void PrintCurrentEnergy();
00248 double GetCurrentEnergy();
00249 void SetCurrentEnergy( double e = 0.0);
00250
00251 protected:
00252
00253
00254 private:
00255 MovingPointer m_MovingImage;
00256 FixedPointer m_FixedImage;
00258 typename MovingImageType::SizeType m_MovingSize;
00259 typename FixedImageType::SizeType m_FixedSize;
00260 unsigned int m_NumberOfIntegrationPoints;
00261 unsigned int m_SolutionIndex;
00262 unsigned int m_SolutionIndex2;
00263 Float m_Temp;
00264 Float m_Gamma;
00265 typename Solution::ConstPointer m_Solution;
00266
00267 float m_GradSigma;
00268 float m_Sign;
00269 float m_WhichMetric;
00270 FiniteDifferenceFunctionTypePointer m_DifferenceFunction;
00271
00272 typename DeformationFieldType::Pointer m_DeformationField;
00275 static const int DummyCLID;
00276
00277 };
00278
00279
00280
00281
00282 }}
00283
00284 #ifndef ITK_MANUAL_INSTANTIATION
00285 #include "itkFEMFiniteDifferenceFunctionLoad.txx"
00286 #endif
00287
00288 #endif
00289