From 5962579eb5b63adf82342d65caac2619aafc60ea Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 18 Jan 2024 12:01:59 +0100 Subject: [PATCH] BUG: Replace itk::Math::Round template argument `double` with `int64_t` According to https://github.com/InsightSoftwareConsortium/ITK/blob/66ab5b14c476d057ed46a4daba05b710681160e6/Modules/Core/Common/include/itkMath.h#L127 the `TReturn` template argument of `Math::Round` must be an integer type. In practice, it will internally call `Detail::RoundHalfIntegerToEven_64` when `TReturn` is a 64-bit `double`. Which returns an `int64_t` anyway. --- Common/CostFunctions/itkAdvancedImageToImageMetric.hxx | 2 +- Common/ImageSamplers/itkImageGridSampler.hxx | 2 +- .../elxCorrespondingPointsEuclideanDistanceMetric.hxx | 3 ++- .../SplineKernelTransform/elxSplineKernelTransform.hxx | 3 ++- Core/ComponentBaseClasses/elxTransformBase.hxx | 8 ++++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx b/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx index b471b8e4e..a41e4b2fd 100644 --- a/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx +++ b/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx @@ -550,7 +550,7 @@ AdvancedImageToImageMetric::EvaluateMovingImageValueA MovingImageIndexType index; for (unsigned int j = 0; j < MovingImageDimension; ++j) { - index[j] = static_cast(Math::Round(cindex[j])); + index[j] = static_cast(Math::Round(cindex[j])); } (*gradient) = this->m_GradientImage->GetPixel(index); } diff --git a/Common/ImageSamplers/itkImageGridSampler.hxx b/Common/ImageSamplers/itkImageGridSampler.hxx index 74876dbf3..d37f09f7e 100644 --- a/Common/ImageSamplers/itkImageGridSampler.hxx +++ b/Common/ImageSamplers/itkImageGridSampler.hxx @@ -543,7 +543,7 @@ ImageGridSampler::SetNumberOfSamples(unsigned long nrofsamples) /** Compute the grid spacing. */ const double indimd = static_cast(InputImageDimension); int gridSpacing = static_cast( // no unsigned int version of rnd, max - Math::Round(std::pow(fraction, 1.0 / indimd))); + Math::Round(std::pow(fraction, 1.0 / indimd))); gridSpacing = std::max(1, gridSpacing); /** Set gridSpacings for all dimensions diff --git a/Components/Metrics/CorrespondingPointsEuclideanDistanceMetric/elxCorrespondingPointsEuclideanDistanceMetric.hxx b/Components/Metrics/CorrespondingPointsEuclideanDistanceMetric/elxCorrespondingPointsEuclideanDistanceMetric.hxx index 6fc4d5f21..9b766dbb0 100644 --- a/Components/Metrics/CorrespondingPointsEuclideanDistanceMetric/elxCorrespondingPointsEuclideanDistanceMetric.hxx +++ b/Components/Metrics/CorrespondingPointsEuclideanDistanceMetric/elxCorrespondingPointsEuclideanDistanceMetric.hxx @@ -21,6 +21,7 @@ #include "elxCorrespondingPointsEuclideanDistanceMetric.h" #include "itkTransformixInputPointFileReader.h" #include "itkTimeProbe.h" +#include // For int64_t. namespace elastix { @@ -196,7 +197,7 @@ CorrespondingPointsEuclideanDistanceMetric::ReadLandmarks(const std::s pointSet->GetPoint(j, &point); for (unsigned int d = 0; d < FixedImageDimension; ++d) { - index[d] = static_cast(itk::Math::Round(point[d])); + index[d] = static_cast(itk::Math::Round(point[d])); } /** Compute the input point in physical coordinates. */ diff --git a/Components/Transforms/SplineKernelTransform/elxSplineKernelTransform.hxx b/Components/Transforms/SplineKernelTransform/elxSplineKernelTransform.hxx index 40a2857e3..8c931ec01 100644 --- a/Components/Transforms/SplineKernelTransform/elxSplineKernelTransform.hxx +++ b/Components/Transforms/SplineKernelTransform/elxSplineKernelTransform.hxx @@ -22,6 +22,7 @@ #include "itkTransformixInputPointFileReader.h" #include #include "itkTimeProbe.h" +#include // For int64_t. namespace elastix { @@ -338,7 +339,7 @@ SplineKernelTransform::ReadLandmarkFile(const std::string & filename, landmarkPointSet->GetPoint(j, &landmarkPoint); for (unsigned int d = 0; d < SpaceDimension; ++d) { - landmarkIndex[d] = static_cast(itk::Math::Round(landmarkPoint[d])); + landmarkIndex[d] = static_cast(itk::Math::Round(landmarkPoint[d])); } /** Compute the input point in physical coordinates and replace the point. */ diff --git a/Core/ComponentBaseClasses/elxTransformBase.hxx b/Core/ComponentBaseClasses/elxTransformBase.hxx index 635a78cc7..353cacfe9 100644 --- a/Core/ComponentBaseClasses/elxTransformBase.hxx +++ b/Core/ComponentBaseClasses/elxTransformBase.hxx @@ -803,7 +803,7 @@ TransformBase::TransformPointsSomePoints(const std::string & filename) inputPointSet->GetPoint(j, &point); for (unsigned int i = 0; i < FixedImageDimension; ++i) { - inputindexvec[j][i] = static_cast(itk::Math::Round(point[i])); + inputindexvec[j][i] = static_cast(itk::Math::Round(point[i])); } /** Compute the input point in physical coordinates. */ dummyImage->TransformIndexToPhysicalPoint(inputindexvec[j], inputpointvec[j]); @@ -820,7 +820,7 @@ TransformBase::TransformPointsSomePoints(const std::string & filename) const auto fixedcindex = dummyImage->template TransformPhysicalPointToContinuousIndex(point); for (unsigned int i = 0; i < FixedImageDimension; ++i) { - inputindexvec[j][i] = static_cast(itk::Math::Round(fixedcindex[i])); + inputindexvec[j][i] = static_cast(itk::Math::Round(fixedcindex[i])); } } } @@ -836,7 +836,7 @@ TransformBase::TransformPointsSomePoints(const std::string & filename) const auto fixedcindex = dummyImage->template TransformPhysicalPointToContinuousIndex(outputpointvec[j]); for (unsigned int i = 0; i < FixedImageDimension; ++i) { - outputindexfixedvec[j][i] = static_cast(itk::Math::Round(fixedcindex[i])); + outputindexfixedvec[j][i] = static_cast(itk::Math::Round(fixedcindex[i])); } if (alsoMovingIndices) @@ -846,7 +846,7 @@ TransformBase::TransformPointsSomePoints(const std::string & filename) movingImage->template TransformPhysicalPointToContinuousIndex(outputpointvec[j]); for (unsigned int i = 0; i < MovingImageDimension; ++i) { - outputindexmovingvec[j][i] = static_cast(itk::Math::Round(movingcindex[i])); + outputindexmovingvec[j][i] = static_cast(itk::Math::Round(movingcindex[i])); } }