4 #include <itkImageRegionConstIteratorWithIndex.h> 9 template <
class TFixedImage,
class TMovingImage>
13 m_ScaleIntensities =
false;
14 m_DefaultBackgroundValue = 0.0;
17 template <
class TFixedImage,
class TMovingImage>
26 itkExceptionMacro( <<
"Fixed image has not been assigned" );
29 if (this->m_NumberOfPixelsCounted == 0)
33 this->SetTransformParameters( parameters );
39 for (
unsigned int i = 0;i < this->m_NumberOfPixelsCounted;++i)
41 transformedPoint = this->m_Transform->TransformPoint( m_FixedImagePoints[i] );
42 this->m_Interpolator->GetInputImage()->TransformPhysicalPointToContinuousIndex(transformedPoint,transformedIndex);
44 movingValue = m_DefaultBackgroundValue;
46 if( this->m_Interpolator->IsInsideBuffer( transformedIndex ) )
48 movingValue = this->m_Interpolator->EvaluateAtContinuousIndex( transformedIndex );
50 if (m_ScaleIntensities)
52 typedef itk::MatrixOffsetTransformBase <
typename TransformType::ScalarType,
53 TFixedImage::ImageDimension, TFixedImage::ImageDimension> BaseTransformType;
54 BaseTransformType *currentTrsf =
dynamic_cast<BaseTransformType *
> (this->m_Transform.GetPointer());
56 double factor = vnl_determinant(currentTrsf->GetMatrix().GetVnlMatrix());
57 movingValue *= factor;
61 measure += (movingValue - m_FixedImageValues[i]) * (movingValue - m_FixedImageValues[i]);
64 measure /= this->m_NumberOfPixelsCounted;
69 template <
class TFixedImage,
class TMovingImage>
75 itkExceptionMacro(
"Derivative not implemented yet...");
78 template <
class TFixedImage,
class TMovingImage>
84 itkExceptionMacro(
"Derivative not implemented yet...");
87 template <
class TFixedImage,
class TMovingImage>
96 itkExceptionMacro( <<
"Fixed image has not been assigned" );
99 typedef itk::ImageRegionConstIteratorWithIndex<FixedImageType> FixedIteratorType;
101 FixedIteratorType ti( fixedImage, this->GetFixedImageRegion() );
102 typename FixedImageType::IndexType index;
104 this->m_NumberOfPixelsCounted = this->GetFixedImageRegion().GetSize()[0];
105 for (
unsigned int i = 1;i < TFixedImage::GetImageDimension();++i)
106 this->m_NumberOfPixelsCounted *= this->GetFixedImageRegion().GetSize()[i];
108 m_FixedImagePoints.resize(this->m_NumberOfPixelsCounted);
109 m_FixedImageValues.resize(this->m_NumberOfPixelsCounted);
113 unsigned int pos = 0;
118 index = ti.GetIndex();
119 fixedImage->TransformIndexToPhysicalPoint( index, inputPoint );
121 m_FixedImagePoints[pos] = inputPoint;
122 fixedValue = ti.Value();
123 m_FixedImageValues[pos] = fixedValue;
Superclass::DerivativeType DerivativeType
Superclass::RealType RealType
void PreComputeFixedValues()
void GetDerivative(const TransformParametersType ¶meters, DerivativeType &Derivative) const ITK_OVERRIDE
Superclass::InputPointType InputPointType
Superclass::MeasureType MeasureType
MeasureType GetValue(const TransformParametersType ¶meters) const ITK_OVERRIDE
FastMeanSquaresImageToImageMetric()
Superclass::FixedImageConstPointer FixedImageConstPointer
Superclass::TransformParametersType TransformParametersType
void GetValueAndDerivative(const TransformParametersType ¶meters, MeasureType &Value, DerivativeType &Derivative) const ITK_OVERRIDE
itk::ContinuousIndex< double, TFixedImage::ImageDimension > ContinuousIndexType
Superclass::OutputPointType OutputPointType