diff --git a/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.h b/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.h index 5a63ce757..79b37d0be 100644 --- a/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.h +++ b/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.h @@ -18,6 +18,7 @@ #ifndef itkCombinationImageToImageMetric_h #define itkCombinationImageToImageMetric_h +#include "itkTransformPenaltyTerm.h" #include "itkAdvancedImageToImageMetric.h" #include "itkSingleValuedPointSetToPointSetMetric.h" @@ -131,6 +132,10 @@ class ITK_TEMPLATE_EXPORT CombinationImageToImageMetric : public AdvancedImageTo using MovingImageRegionType = typename MovingImageType::RegionType; using MovingImageDerivativeScalesType = FixedArray; + /** Typedef for transform penalty metrics. */ + typedef TransformPenaltyTerm TransformMetricType; + typedef typename TransformMetricType::Pointer TransformMetricPointer; + /** Typedef for the PointSetMetric. */ using FixedPointSetType = PointSet m_Metrics{}; std::vector m_MetricWeights{}; std::vector m_MetricRelativeWeights{}; diff --git a/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.hxx b/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.hxx index b6be0fbaa..501f5d1f1 100644 --- a/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.hxx +++ b/Components/Registrations/MultiMetricMultiResolutionRegistration/itkCombinationImageToImageMetric.hxx @@ -160,6 +160,9 @@ CombinationImageToImageMetric::PrintSelf(std::ostream /** Add debugging information. */ os << "NumberOfMetrics: " << this->m_NumberOfMetrics << std::endl; + os << "NumberOfImageMetrics: " << this->m_NumberOfImageMetrics << std::endl; + os << "NumberOfTransformMetrics: " << this->m_NumberOfTransformMetrics << std::endl; + os << "NumberOfPointSetMetrics: " << this->m_NumberOfPointSetMetrics << std::endl; for (unsigned int i = 0; i < this->m_NumberOfMetrics; ++i) { os << "Metric " << i << ":\n"; @@ -275,12 +278,51 @@ CombinationImageToImageMetric::SetMetric(SingleValued this->SetNumberOfMetrics(pos + 1); } - if (metric != this->m_Metrics[pos]) + SingleValuedCostFunctionPointer oldMetricPtr = this->m_Metrics[pos]; + if (metric == oldMetricPtr) { - this->m_Metrics[pos] = metric; - this->Modified(); + return; + } + + PointSetMetricType * testPtr1 = dynamic_cast(metric); + TransformMetricType * testPtr2 = dynamic_cast(metric); + + // Increase newly defined numberOfMetric counters + if (testPtr1) + { + this->m_NumberOfPointSetMetrics++; + } + else if (testPtr2) + { + this->m_NumberOfTransformMetrics++; + } + else + { + this->m_NumberOfImageMetrics++; } + // if the metric has already been set, decrease the correct counter + if (oldMetricPtr != nullptr) + { + PointSetMetricType * oldTestPtr1 = dynamic_cast(oldMetricPtr.GetPointer()); + TransformMetricType * oldTestPtr2 = dynamic_cast(oldMetricPtr.GetPointer()); + if (oldTestPtr1) + { + this->m_NumberOfPointSetMetrics--; + } + else if (oldTestPtr2) + { + this->m_NumberOfTransformMetrics--; + } + else + { + this->m_NumberOfImageMetrics--; + } + } + + this->m_Metrics[pos] = metric; + this->Modified(); + } // end SetMetric() diff --git a/Components/Registrations/MultiMetricMultiResolutionRegistration/itkMultiMetricMultiResolutionImageRegistrationMethod.hxx b/Components/Registrations/MultiMetricMultiResolutionRegistration/itkMultiMetricMultiResolutionImageRegistrationMethod.hxx index 36a83d832..bf00827cc 100644 --- a/Components/Registrations/MultiMetricMultiResolutionRegistration/itkMultiMetricMultiResolutionImageRegistrationMethod.hxx +++ b/Components/Registrations/MultiMetricMultiResolutionRegistration/itkMultiMetricMultiResolutionImageRegistrationMethod.hxx @@ -565,44 +565,44 @@ MultiMetricMultiResolutionImageRegistrationMethod::Ch } /** nrofmetrics >= nrofinterpolators >= nrofpyramids >= nofimages */ - unsigned int nrOfMetrics = m_CombinationMetric->GetNumberOfMetrics(); - if (this->GetNumberOfInterpolators() > nrOfMetrics) + unsigned int nrOfImageMetrics = this->GetCombinationMetric()->GetNumberOfImageMetrics(); + if (this->GetNumberOfInterpolators() > nrOfImageMetrics) { - itkExceptionMacro("NumberOfInterpolators can not exceed the NumberOfMetrics in the CombinationMetric!"); + itkExceptionMacro("NumberOfInterpolators can not exceed the nrOfImageMetrics in the CombinationMetric!"); } - if (this->GetNumberOfFixedImagePyramids() > nrOfMetrics) + if (this->GetNumberOfFixedImagePyramids() > nrOfImageMetrics) { - itkExceptionMacro("NumberOfFixedImagePyramids can not exceed the NumberOfMetrics in the CombinationMetric!"); + itkExceptionMacro("NumberOfFixedImagePyramids can not exceed the nrOfImageMetrics in the CombinationMetric!"); } - if (this->GetNumberOfMovingImagePyramids() > nrOfMetrics) + if (this->GetNumberOfMovingImagePyramids() > nrOfImageMetrics) { - itkExceptionMacro("NumberOfMovingImagePyramids can not exceed the NumberOfMetrics in the CombinationMetric!"); + itkExceptionMacro("NumberOfMovingImagePyramids can not exceed the nrOfImageMetrics in the CombinationMetric!"); } if (this->GetNumberOfMovingImagePyramids() > this->GetNumberOfInterpolators()) { itkExceptionMacro("NumberOfMovingImagePyramids can not exceed the NumberOfInterpolators!"); } - /** For all components: ==nrofmetrics of ==1. */ - if ((this->GetNumberOfInterpolators() != 1) && (this->GetNumberOfInterpolators() != nrOfMetrics)) + /** For all components: ==nrOfImageMetrics of ==1. */ + if ((this->GetNumberOfInterpolators() != 1) && (this->GetNumberOfInterpolators() != nrOfImageMetrics)) { - itkExceptionMacro("The NumberOfInterpolators should equal 1 or equal the NumberOfMetrics"); + itkExceptionMacro("The NumberOfInterpolators should equal 1 or equal the nrOfImageMetrics"); } - if ((this->GetNumberOfFixedImagePyramids() != 1) && (this->GetNumberOfFixedImagePyramids() != nrOfMetrics)) + if ((this->GetNumberOfFixedImagePyramids() != 1) && (this->GetNumberOfFixedImagePyramids() != nrOfImageMetrics)) { - itkExceptionMacro("The NumberOfFixedImagePyramids should equal 1 or equal the NumberOfMetrics"); + itkExceptionMacro("The NumberOfFixedImagePyramids should equal 1 or equal the nrOfImageMetrics"); } - if ((this->GetNumberOfMovingImagePyramids() != 1) && (this->GetNumberOfMovingImagePyramids() != nrOfMetrics)) + if ((this->GetNumberOfMovingImagePyramids() != 1) && (this->GetNumberOfMovingImagePyramids() != nrOfImageMetrics)) { - itkExceptionMacro("The NumberOfMovingImagePyramids should equal 1 or equal the NumberOfMetrics"); + itkExceptionMacro("The NumberOfMovingImagePyramids should equal 1 or equal the nrOfImageMetrics"); } - if ((this->GetNumberOfFixedImages() != 1) && (this->GetNumberOfFixedImages() != nrOfMetrics)) + if ((this->GetNumberOfFixedImages() != 1) && (this->GetNumberOfFixedImages() != nrOfImageMetrics)) { - itkExceptionMacro("The NumberOfFixedImages should equal 1 or equal the NumberOfMetrics"); + itkExceptionMacro("The NumberOfFixedImages should equal 1 or equal the nrOfImageMetrics"); } - if ((this->GetNumberOfMovingImages() != 1) && (this->GetNumberOfMovingImages() != nrOfMetrics)) + if ((this->GetNumberOfMovingImages() != 1) && (this->GetNumberOfMovingImages() != nrOfImageMetrics)) { - itkExceptionMacro("The NumberOfMovingImages should equal 1 or equal the NumberOfMetrics"); + itkExceptionMacro("The NumberOfMovingImages should equal 1 or equal the nrOfImageMetrics"); } } // end CheckOnInitialize()