Skip to content

Commit

Permalink
COMP: Fix TransformPhysicalPointToContinuousIndex nodiscard warnings
Browse files Browse the repository at this point in the history
Did find code like this:

    ContinuousIndexType index;
    image->TransformPhysicalPointToContinuousIndex(point, index);

And replaced it by something like:

    const ContinuousIndexType index =
      image->template TransformPhysicalPointToContinuousIndex<ContinuousIndexValueType>(point);

When the `bool` return value is ignored, it is preferable (for performance
reasons) to call the overload that just returns the continuous index, preventing
`[[nodiscard]]` compile warnings.

These cases are found in Visual Studio, using the following regular expression:
`  [^ ]+->TransformPhysicalPointToContinuousIndex\(.*,`
  • Loading branch information
N-Dekker authored and dzenanz committed Apr 6, 2023
1 parent 49ece7f commit 7cda5ba
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Expand Up @@ -114,7 +114,6 @@ VectorResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>
PointType inputPoint; // Coordinates of current input pixel

using ContinuousIndexType = ContinuousIndex<TInterpolatorPrecisionType, ImageDimension>;
ContinuousIndexType inputIndex;

// Doc says this only works for VectorImage, but Image implementation says otherwise...
const unsigned int numberOfComponents = this->GetInput()->GetNumberOfComponentsPerPixel();
Expand All @@ -131,7 +130,8 @@ VectorResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>

// Compute corresponding input pixel position
inputPoint = m_Transform->TransformPoint(outputPoint);
inputPtr->TransformPhysicalPointToContinuousIndex(inputPoint, inputIndex);
const ContinuousIndexType inputIndex =
inputPtr->template TransformPhysicalPointToContinuousIndex<TInterpolatorPrecisionType>(inputPoint);

// Evaluate input at right position and copy to the output
if (m_Interpolator->IsInsideBuffer(inputIndex))
Expand Down
Expand Up @@ -180,9 +180,9 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolateImageFunction : public InterpolateIm
CovariantVectorType
EvaluateDerivative(const PointType & point) const
{
ContinuousIndexType index;
const ContinuousIndexType index =
this->GetInputImage()->template TransformPhysicalPointToContinuousIndex<TCoordRep>(point);

this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
// No thread info passed in, so call method that doesn't need thread ID.
return (this->EvaluateDerivativeAtContinuousIndex(index));
}
Expand Down Expand Up @@ -222,9 +222,8 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolateImageFunction : public InterpolateIm
void
EvaluateValueAndDerivative(const PointType & point, OutputType & value, CovariantVectorType & deriv) const
{
ContinuousIndexType index;

this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
const ContinuousIndexType index =
this->GetInputImage()->template TransformPhysicalPointToContinuousIndex<TCoordRep>(point);

// No thread info passed in, so call method that doesn't need thread ID.
this->EvaluateValueAndDerivativeAtContinuousIndex(index, value, deriv);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/ImageFunction/include/itkImageFunction.h
Expand Up @@ -191,7 +191,7 @@ class ITK_TEMPLATE_EXPORT ImageFunction : public FunctionBase<Point<TCoordRep, T
void
ConvertPointToContinuousIndex(const PointType & point, ContinuousIndexType & cindex) const
{
m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
cindex = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordRep>(point);
}

/** Convert continuous index to nearest index. */
Expand Down
Expand Up @@ -138,9 +138,7 @@ itkDiscreteGaussianDerivativeImageFunctionTestND(int argc, char * argv[])
out.GoToBegin();

using PointType = typename GaussianDerivativeImageFunctionType::PointType;
PointType point;
using ContinuousIndexType = typename GaussianDerivativeImageFunctionType::ContinuousIndexType;
ContinuousIndexType cindex;
PointType point;
const unsigned long nop = inputImage->GetRequestedRegion().GetNumberOfPixels();
unsigned long pixelNumber = 0;
while (!it.IsAtEnd())
Expand All @@ -157,8 +155,12 @@ itkDiscreteGaussianDerivativeImageFunctionTestND(int argc, char * argv[])
}
else
{
using ContinuousIndexType = typename GaussianDerivativeImageFunctionType::ContinuousIndexType;
using ContinuousIndexValueType = typename ContinuousIndexType::ValueType;

inputImage->TransformIndexToPhysicalPoint(it.GetIndex(), point);
inputImage->TransformPhysicalPointToContinuousIndex(point, cindex);
const ContinuousIndexType cindex =
inputImage->template TransformPhysicalPointToContinuousIndex<ContinuousIndexValueType>(point);
out.Set(function->EvaluateAtContinuousIndex(cindex));
}
++it;
Expand Down
Expand Up @@ -139,9 +139,7 @@ itkDiscreteGradientMagnitudeGaussianImageFunctionTestND(int argc, char * argv[])
out.GoToBegin();

using PointType = typename DiscreteGradientMagnitudeGaussianFunctionType::PointType;
PointType point;
using ContinuousIndexType = typename DiscreteGradientMagnitudeGaussianFunctionType::ContinuousIndexType;
ContinuousIndexType cindex;
PointType point;
const unsigned long nop = inputImage->GetRequestedRegion().GetNumberOfPixels();
unsigned long pixelNumber = 0;
while (!it.IsAtEnd())
Expand All @@ -158,8 +156,12 @@ itkDiscreteGradientMagnitudeGaussianImageFunctionTestND(int argc, char * argv[])
}
else
{
using ContinuousIndexType = typename DiscreteGradientMagnitudeGaussianFunctionType::ContinuousIndexType;
using ContinuousValueIndexType = typename ContinuousIndexType::ContinuousIndexType;

inputImage->TransformIndexToPhysicalPoint(it.GetIndex(), point);
inputImage->TransformPhysicalPointToContinuousIndex(point, cindex);
const ContinuousIndexType cindex =
inputImage->TransformPhysicalPointToContinuousIndex<ContinuousValueIndexType>(point);
out.Set(function->EvaluateAtContinuousIndex(cindex));
}
++it;
Expand Down
Expand Up @@ -132,9 +132,7 @@ itkDiscreteHessianGaussianImageFunctionTestND(int argc, char * argv[])
IteratorType outIter(output, output->GetRequestedRegion());

using PointType = typename HessianGaussianImageFunctionType::PointType;
PointType point;
using ContinuousIndexType = typename HessianGaussianImageFunctionType::ContinuousIndexType;
ContinuousIndexType cindex;
PointType point;
const unsigned long nop = reader->GetOutput()->GetRequestedRegion().GetNumberOfPixels();
unsigned long pixelNumber = 0;
while (!it.IsAtEnd())
Expand All @@ -150,8 +148,12 @@ itkDiscreteHessianGaussianImageFunctionTestND(int argc, char * argv[])
}
else
{
using ContinuousIndexType = typename HessianGaussianImageFunctionType::ContinuousIndexType;
using ContinuousIndexValueType = typename ContinuousIndexType::ValueType;

reader->GetOutput()->TransformIndexToPhysicalPoint(it.GetIndex(), point);
reader->GetOutput()->TransformPhysicalPointToContinuousIndex(point, cindex);
const ContinuousIndexType cindex =
reader->GetOutput()->TransformPhysicalPointToContinuousIndex<ContinuousIndexValueType>(point);
hessian = function->EvaluateAtContinuousIndex(cindex);
}

Expand Down

0 comments on commit 7cda5ba

Please sign in to comment.