Skip to content

Commit

Permalink
STYLE: Prefer itk::Math::abs for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjmjohnson committed Dec 17, 2021
1 parent 4e48dc4 commit 05f3ad2
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions include/rtkBackProjectionImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ BackProjectionImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateDat
}

// Optimized version
if (fabs(matrix[1][0]) < 1e-10 && fabs(matrix[2][0]) < 1e-10)
if (itk::Math::abs(matrix[1][0]) < 1e-10 && itk::Math::abs(matrix[2][0]) < 1e-10)
{
OptimizedBackprojectionX(outputRegionForThread, matrix, projection);
continue;
}
if (fabs(matrix[1][1]) < 1e-10 && fabs(matrix[2][1]) < 1e-10)
if (itk::Math::abs(matrix[1][1]) < 1e-10 && itk::Math::abs(matrix[2][1]) < 1e-10)
{
OptimizedBackprojectionY(outputRegionForThread, matrix, projection);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ DisplacedDetectorForOffsetFieldOfViewImageFilter<TInputImage, TOutputImage>::Gen
<< " space must be covered by all projections.");
}
// Case 2: Not displaced if less than 10% relative difference between radii
else if (200. * fabs(ri - rs) / (ri + rs) < 10.)
else if (200. * itk::Math::abs(ri - rs) / (ri + rs) < 10.)
{
this->SetInPlace(true);
}
Expand Down
4 changes: 2 additions & 2 deletions include/rtkDisplacedDetectorImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ DisplacedDetectorImageFilter<TInputImage, TOutputImage>::GenerateOutputInformati
<< " Corner inf=" << m_InferiorCorner << " and corner sup=" << m_SuperiorCorner);
}
// Case 2: Not displaced, or explicit request not to pad: default outputLargestPossibleRegion is fine
else if ((fabs(m_InferiorCorner + m_SuperiorCorner) < 0.1 * fabs(m_SuperiorCorner - m_InferiorCorner)) ||
else if ((itk::Math::abs(m_InferiorCorner + m_SuperiorCorner) < 0.1 * itk::Math::abs(m_SuperiorCorner - m_InferiorCorner)) ||
!m_PadOnTruncatedSide)
{
this->SetInPlace(true);
Expand Down Expand Up @@ -204,7 +204,7 @@ DisplacedDetectorImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerate
itk::ImageRegionConstIterator<InputImageType> itIn(this->GetInput(), overlapRegion);

// Not displaced, nothing to do
if ((fabs(m_InferiorCorner + m_SuperiorCorner) < 0.1 * fabs(m_SuperiorCorner - m_InferiorCorner)) || m_Disable)
if ((itk::Math::abs(m_InferiorCorner + m_SuperiorCorner) < 0.1 * itk::Math::abs(m_SuperiorCorner - m_InferiorCorner)) || m_Disable)
{
// If not in place, copy is required
if (this->GetInput() != this->GetOutput())
Expand Down
4 changes: 2 additions & 2 deletions include/rtkFDKBackProjectionImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ FDKBackProjectionImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerate
matrix /= perspFactor;

// Optimized version
if (fabs(matrix[1][0]) < 1e-10 && fabs(matrix[2][0]) < 1e-10)
if (itk::Math::abs(matrix[1][0]) < 1e-10 && itk::Math::abs(matrix[2][0]) < 1e-10)
{
OptimizedBackprojectionX(outputRegionForThread, matrix, projection);
continue;
}
if (fabs(matrix[1][1]) < 1e-10 && fabs(matrix[2][1]) < 1e-10)
if (itk::Math::abs(matrix[1][1]) < 1e-10 && itk::Math::abs(matrix[2][1]) < 1e-10)
{
OptimizedBackprojectionY(outputRegionForThread, matrix, projection);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ FourDReconstructionConjugateGradientOperator<VolumeSeriesType, ProjectionStackTy
{
for (int proj = FirstProj + 1; proj < FirstProj + NumberProjs; proj++)
{
if (fabs(m_Signal[proj] - m_Signal[proj - 1]) > 1e-4)
if (itk::Math::abs(m_Signal[proj] - m_Signal[proj - 1]) > 1e-4)
{
// Compute the number of projections in the current slab
sizeOfSlabs.push_back(proj - firstProjectionInSlabs[firstProjectionInSlabs.size() - 1]);
Expand Down
6 changes: 3 additions & 3 deletions include/rtkJosephBackProjectionImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ JosephBackProjectionImageFilter<TInputImage,
bool isNewRay = true;
if (fs == ns) // If the voxel is a corner, we can skip most steps
{
attenuationRay += BilinearInterpolationOnBorders(std::abs(fp[mainDir] - np[mainDir]),
attenuationRay += BilinearInterpolationOnBorders(itk::Math::abs(fp[mainDir] - np[mainDir]),
pxiyi,
pxsyi,
pxiys,
Expand All @@ -226,7 +226,7 @@ JosephBackProjectionImageFilter<TInputImage,
const typename TInputImage::PixelType & rayValue =
m_SumAlongRay(itIn->Value(), attenuationRay, stepMM, isNewRay);
BilinearSplatOnBorders(rayValue,
std::abs(fp[mainDir] - np[mainDir]),
itk::Math::abs(fp[mainDir] - np[mainDir]),
stepMM.GetNorm(),
pxiyi,
pxsyi,
Expand Down Expand Up @@ -275,7 +275,7 @@ JosephBackProjectionImageFilter<TInputImage,
currenty += stepy;

// Middle steps
for (int i{ 0 }; i < std::abs(fs - ns) - 1; ++i)
for (int i{ 0 }; i < itk::Math::abs(fs - ns) - 1; ++i)
{
attenuationRay += BilinearInterpolation(1., pxiyi, pxsyi, pxiys, pxsys, currentx, currenty, offsetx, offsety);

Expand Down
4 changes: 2 additions & 2 deletions include/rtkJosephForwardProjectionImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ JosephForwardProjectionImageFilter<TInputImage,
if (fs == ns) // If the voxel is a corner, we can skip most steps
{
volumeValue = BilinearInterpolationOnBorders(threadId,
std::abs(fp[mainDir] - np[mainDir]),
itk::Math::abs(fp[mainDir] - np[mainDir]),
pxiyi,
pxsyi,
pxiys,
Expand Down Expand Up @@ -232,7 +232,7 @@ JosephForwardProjectionImageFilter<TInputImage,
currenty += stepy;

// Middle steps
for (int i{ 0 }; i < std::abs(fs - ns) - 1; ++i)
for (int i{ 0 }; i < itk::Math::abs(fs - ns) - 1; ++i)
{
volumeValue =
BilinearInterpolation(threadId, 1., pxiyi, pxsyi, pxiys, pxsys, currentx, currenty, offsetx, offsety);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ MotionCompensatedFourDReconstructionConjugateGradientOperator<VolumeSeriesType,
{
for (int proj = FirstProj + 1; proj < FirstProj + NumberProjs; proj++)
{
if (fabs(m_Signal[proj] - m_Signal[proj - 1]) > 1e-4)
if (itk::Math::abs(m_Signal[proj] - m_Signal[proj - 1]) > 1e-4)
{
// Compute the number of projections in the current slab
sizeOfSlabs.push_back(proj - firstProjectionInSlabs[firstProjectionInSlabs.size() - 1]);
Expand Down
2 changes: 1 addition & 1 deletion include/rtkPhaseGatingImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PhaseGatingImageFilter<ProjectionStackType>::ComputeWeights()
// Compute the gating weights
for (float m_Phase : m_Phases)
{
distance = std::min(fabs(m_GatingWindowCenter - 1 - m_Phase), fabs(m_GatingWindowCenter - m_Phase));
distance = std::min(itk::Math::abs(m_GatingWindowCenter - 1 - m_Phase), itk::Math::abs(m_GatingWindowCenter - m_Phase));
distance = std::min(distance, itk::Math::abs(m_GatingWindowCenter + 1.f - m_Phase));

switch (m_GatingWindowShape)
Expand Down
2 changes: 1 addition & 1 deletion include/rtkProjectionStackToFourDImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ ProjectionStackToFourDImageFilter<VolumeSeriesType, ProjectionStackType, TFFTPre
{
for (int proj = FirstProj + 1; proj < FirstProj + NumberProjs; proj++)
{
if (fabs(m_Signal[proj] - m_Signal[proj - 1]) > 1e-4)
if (itk::Math::abs(m_Signal[proj] - m_Signal[proj - 1]) > 1e-4)
{
// Compute the number of projections in the current slab
sizeOfSlabs.push_back(proj - firstProjectionInSlabs[firstProjectionInSlabs.size() - 1]);
Expand Down
4 changes: 2 additions & 2 deletions include/rtkScatterGlareCorrectionImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ ScatterGlareCorrectionImageFilter<TInputImage, TOutputImage, TFFTPrecision>::Upd
while (!itK.IsAtEnd())
{
idx = itK.GetIndex();
double xx = halfXSz - fabs(halfXSz - idx[0]); // Distance to nearest x border
double yy = halfYSz - fabs(halfYSz - idx[1]); // Distance to nearest y border
double xx = halfXSz - itk::Math::abs(halfXSz - idx[0]); // Distance to nearest x border
double yy = halfYSz - itk::Math::abs(halfYSz - idx[1]); // Distance to nearest y border
double rr2 = (xx * xx + yy * yy);
g = (a3 * dx * dy / (2. * itk::Math::pi * b3sq)) / std::pow((1. + rr2 / b3sq), 1.5);
itK.Set(g);
Expand Down
2 changes: 1 addition & 1 deletion src/rtkConditionalMedianImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rtk::ConditionalMedianImageFilter<itk::VectorImage<float, 3>>::DynamicThreadedGe
std::nth_element(pixels[mat].begin(), pixels[mat].begin() + pixels[mat].size() / 2, pixels[mat].end());

// If the pixel value is too far from the median, replace it by the median
if (fabs(pixels[mat][pixels[mat].size() / 2] - nIt.GetCenterPixel()[mat]) > (m_ThresholdMultiplier * stdev))
if (itk::Math::abs(pixels[mat][pixels[mat].size() / 2] - nIt.GetCenterPixel()[mat]) > (m_ThresholdMultiplier * stdev))
vlv[mat] = pixels[mat][pixels[mat].size() / 2];
else // Otherwise, leave it as is
vlv[mat] = nIt.GetCenterPixel()[mat];
Expand Down
4 changes: 2 additions & 2 deletions src/rtkCudaDisplacedDetectorImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ CudaDisplacedDetectorImageFilter ::GPUGenerateData()
outBuffer += this->GetOutput()->ComputeOffset(this->GetOutput()->GetRequestedRegion().GetIndex());

// nothing to do
if ((fabs(this->GetInferiorCorner() + this->GetSuperiorCorner()) <
0.1 * fabs(this->GetSuperiorCorner() - this->GetInferiorCorner())) ||
if ((itk::Math::abs(this->GetInferiorCorner() + this->GetSuperiorCorner()) <
0.1 * itk::Math::abs(this->GetSuperiorCorner() - this->GetInferiorCorner())) ||
this->GetDisable())
{
if (outBuffer != inBuffer)
Expand Down
4 changes: 2 additions & 2 deletions src/rtkDigisensGeometryReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ rtk::DigisensGeometryReader ::GenerateData()
}

// Source / Detector / Center distances
double sdd = fabs(sourcePosition[2] - detectorPosition[2]);
double sid = fabs(sourcePosition[2] - rotationCenter[2]);
double sdd = itk::Math::abs(sourcePosition[2] - detectorPosition[2]);
double sid = itk::Math::abs(sourcePosition[2] - rotationCenter[2]);

// Scaling
using MetaDataIntegerType = itk::MetaDataObject<int>;
Expand Down
2 changes: 1 addition & 1 deletion src/rtkForbildPhantomFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ ForbildPhantomFileReader::ComputeRotationMatrixBetweenVectors(const VectorType &
RotationMatrixType r;
r.SetIdentity();
ScalarType c = s * d;
if (fabs(c) - 1. == itk::NumericTraits<ScalarType>::ZeroValue())
if (itk::Math::abs(c) - 1. == itk::NumericTraits<ScalarType>::ZeroValue())
{
return r;
}
Expand Down
6 changes: 3 additions & 3 deletions src/rtkThreeDCircularProjectionGeometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ rtk::ThreeDCircularProjectionGeometry::AddProjection(const PointType & sourcePo
const PointType & S = sourcePosition; // source pos
const PointType & R = detectorPosition; // detector pos

if (fabs(r * c) > 1e-6) // non-orthogonal row/column vectors
if (itk::Math::abs(r * c) > 1e-6) // non-orthogonal row/column vectors
return false;

// Euler angles (ZXY convention) from detector orientation in IEC-based WCS:
Expand Down Expand Up @@ -637,7 +637,7 @@ rtk::ThreeDCircularProjectionGeometry::VerifyAngles(const double outOfP

for (int i = 0; i < 3; i++) // check whether matrices match
for (int j = 0; j < 3; j++)
if (fabs(rm[i][j] - m[i][j]) > EPSILON)
if (itk::Math::abs(rm[i][j] - m[i][j]) > EPSILON)
return false;

return true;
Expand All @@ -652,7 +652,7 @@ rtk::ThreeDCircularProjectionGeometry::FixAngles(double & outOfPlan
const Matrix3x3Type & rm = referenceMatrix; // shortcut
const double EPSILON = 1e-6; // internal tolerance for comparison

if (fabs(fabs(rm[2][1]) - 1.) > EPSILON)
if (itk::Math::abs(fabs(rm[2][1]) - 1.) > EPSILON)
{
double oa = NAN, ga = NAN, ia = NAN;

Expand Down
2 changes: 1 addition & 1 deletion src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ThreeDCircularProjectionGeometryXMLFileReader::EndElement(const char * name)
{
// Tolerance can not be vcl_numeric_limits<double>::epsilon(), too strict
// 0.001 is a random choice to catch "large" inconsistencies
if (fabs(m_Matrix[i][j] - m_OutputObject->GetMatrices().back()[i][j]) > 0.001)
if (itk::Math::abs(m_Matrix[i][j] - m_OutputObject->GetMatrices().back()[i][j]) > 0.001)
{
itkGenericExceptionMacro(<< "Matrix and parameters are not consistent." << std::endl
<< "Read matrix from geometry file: " << std::endl
Expand Down
28 changes: 14 additions & 14 deletions test/rtkTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ CheckGeometries(const rtk::ThreeDCircularProjectionGeometry * g1, const rtk::Thr
std::cerr << "Unequal number of projections in the two geometries" << std::endl;
exit(EXIT_FAILURE);
}
if (e < std::fabs(g1->GetRadiusCylindricalDetector() - g2->GetRadiusCylindricalDetector()))
if (e < itk::Math::abs(g1->GetRadiusCylindricalDetector() - g2->GetRadiusCylindricalDetector()))
{
std::cerr << "Geometries don't have the same cylindrical detector radius" << std::endl;
exit(EXIT_FAILURE);
Expand All @@ -312,21 +312,21 @@ CheckGeometries(const rtk::ThreeDCircularProjectionGeometry * g1, const rtk::Thr
{
// std::cout << g1->GetGantryAngles()[i] << " " << g2->GetGantryAngles()[i] << std::endl;
if (e < rtk::ThreeDCircularProjectionGeometry::ConvertAngleBetween0And2PIRadians(
std::fabs(g1->GetGantryAngles()[i] - g2->GetGantryAngles()[i])) ||
itk::Math::abs(g1->GetGantryAngles()[i] - g2->GetGantryAngles()[i])) ||
e < rtk::ThreeDCircularProjectionGeometry::ConvertAngleBetween0And2PIRadians(
std::fabs(g1->GetOutOfPlaneAngles()[i] - g2->GetOutOfPlaneAngles()[i])) ||
itk::Math::abs(g1->GetOutOfPlaneAngles()[i] - g2->GetOutOfPlaneAngles()[i])) ||
e < rtk::ThreeDCircularProjectionGeometry::ConvertAngleBetween0And2PIRadians(
std::fabs(g1->GetInPlaneAngles()[i] - g2->GetInPlaneAngles()[i])) ||
e < std::fabs(g1->GetSourceToIsocenterDistances()[i] - g2->GetSourceToIsocenterDistances()[i]) ||
e < std::fabs(g1->GetSourceOffsetsX()[i] - g2->GetSourceOffsetsX()[i]) ||
e < std::fabs(g1->GetSourceOffsetsY()[i] - g2->GetSourceOffsetsY()[i]) ||
e < std::fabs(g1->GetSourceToDetectorDistances()[i] - g2->GetSourceToDetectorDistances()[i]) ||
e < std::fabs(g1->GetProjectionOffsetsX()[i] - g2->GetProjectionOffsetsX()[i]) ||
e < std::fabs(g1->GetProjectionOffsetsY()[i] - g2->GetProjectionOffsetsY()[i]) ||
e < std::fabs(g1->GetCollimationUInf()[i] - g2->GetCollimationUInf()[i]) ||
e < std::fabs(g1->GetCollimationVInf()[i] - g2->GetCollimationVInf()[i]) ||
e < std::fabs(g1->GetCollimationUSup()[i] - g2->GetCollimationUSup()[i]) ||
e < std::fabs(g1->GetCollimationVSup()[i] - g2->GetCollimationVSup()[i]))
itk::Math::abs(g1->GetInPlaneAngles()[i] - g2->GetInPlaneAngles()[i])) ||
e < itk::Math::abs(g1->GetSourceToIsocenterDistances()[i] - g2->GetSourceToIsocenterDistances()[i]) ||
e < itk::Math::abs(g1->GetSourceOffsetsX()[i] - g2->GetSourceOffsetsX()[i]) ||
e < itk::Math::abs(g1->GetSourceOffsetsY()[i] - g2->GetSourceOffsetsY()[i]) ||
e < itk::Math::abs(g1->GetSourceToDetectorDistances()[i] - g2->GetSourceToDetectorDistances()[i]) ||
e < itk::Math::abs(g1->GetProjectionOffsetsX()[i] - g2->GetProjectionOffsetsX()[i]) ||
e < itk::Math::abs(g1->GetProjectionOffsetsY()[i] - g2->GetProjectionOffsetsY()[i]) ||
e < itk::Math::abs(g1->GetCollimationUInf()[i] - g2->GetCollimationUInf()[i]) ||
e < itk::Math::abs(g1->GetCollimationVInf()[i] - g2->GetCollimationVInf()[i]) ||
e < itk::Math::abs(g1->GetCollimationUSup()[i] - g2->GetCollimationUSup()[i]) ||
e < itk::Math::abs(g1->GetCollimationVSup()[i] - g2->GetCollimationVSup()[i]))
{
std::cerr << "Geometry of projection #" << i << " is unvalid." << std::endl;
exit(EXIT_FAILURE);
Expand Down
4 changes: 2 additions & 2 deletions test/rtkTestReg23ProjectionGeometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ main(int argc, char * argv[])
{
for (std::size_t i = 0; i < referenceMarkerProjections.size(); ++i)
{
if (fabs(referenceMarkerProjections[i][0] - rtkMarkerProjections[i][0]) > EPSILON ||
fabs(referenceMarkerProjections[i][1] - rtkMarkerProjections[i][1]) > EPSILON)
if (itk::Math::abs(referenceMarkerProjections[i][0] - rtkMarkerProjections[i][0]) > EPSILON ||
itk::Math::abs(referenceMarkerProjections[i][1] - rtkMarkerProjections[i][1]) > EPSILON)
{
VERBOSE(<< "\nAngle-combination out-of-plane=" << anglesList[i][0] << ", gantry=" << anglesList[i][1]
<< ", in-plane=" << anglesList[i][2] << " failed:\n")
Expand Down
2 changes: 1 addition & 1 deletion test/rtkcroptest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ main(int, char **)
ImageType::IndexType index;
index.Fill(2);

if (fabs(crop->GetOutput()->GetPixel(index) - 12.3) > 0.0001)
if (itk::Math::abs(crop->GetOutput()->GetPixel(index) - 12.3) > 0.0001)
{
std::cout << "Output should be 12.3. Value Computed = " << crop->GetOutput()->GetPixel(index) << std::endl;
return EXIT_FAILURE;
Expand Down
6 changes: 3 additions & 3 deletions test/rtkrampfiltertest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ main(int, char **)
index[2] = 26;

float value = 0.132652;
if (fabs(rampFilter->GetOutput()->GetPixel(index) - value) > 0.000001)
if (itk::Math::abs(rampFilter->GetOutput()->GetPixel(index) - value) > 0.000001)
{
std::cout << "Output value #0 should be " << value << " found " << rampFilter->GetOutput()->GetPixel(index)
<< " instead." << std::endl;
Expand All @@ -72,7 +72,7 @@ main(int, char **)
rampFilter->SetHannCutFrequency(0.8);
rampFilter->Update();
value = 0.149724;
if (fabs(rampFilter->GetOutput()->GetPixel(index) - value) > 0.000001)
if (itk::Math::abs(rampFilter->GetOutput()->GetPixel(index) - value) > 0.000001)
{
std::cout << "Output value #1 should be " << value << " found " << rampFilter->GetOutput()->GetPixel(index)
<< " instead." << std::endl;
Expand All @@ -83,7 +83,7 @@ main(int, char **)
rampFilter->SetHannCutFrequencyY(0.1);
rampFilter->Update();
value = 0.150181;
if (fabs(rampFilter->GetOutput()->GetPixel(index) - value) > 0.000001)
if (itk::Math::abs(rampFilter->GetOutput()->GetPixel(index) - value) > 0.000001)
{
std::cout << "Output value #2 should be " << value << " found " << rampFilter->GetOutput()->GetPixel(index)
<< " instead." << std::endl;
Expand Down

0 comments on commit 05f3ad2

Please sign in to comment.