diff --git a/Modules/Core/Common/include/itkMath.h b/Modules/Core/Common/include/itkMath.h index d20cb490c44..17dadefcd70 100644 --- a/Modules/Core/Common/include/itkMath.h +++ b/Modules/Core/Common/include/itkMath.h @@ -329,11 +329,7 @@ FloatAlmostEqual(T x1, return false; } - typename Detail::FloatIEEE::IntType ulps = FloatDifferenceULP(x1, x2); - if (ulps < 0) - { - ulps = -ulps; - } + typename Detail::FloatIEEE::IntType ulps = std::abs(FloatDifferenceULP(x1, x2)); return ulps <= maxUlps; } diff --git a/Modules/Core/Common/include/itkTriangleCell.hxx b/Modules/Core/Common/include/itkTriangleCell.hxx index 9df171acaf5..13169c09cd8 100644 --- a/Modules/Core/Common/include/itkTriangleCell.hxx +++ b/Modules/Core/Common/include/itkTriangleCell.hxx @@ -20,6 +20,7 @@ #include "vnl/algo/vnl_determinant.h" #include // For copy_n. +#include // For abs. namespace itk { @@ -237,12 +238,7 @@ TriangleCell::DistanceToLine(PointType x, denom += static_cast(v21[i] * v21[i]); } - // trying to avoid an expensive fabs - double tolerance = 1.e-05 * num; - if (tolerance < 0.0) - { - tolerance = -tolerance; - } + double tolerance = std::abs(1.e-05 * num); if ((-tolerance < denom) && (denom < tolerance)) // numerically bad! { closestPoint = p1; // arbitrary, point is (numerically) far away diff --git a/Modules/Core/TestKernel/include/itkTestingComparisonImageFilter.hxx b/Modules/Core/TestKernel/include/itkTestingComparisonImageFilter.hxx index a93af7d2470..998319196e5 100644 --- a/Modules/Core/TestKernel/include/itkTestingComparisonImageFilter.hxx +++ b/Modules/Core/TestKernel/include/itkTestingComparisonImageFilter.hxx @@ -24,6 +24,8 @@ #include "itkNeighborhoodAlgorithm.h" #include "itkProgressReporter.h" +#include // For abs. + namespace itk { namespace Testing @@ -165,12 +167,8 @@ ComparisonImageFilter::ThreadedGenerateData(const Out InputPixelType t = valid.Get(); // Assume a good match - so test center pixel first, for speed - RealType difference = static_cast(t) - test.GetCenterPixel(); - if (NumericTraits::IsNegative(difference)) - { - difference = -difference; - } - auto minimumDifference = static_cast(difference); + RealType difference = std::abs(static_cast(t) - test.GetCenterPixel()); + auto minimumDifference = static_cast(difference); // If center pixel isn't good enough, then test the neighborhood if (minimumDifference > m_DifferenceThreshold) @@ -182,12 +180,8 @@ ComparisonImageFilter::ThreadedGenerateData(const Out { // Use the RealType for the difference to make sure we get the // sign. - RealType differenceReal = static_cast(t) - test.GetPixel(i); - if (NumericTraits::IsNegative(differenceReal)) - { - differenceReal = -differenceReal; - } - auto d = static_cast(differenceReal); + RealType differenceReal = std::abs(static_cast(t) - test.GetPixel(i)); + auto d = static_cast(differenceReal); if (d < minimumDifference) { minimumDifference = d; diff --git a/Modules/Filtering/ImageFeature/include/itkBilateralImageFilter.hxx b/Modules/Filtering/ImageFeature/include/itkBilateralImageFilter.hxx index fd250e6b086..92bf5bed6cc 100644 --- a/Modules/Filtering/ImageFeature/include/itkBilateralImageFilter.hxx +++ b/Modules/Filtering/ImageFeature/include/itkBilateralImageFilter.hxx @@ -25,6 +25,8 @@ #include "itkTotalProgressReporter.h" #include "itkStatisticsImageFilter.h" +#include // For abs. + namespace itk { template @@ -280,12 +282,8 @@ BilateralImageFilter::DynamicThreadedGenerateData( { // range distance between neighborhood pixel and neighborhood center pixel = static_cast(b_iter.GetPixel(i)); - rangeDistance = pixel - centerPixel; // flip sign if needed - if (rangeDistance < 0.0) - { - rangeDistance *= -1.0; - } + rangeDistance = std::abs(pixel - centerPixel); // if the range distance is close enough, then use the pixel if (rangeDistance < rangeDistanceThreshold) diff --git a/Modules/Numerics/FEM/src/itkFEMElement2DC0LinearLine.cxx b/Modules/Numerics/FEM/src/itkFEMElement2DC0LinearLine.cxx index 2d16a3fb40e..388781d6a90 100644 --- a/Modules/Numerics/FEM/src/itkFEMElement2DC0LinearLine.cxx +++ b/Modules/Numerics/FEM/src/itkFEMElement2DC0LinearLine.cxx @@ -17,6 +17,7 @@ *=========================================================================*/ #include "itkFEMElement2DC0LinearLine.h" +#include // For abs. namespace itk { @@ -144,13 +145,7 @@ Element2DC0LinearLine::DistanceToLine(const VectorType & x, // num = p21[0] * (x[0] - p1[0]) + p21[1] * (x[1] - p1[1]) + p21[2] * (x[2] - p1[2]); denom = p21[0] * p21[0] + p21[1] * p21[1] + p21[2] * p21[2]; - - // trying to avoid an expensive fabs - tolerance = 1e-5 * num; - if (tolerance < 0.0) - { - tolerance = -tolerance; - } + tolerance = std::abs(1e-5 * num); if (-tolerance < denom && denom < tolerance) // numerically bad! { closest = p1; // arbitrary, point is (numerically) far away diff --git a/Modules/Registration/Common/include/itkEuclideanDistancePointMetric.hxx b/Modules/Registration/Common/include/itkEuclideanDistancePointMetric.hxx index 50d8bc92ba0..e5614e7b854 100644 --- a/Modules/Registration/Common/include/itkEuclideanDistancePointMetric.hxx +++ b/Modules/Registration/Common/include/itkEuclideanDistancePointMetric.hxx @@ -19,6 +19,7 @@ #define itkEuclideanDistancePointMetric_hxx #include "itkImageRegionConstIteratorWithIndex.h" +#include // For abs. namespace itk { @@ -86,13 +87,9 @@ EuclideanDistancePointMetric::Get typename DistanceMapType::IndexType index; if (m_DistanceMap->TransformPhysicalPointToIndex(transformedPoint, index)) { - minimumDistance = m_DistanceMap->GetPixel(index); // In case the provided distance map was signed, // we correct here the distance to take its absolute value. - if (minimumDistance < 0.0) - { - minimumDistance = -minimumDistance; - } + minimumDistance = std::abs(m_DistanceMap->GetPixel(index)); closestPoint = true; } }