Skip to content

Commit

Permalink
BUG: Replace itk::Math::Round template argument double with int64_t
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
N-Dekker committed Jan 19, 2024
1 parent f831400 commit 5962579
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Common/CostFunctions/itkAdvancedImageToImageMetric.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ AdvancedImageToImageMetric<TFixedImage, TMovingImage>::EvaluateMovingImageValueA
MovingImageIndexType index;
for (unsigned int j = 0; j < MovingImageDimension; ++j)
{
index[j] = static_cast<long>(Math::Round<double>(cindex[j]));
index[j] = static_cast<long>(Math::Round<int64_t>(cindex[j]));
}
(*gradient) = this->m_GradientImage->GetPixel(index);
}
Expand Down
2 changes: 1 addition & 1 deletion Common/ImageSamplers/itkImageGridSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ ImageGridSampler<TInputImage>::SetNumberOfSamples(unsigned long nrofsamples)
/** Compute the grid spacing. */
const double indimd = static_cast<double>(InputImageDimension);
int gridSpacing = static_cast<int>( // no unsigned int version of rnd, max
Math::Round<double>(std::pow(fraction, 1.0 / indimd)));
Math::Round<int64_t>(std::pow(fraction, 1.0 / indimd)));
gridSpacing = std::max(1, gridSpacing);

/** Set gridSpacings for all dimensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "elxCorrespondingPointsEuclideanDistanceMetric.h"
#include "itkTransformixInputPointFileReader.h"
#include "itkTimeProbe.h"
#include <cstdint> // For int64_t.

namespace elastix
{
Expand Down Expand Up @@ -196,7 +197,7 @@ CorrespondingPointsEuclideanDistanceMetric<TElastix>::ReadLandmarks(const std::s
pointSet->GetPoint(j, &point);
for (unsigned int d = 0; d < FixedImageDimension; ++d)
{
index[d] = static_cast<IndexValueType>(itk::Math::Round<double>(point[d]));
index[d] = static_cast<IndexValueType>(itk::Math::Round<std::int64_t>(point[d]));
}

/** Compute the input point in physical coordinates. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "itkTransformixInputPointFileReader.h"
#include <vnl/vnl_math.h>
#include "itkTimeProbe.h"
#include <cstdint> // For int64_t.

namespace elastix
{
Expand Down Expand Up @@ -338,7 +339,7 @@ SplineKernelTransform<TElastix>::ReadLandmarkFile(const std::string & filename,
landmarkPointSet->GetPoint(j, &landmarkPoint);
for (unsigned int d = 0; d < SpaceDimension; ++d)
{
landmarkIndex[d] = static_cast<IndexValueType>(itk::Math::Round<double>(landmarkPoint[d]));
landmarkIndex[d] = static_cast<IndexValueType>(itk::Math::Round<std::int64_t>(landmarkPoint[d]));
}

/** Compute the input point in physical coordinates and replace the point. */
Expand Down
8 changes: 4 additions & 4 deletions Core/ComponentBaseClasses/elxTransformBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ TransformBase<TElastix>::TransformPointsSomePoints(const std::string & filename)
inputPointSet->GetPoint(j, &point);
for (unsigned int i = 0; i < FixedImageDimension; ++i)
{
inputindexvec[j][i] = static_cast<FixedImageIndexValueType>(itk::Math::Round<double>(point[i]));
inputindexvec[j][i] = static_cast<FixedImageIndexValueType>(itk::Math::Round<int64_t>(point[i]));
}
/** Compute the input point in physical coordinates. */
dummyImage->TransformIndexToPhysicalPoint(inputindexvec[j], inputpointvec[j]);
Expand All @@ -820,7 +820,7 @@ TransformBase<TElastix>::TransformPointsSomePoints(const std::string & filename)
const auto fixedcindex = dummyImage->template TransformPhysicalPointToContinuousIndex<double>(point);
for (unsigned int i = 0; i < FixedImageDimension; ++i)
{
inputindexvec[j][i] = static_cast<FixedImageIndexValueType>(itk::Math::Round<double>(fixedcindex[i]));
inputindexvec[j][i] = static_cast<FixedImageIndexValueType>(itk::Math::Round<int64_t>(fixedcindex[i]));
}
}
}
Expand All @@ -836,7 +836,7 @@ TransformBase<TElastix>::TransformPointsSomePoints(const std::string & filename)
const auto fixedcindex = dummyImage->template TransformPhysicalPointToContinuousIndex<double>(outputpointvec[j]);
for (unsigned int i = 0; i < FixedImageDimension; ++i)
{
outputindexfixedvec[j][i] = static_cast<FixedImageIndexValueType>(itk::Math::Round<double>(fixedcindex[i]));
outputindexfixedvec[j][i] = static_cast<FixedImageIndexValueType>(itk::Math::Round<int64_t>(fixedcindex[i]));
}

if (alsoMovingIndices)
Expand All @@ -846,7 +846,7 @@ TransformBase<TElastix>::TransformPointsSomePoints(const std::string & filename)
movingImage->template TransformPhysicalPointToContinuousIndex<double>(outputpointvec[j]);
for (unsigned int i = 0; i < MovingImageDimension; ++i)
{
outputindexmovingvec[j][i] = static_cast<MovingImageIndexValueType>(itk::Math::Round<double>(movingcindex[i]));
outputindexmovingvec[j][i] = static_cast<MovingImageIndexValueType>(itk::Math::Round<int64_t>(movingcindex[i]));
}
}

Expand Down

0 comments on commit 5962579

Please sign in to comment.