00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00093 typedef typename
LoadElement::
Float Float;
00094
00095 typedef TMoving
MovingType;
00096 typedef typename MovingType::
ConstPointer MovingConstPointer;
00097 typedef MovingType*
MovingPointer;
00098 typedef TFixed
FixedType;
00099 typedef FixedType*
FixedPointer;
00100 typedef typename FixedType::
ConstPointer FixedConstPointer;
00101
00103 itkStaticConstMacro(ImageDimension,
unsigned int,
00104 MovingType::ImageDimension);
00105
00106 typedef
ImageRegionIteratorWithIndex<MovingType>
MovingRegionIteratorType;
00107 typedef
ImageRegionIteratorWithIndex<FixedType>
FixedRegionIteratorType;
00108
00109
00110 typedef
NeighborhoodIterator<MovingType>
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<FixedType>
00119 FixedNeighborhoodIteratorType;
00120 typedef typename FixedNeighborhoodIteratorType::IndexType
00121 FixedNeighborhoodIndexType;
00122 typedef typename FixedNeighborhoodIteratorType::RadiusType
00123 FixedRadiusType;
00124
00125
00126
00127 typedef typename MovingType::
PixelType MovingPixelType;
00128 typedef typename FixedType::
PixelType FixedPixelType;
00129 typedef Float
PixelType;
00130 typedef Float
ComputationType;
00131 typedef
Image< MovingPixelType, itkGetStaticConstMacro(ImageDimension) >
MovingImageType;
00132 typedef
Image< FixedPixelType, itkGetStaticConstMacro(ImageDimension) >
FixedImageType;
00133 typedef
Image< PixelType, itkGetStaticConstMacro(ImageDimension) >
ImageType;
00134 typedef itk::
Vector<
float,itkGetStaticConstMacro(ImageDimension)>
VectorType;
00135 typedef
vnl_vector<Float>
FEMVectorType;
00136 typedef
Image< VectorType, itkGetStaticConstMacro(ImageDimension) >
DeformationFieldType;
00137 typedef typename DeformationFieldType::
Pointer DeformationFieldTypePointer;
00138
00139
00140 typedef
NeighborhoodIterator<DeformationFieldType>
00141 FieldIteratorType;
00142
00143
00144
00146 typedef
PDEDeformableRegistrationFunction<FixedImageType,MovingImageType,
00147 DeformationFieldType>
FiniteDifferenceFunctionType;
00148 typedef typename FiniteDifferenceFunctionType::
Pointer FiniteDifferenceFunctionTypePointer;
00149 typedef typename FiniteDifferenceFunctionType::
TimeStepType TimeStepType;
00150
00151 typedef
MeanSquareRegistrationFunction<FixedImageType,MovingImageType,
00152 DeformationFieldType>
MeanSquareRegistrationFunctionType;
00153
00154 typedef
DemonsRegistrationFunction<FixedImageType,MovingImageType,
00155 DeformationFieldType>
DemonsRegistrationFunctionType;
00156
00157 typedef
NCCRegistrationFunction<FixedImageType,MovingImageType,
00158 DeformationFieldType>
NCCRegistrationFunctionType;
00159
00160 typedef
MIRegistrationFunction<FixedImageType,MovingImageType,
00161 DeformationFieldType>
MIRegistrationFunctionType;
00162
00163
00164
00165
00166
00167
00168 void SetDifferenceFunction( FiniteDifferenceFunctionTypePointer drfp)
00169 {
00170 drfp->SetFixedImage(m_FixedImage);
00171 drfp->SetMovingImage(m_MovingImage);
00172 drfp->SetRadius(m_MetricRadius);
00173 drfp->SetDeformationField(m_DeformationField);
00174 drfp->InitializeIteration();
00175 this->m_DifferenceFunction=drfp;
00176 }
00177
00178 void SetMetric(
FiniteDifferenceFunctionTypePointer drfp )
00179 {
00180 this->
SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
00181 drfp.GetPointer() ) );
00182
00183 m_FixedSize=m_DeformationField->GetLargestPossibleRegion().GetSize();
00184 }
00185
00186
00187
00189 void SetMovingImage(
MovingType* R)
00190 {
00191 m_MovingImage = R;
00192 m_MovingSize=m_MovingImage->
GetLargestPossibleRegion().GetSize();
00193
if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetMovingImage(m_MovingImage);
00194
00195 };
00196
00197
00199
void SetFixedImage(FixedType* T)
00200 {
00201 m_FixedImage=T;
00202 m_FixedSize=T->GetLargestPossibleRegion().GetSize();
00203
if (this->m_DifferenceFunction) this->m_DifferenceFunction->SetFixedImage(m_MovingImage);
00204
00205 };
00206
00207
00208 MovingPointer
GetMovingImage() {
return m_MovingImage; };
00209 FixedPointer
GetFixedImage() {
return m_FixedImage; };
00210
00212
void SetMetricRadius(
MovingRadiusType T) {m_MetricRadius = T; };
00214 MovingRadiusType GetMetricRadius() {
return m_MetricRadius; };
00215
00220
void SetNumberOfIntegrationPoints(
unsigned int i){ m_NumberOfIntegrationPoints=i;}
00221
unsigned int GetNumberOfIntegrationPoints(){
return m_NumberOfIntegrationPoints;}
00222
00226
void SetSign(Float s) {m_Sign=s;}
00227
00229
void SetTemp(Float s) {m_Temp=s;}
00230
00231
00233 void SetGamma(
Float s) {m_Gamma=s;}
00234
00235
void SetSolution(
Solution::ConstPointer ptr) { m_Solution=ptr; }
00236 Solution::ConstPointer
GetSolution() {
return m_Solution; }
00237
00238
00239 Float GetSolution(
unsigned int i,
unsigned int which=0)
00240 {
00241
return m_Solution->
GetSolutionValue(i,which);
00242 }
00243
00244
FiniteDifferenceFunctionLoad();
00245
Float EvaluateMetricGivenSolution (
Element::ArrayType* el,
Float step=1.0);
00246
00250
VectorType Fe1(
VectorType);
00251
FEMVectorType Fe(
FEMVectorType,
FEMVectorType);
00252
00253
static Baseclass*
NewFiniteDifferenceFunctionLoad(
void)
00254 {
return new FiniteDifferenceFunctionLoad; }
00255
00256
00258 void SetDeformationField(
DeformationFieldTypePointer df)
00259 { m_DeformationField=df;}
00260
00262 DeformationFieldTypePointer
GetDeformationField() {
return m_DeformationField;}
00263 void InitializeIteration();
00264
void InitializeMetric();
00265
00266
void PrintCurrentEnergy();
00267 double GetCurrentEnergy();
00268
void SetCurrentEnergy(
double e = 0.0);
00269
00270
protected:
00271
00272
00273
private:
00274
MovingPointer m_MovingImage;
00275
FixedPointer m_FixedImage;
00276
MovingRadiusType m_MetricRadius;
00277
typename MovingType::SizeType m_MovingSize;
00278
typename FixedType::SizeType m_FixedSize;
00279
unsigned int m_NumberOfIntegrationPoints;
00280
unsigned int m_SolutionIndex;
00281
unsigned int m_SolutionIndex2;
00282
Float m_Temp;
00283
Float m_Gamma;
00284
typename Solution::ConstPointer m_Solution;
00285
00286
float m_GradSigma;
00287
float m_Sign;
00288
float m_WhichMetric;
00289
FiniteDifferenceFunctionTypePointer m_DifferenceFunction;
00290
00291
typename DeformationFieldType::Pointer m_DeformationField;
00294
static const int DummyCLID;
00295
00296 };
00297
00298
00299
00300
00301 }}
00302
00303
#ifndef ITK_MANUAL_INSTANTIATION
00304
#include "itkFEMFiniteDifferenceFunctionLoad.txx"
00305
#endif
00306
00307
#endif