Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/ImageRegistration11.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CommandIterationUpdate : public itk::Command
}
const double currentValue = optimizer->GetValue();
// Only print out when the Metric value changes
if (itk::Math::abs(m_LastMetricValue - currentValue) > 1e-7)
if (itk::Math::Absolute(m_LastMetricValue - currentValue) > 1e-7)
{
std::cout << optimizer->GetCurrentIteration() << " ";
std::cout << currentValue << " ";
Expand Down
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/ImageRegistration14.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CommandIterationUpdate : public itk::Command
}
const double currentValue = optimizer->GetValue();
// Only print out when the Metric value changes
if (itk::Math::abs(m_LastMetricValue - currentValue) > 1e-7)
if (itk::Math::Absolute(m_LastMetricValue - currentValue) > 1e-7)
{
std::cout << optimizer->GetCurrentIteration() << " ";
std::cout << currentValue << " ";
Expand Down
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/ImageRegistration15.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CommandIterationUpdate : public itk::Command
}
const double currentValue = optimizer->GetValue();
// Only print out when the Metric value changes
if (itk::Math::abs(m_LastMetricValue - currentValue) > 1e-7)
if (itk::Math::Absolute(m_LastMetricValue - currentValue) > 1e-7)
{
std::cout << optimizer->GetCurrentIteration() << " ";
std::cout << currentValue << " ";
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkBSplineKernelFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
static inline TRealValueType
Evaluate(const Dispatch<0> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
const TRealValueType absValue = itk::Math::Absolute(u);
if (absValue < TRealValueType{ 0.5 })
{
return TRealValueType{ 1.0 };
Expand All @@ -117,7 +117,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
static inline TRealValueType
Evaluate(const Dispatch<1> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
const TRealValueType absValue = itk::Math::Absolute(u);
if (absValue < TRealValueType{ 1.0 })
{
return TRealValueType{ 1.0 } - absValue;
Expand All @@ -130,7 +130,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
static inline TRealValueType
Evaluate(const Dispatch<2> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
const TRealValueType absValue = itk::Math::Absolute(u);
if (absValue < TRealValueType{ 0.5 })
{
const TRealValueType sqrValue = itk::Math::sqr(absValue);
Expand All @@ -153,7 +153,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
static inline TRealValueType
Evaluate(const Dispatch<3> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
const TRealValueType absValue = itk::Math::Absolute(u);
if (absValue < TRealValueType{ 1.0 })
{
const TRealValueType sqrValue = itk::Math::sqr(absValue);
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkBresenhamLine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ BresenhamLine<VDimension>::BuildLine(LType Direction, IdentifierType length) ->
IndexType overflowIncrement;
for (unsigned int i = 0; i < VDimension; ++i)
{
auto distance = static_cast<long>(itk::Math::abs(LastIndex[i]));
auto distance = static_cast<long>(itk::Math::Absolute(LastIndex[i]));
if (distance > maxDistance)
{
maxDistance = distance;
Expand Down Expand Up @@ -113,7 +113,7 @@ BresenhamLine<VDimension>::BuildLine(IndexType p0, IndexType p1) -> IndexArray
{
point0[i] = p0[i];
point1[i] = p1[i];
const IdentifierType distance = itk::Math::abs(p0[i] - p1[i]) + 1;
const IdentifierType distance = itk::Math::Absolute(p0[i] - p1[i]) + 1;
if (distance > maxDistance)
{
maxDistance = distance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ FiniteCylinderSpatialFunction<VDimension, TInput>::Evaluate(const InputType & po
FloatingPointExceptions::SetEnabled(saveFPEState);
}

if (itk::Math::abs(distanceFromCenter) <= (halfAxisLength) &&
if (itk::Math::Absolute(distanceFromCenter) <= (halfAxisLength) &&
m_Radius >= std::sqrt(Math::sqr(pointVector.GetNorm()) - Math::sqr(distanceFromCenter)))
{
return 1;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkFrustumSpatialFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FrustumSpatialFunction<VDimension, TInput>::Evaluate(const InputType & position)

// Check planes along Y
const double angleY = std::atan2(dy, distanceXZ);
if (itk::Math::abs(angleY) > m_ApertureAngleY * deg2rad)
if (itk::Math::Absolute(angleY) > m_ApertureAngleY * deg2rad)
{
return 0;
}
Expand All @@ -89,7 +89,7 @@ FrustumSpatialFunction<VDimension, TInput>::Evaluate(const InputType & position)

// Check planes along X
const double angleX = std::atan2(dx, distanceYZ);
if (itk::Math::abs(angleX) > m_ApertureAngleX * deg2rad)
if (itk::Math::Absolute(angleX) > m_ApertureAngleX * deg2rad)
{
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkGaussianDerivativeOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ GaussianDerivativeOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI0(dou
{
double accumulator = NAN;

const double d = itk::Math::abs(y);
const double d = itk::Math::Absolute(y);
if (d < 3.75)
{
double m = y / 3.75;
Expand Down Expand Up @@ -191,7 +191,7 @@ double
GaussianDerivativeOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI1(double y)
{
double accumulator = NAN;
const double d = itk::Math::abs(y);
const double d = itk::Math::Absolute(y);
if (d < 3.75)
{
double m = y / 3.75;
Expand Down Expand Up @@ -236,15 +236,15 @@ GaussianDerivativeOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI(int
return 0.0;
}

const double toy = 2.0 / itk::Math::abs(y);
const double toy = 2.0 / itk::Math::Absolute(y);
double qip = accumulator = 0.0;
double qi = 1.0;
for (int j = 2 * (n + static_cast<int>(DIGITS * std::sqrt(static_cast<double>(n)))); j > 0; j--)
{
const double qim = qip + j * toy * qi;
qip = qi;
qi = qim;
if (itk::Math::abs(qi) > 1.0e10)
if (itk::Math::Absolute(qi) > 1.0e10)
{
accumulator *= 1.0e-10;
qi *= 1.0e-10;
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkGaussianOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ template <typename TPixel, unsigned int VDimension, typename TAllocator>
double
GaussianOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI0(double y)
{
const double d = itk::Math::abs(y);
const double d = itk::Math::Absolute(y);
double accumulator = NAN;

if (d < 3.75)
Expand Down Expand Up @@ -104,7 +104,7 @@ template <typename TPixel, unsigned int VDimension, typename TAllocator>
double
GaussianOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI1(double y)
{
const double d = itk::Math::abs(y);
const double d = itk::Math::Absolute(y);
double accumulator = NAN;

if (d < 3.75)
Expand Down Expand Up @@ -151,7 +151,7 @@ GaussianOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI(int n, double
return 0.0;
}

const double toy = 2.0 / itk::Math::abs(y);
const double toy = 2.0 / itk::Math::Absolute(y);
double qip = 0.0;
double accumulator = 0.0;
double qi = 1.0;
Expand All @@ -161,7 +161,7 @@ GaussianOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI(int n, double
const double qim = qip + j * toy * qi;
qip = qi;
qi = qim;
if (itk::Math::abs(qi) > 1.0e10)
if (itk::Math::Absolute(qi) > 1.0e10)
{
accumulator *= 1.0e-10;
qi *= 1.0e-10;
Expand Down
12 changes: 6 additions & 6 deletions Modules/Core/Common/include/itkHexahedronCell.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ HexahedronCell<TCellInterface>::EvaluatePosition(CoordinateType * x,
// spell-check-disable
// d=vtkMath::Determinant3x3(rcol,scol,tcol);
// spell-check-enable
if (itk::Math::abs(d) < 1.e-20)
if (itk::Math::Absolute(d) < 1.e-20)
{
return false;
}
Expand Down Expand Up @@ -443,16 +443,16 @@ HexahedronCell<TCellInterface>::EvaluatePosition(CoordinateType * x,
}

// check for convergence
if (((itk::Math::abs(pcoords[0] - params[0])) < ITK_HEX_CONVERGED) &&
((itk::Math::abs(pcoords[1] - params[1])) < ITK_HEX_CONVERGED) &&
((itk::Math::abs(pcoords[2] - params[2])) < ITK_HEX_CONVERGED))
if (((itk::Math::Absolute(pcoords[0] - params[0])) < ITK_HEX_CONVERGED) &&
((itk::Math::Absolute(pcoords[1] - params[1])) < ITK_HEX_CONVERGED) &&
((itk::Math::Absolute(pcoords[2] - params[2])) < ITK_HEX_CONVERGED))
{
converged = 1;
}

// Test for bad divergence (S.Hirschberg 11.12.2001)
else if ((itk::Math::abs(pcoords[0]) > ITK_DIVERGED) || (itk::Math::abs(pcoords[1]) > ITK_DIVERGED) ||
(itk::Math::abs(pcoords[2]) > ITK_DIVERGED))
else if ((itk::Math::Absolute(pcoords[0]) > ITK_DIVERGED) || (itk::Math::Absolute(pcoords[1]) > ITK_DIVERGED) ||
(itk::Math::Absolute(pcoords[2]) > ITK_DIVERGED))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImageBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ ImageBase<VImageDimension>::IsCongruentImageGeometry(const ImageBase * otherImag
// tolerance for origin and spacing depends on the size of pixel
// tolerance for directions a fraction of the unit cube.
const SpacePrecisionType coordinateTol =
itk::Math::abs(coordinateTolerance * this->GetSpacing()[0]); // use first dimension spacing
itk::Math::Absolute(coordinateTolerance * this->GetSpacing()[0]); // use first dimension spacing

return this->GetOrigin().GetVnlVector().is_equal(otherImage->GetOrigin().GetVnlVector(), coordinateTol) &&
this->GetSpacing().GetVnlVector().is_equal(otherImage->GetSpacing().GetVnlVector(), coordinateTol) &&
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImageSink.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ ImageSink<TInputImage>::VerifyInputInformation() const
// tolerance for origin and spacing depends on the size of pixel
// tolerance for directions a fraction of the unit cube.
const SpacePrecisionType coordinateTol =
itk::Math::abs(this->m_CoordinateTolerance * inputPtr1->GetSpacing()[0]); // use first dimension spacing
itk::Math::Absolute(this->m_CoordinateTolerance * inputPtr1->GetSpacing()[0]); // use first dimension spacing

if (!inputPtr1->GetOrigin().GetVnlVector().is_equal(inputPtrN->GetOrigin().GetVnlVector(), coordinateTol) ||
!inputPtr1->GetSpacing().GetVnlVector().is_equal(inputPtrN->GetSpacing().GetVnlVector(), coordinateTol) ||
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImageToImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ImageToImageFilter<TInputImage, TOutputImage>::VerifyInputInformation() const
// tolerance for origin and spacing depends on the size of pixel
// tolerance for directions a fraction of the unit cube.
const SpacePrecisionType coordinateTol =
itk::Math::abs(this->m_CoordinateTolerance * inputPtr1->GetSpacing()[0]); // use first dimension spacing
itk::Math::Absolute(this->m_CoordinateTolerance * inputPtr1->GetSpacing()[0]); // use first dimension spacing

if (!inputPtr1->IsCongruentImageGeometry(inputPtrN, m_CoordinateTolerance, m_DirectionTolerance))
{
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkLineConstIterator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LineConstIterator<TImage>::LineConstIterator(const ImageType * imagePtr,
unsigned int maxDistanceDimension = 0;
for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
{
const IndexValueType distance = itk::Math::abs(difference[i]);
const IndexValueType distance = itk::Math::Absolute(difference[i]);
if (distance > maxDistance)
{
maxDistance = distance;
Expand Down
24 changes: 15 additions & 9 deletions Modules/Core/Common/include/itkMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -860,18 +860,24 @@ using vnl_math::squared_magnitude;
* @brief Returns the absolute value of a number.
*
* This function provides a c++17 implementation of the vnl_math::abs absolute value functionality.
* safe_abs preserves backward compatibility with vnl_math::abs that was originally used in ITK.
* itk::Absolute() preserves backward compatibility with vnl_math::abs that was originally used in ITK.
*
* Where std::abs returns the absolute value in the same type as the input, itk::safe_abs
* returns the absolute value in the unsigned equivalent of the input type.
* Key differences between itk::Absolute() and std::abs()
* - Where std::abs() returns the absolute value in the same type as the
* input, itk::Absolute() returns the absolute value in the unsigned
* equivalent of the input type.
* - std::abs() is undefined when converting the minimum storage value of unsigned
* integers to positive values. itk::Absolute() typecasts to a larger storage type
* before taking the absolute value to prevent overflow failures. This is used in
* all cases except 'signed long long' where there is no larger storage type.
*
* @tparam T The type of the input number.
* @param x The input number.
* @return The absolute value of the input number as an unsigned type for integer types.
*/
template <typename T>
constexpr auto
safe_abs(T x) noexcept
Absolute(T x) noexcept
{
if constexpr (std::is_same_v<T, bool>)
{
Expand Down Expand Up @@ -937,23 +943,23 @@ safe_abs(T x) noexcept
}
template <typename T>
auto
safe_abs(const std::complex<T> & x) noexcept
Absolute(const std::complex<T> & x) noexcept
{
// std::abs<T>(std::complex<T>) is not constexpr in in any proposed c++ standard
return std::abs<T>(x);
}


// itk::Math::abs has different behavior than std::abs. The use of
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
// itk::Math::Absolute has different behavior than std::abs. The use of
// abs() in the ITK context without namespace resolution can be confusing
// The abs() version is provided for backwards compatibility.
template <typename T>
auto
abs(T x) noexcept
{
return safe_abs(x);
return Absolute(x);
}

#endif

} // namespace itk::Math

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkNumericTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NumericTraits : public std::numeric_limits<T>
/** Return the type that can be printed. */
using PrintType = T;

/** Return value of itk::Math::abs(). */
/** Return value of itk::Math::Absolute(). */
using AbsType = T;

/** Accumulation of addition and multiplication. */
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkQuadrilateralCell.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ QuadrilateralCell<TCellInterface>::EvaluatePosition(CoordinateType * x,
// spell-check-disable
// d=vtkMath::Determinant2x2(rcol,scol);
// spell-check-enable
if (itk::Math::abs(d) < 1.e-20)
if (itk::Math::Absolute(d) < 1.e-20)
{
return false;
}
Expand Down Expand Up @@ -366,14 +366,14 @@ QuadrilateralCell<TCellInterface>::EvaluatePosition(CoordinateType * x,
}

// check for convergence
if (((itk::Math::abs(pcoords[0] - params[0])) < ITK_QUAD_CONVERGED) &&
((itk::Math::abs(pcoords[1] - params[1])) < ITK_QUAD_CONVERGED))
if (((itk::Math::Absolute(pcoords[0] - params[0])) < ITK_QUAD_CONVERGED) &&
((itk::Math::Absolute(pcoords[1] - params[1])) < ITK_QUAD_CONVERGED))
{
converged = 1;
}

// Test for bad divergence (S.Hirschberg 11.12.2001)
else if ((itk::Math::abs(pcoords[0]) > ITK_DIVERGED) || (itk::Math::abs(pcoords[1]) > ITK_DIVERGED))
else if ((itk::Math::Absolute(pcoords[0]) > ITK_DIVERGED) || (itk::Math::Absolute(pcoords[1]) > ITK_DIVERGED))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ template <typename TInput, typename TOutput>
auto
SinRegularizedHeavisideStepFunction<TInput, TOutput>::EvaluateDerivative(const InputType & input) const -> OutputType
{
if (itk::Math::abs(static_cast<RealType>(input)) >= this->GetEpsilon())
if (itk::Math::Absolute(static_cast<RealType>(input)) >= this->GetEpsilon())
{
return OutputType{};
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkSpatialOrientationAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Max3(double x, double y, double z)
{
constexpr double obliquityThresholdCosineValue{ 0.001 };

const double absX = itk::Math::abs(x);
const double absY = itk::Math::abs(y);
const double absZ = itk::Math::abs(z);
const double absX = itk::Math::Absolute(x);
const double absY = itk::Math::Absolute(y);
const double absZ = itk::Math::Absolute(z);

if ((absX > obliquityThresholdCosineValue) && (absX > absY) && (absX > absZ))
{
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkSymmetricEigenAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sortEigenValuesByMagnitude(TArray & eigenValues, const unsigned int numberOfElem
std::sort(std::begin(indicesSortPermutations),
std::end(indicesSortPermutations),
[&eigenValues](unsigned int a, unsigned int b) {
return itk::Math::abs(eigenValues[a]) < itk::Math::abs(eigenValues[b]);
return itk::Math::Absolute(eigenValues[a]) < itk::Math::Absolute(eigenValues[b]);
});
auto tmpCopy = eigenValues;
for (unsigned int i = 0; i < numberOfElements; ++i)
Expand Down
Loading
Loading