From 7071061dc01a1ca36df9b899fd093f5aeb7702de Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 9 Apr 2023 10:39:49 +0200 Subject: [PATCH 1/3] COMP: Add `template` to TransformPhysicalPointToContinuousIndex in tests Added missing `template` keywords to TransformPhysicalPointToContinuousIndex calls in Nonunit/Review tests. Addressed compile errors from Ubuntu-22.04-gcc11.2-TBB-Debug saying: > error: expected primary-expression before '>' token These compile errors were introduced by pull request https://github.com/InsightSoftwareConsortium/ITK/pull/4000 commit 7cda5badd0ae7802103421b6625e46bc956f6cb9 "COMP: Fix TransformPhysicalPointToContinuousIndex `nodiscard` warnings" --- .../itkDiscreteGradientMagnitudeGaussianImageFunctionTest.cxx | 2 +- .../Review/test/itkDiscreteHessianGaussianImageFunctionTest.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Nonunit/Review/test/itkDiscreteGradientMagnitudeGaussianImageFunctionTest.cxx b/Modules/Nonunit/Review/test/itkDiscreteGradientMagnitudeGaussianImageFunctionTest.cxx index 0361e893ef5..727cf3ba493 100644 --- a/Modules/Nonunit/Review/test/itkDiscreteGradientMagnitudeGaussianImageFunctionTest.cxx +++ b/Modules/Nonunit/Review/test/itkDiscreteGradientMagnitudeGaussianImageFunctionTest.cxx @@ -161,7 +161,7 @@ itkDiscreteGradientMagnitudeGaussianImageFunctionTestND(int argc, char * argv[]) inputImage->TransformIndexToPhysicalPoint(it.GetIndex(), point); const ContinuousIndexType cindex = - inputImage->TransformPhysicalPointToContinuousIndex(point); + inputImage->template TransformPhysicalPointToContinuousIndex(point); out.Set(function->EvaluateAtContinuousIndex(cindex)); } ++it; diff --git a/Modules/Nonunit/Review/test/itkDiscreteHessianGaussianImageFunctionTest.cxx b/Modules/Nonunit/Review/test/itkDiscreteHessianGaussianImageFunctionTest.cxx index 994d833381a..0cb2d19cf9d 100644 --- a/Modules/Nonunit/Review/test/itkDiscreteHessianGaussianImageFunctionTest.cxx +++ b/Modules/Nonunit/Review/test/itkDiscreteHessianGaussianImageFunctionTest.cxx @@ -153,7 +153,7 @@ itkDiscreteHessianGaussianImageFunctionTestND(int argc, char * argv[]) reader->GetOutput()->TransformIndexToPhysicalPoint(it.GetIndex(), point); const ContinuousIndexType cindex = - reader->GetOutput()->TransformPhysicalPointToContinuousIndex(point); + reader->GetOutput()->template TransformPhysicalPointToContinuousIndex(point); hessian = function->EvaluateAtContinuousIndex(cindex); } From 3ce72e2bf47ec594555c6296a911fa151085a835 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 6 Apr 2023 19:38:20 +0200 Subject: [PATCH 2/3] ENH: Simpler `TransformPhysicalPointToContinuousIndex(point)` overloads Added non-template overloads, which allow the user to write: index = image->TransformPhysicalPointToContinuousIndex(point); Instead of calling one of the overload that was added with ITK 5.0, for example: index = image->template TransformPhysicalPointToContinuousIndex(point); --- Modules/Core/Common/include/itkImageBase.h | 13 +++++++++++++ .../itkPhasedArray3DSpecialCoordinatesImage.h | 12 ++++++++++++ .../Core/ImageAdaptors/include/itkImageAdaptor.h | 12 ++++++++++++ 3 files changed, 37 insertions(+) diff --git a/Modules/Core/Common/include/itkImageBase.h b/Modules/Core/Common/include/itkImageBase.h index 231296a722c..35b35019558 100644 --- a/Modules/Core/Common/include/itkImageBase.h +++ b/Modules/Core/Common/include/itkImageBase.h @@ -509,6 +509,19 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject return index; } + + /** \brief Returns the continuous index from a physical point + * \note This specific overload is easier to use, because it does not have template arguments. It just uses + * `itk::SpacePrecisionType`, both for the coordinates of the point and the index values. + * + * \sa Transform */ + [[nodiscard]] ContinuousIndex + TransformPhysicalPointToContinuousIndex(const PointType & point) const + { + return TransformPhysicalPointToContinuousIndex(point); + } + + /** \brief Get the continuous index from a physical point * * Returns true if the resulting index is within the image, false otherwise. diff --git a/Modules/Core/Common/include/itkPhasedArray3DSpecialCoordinatesImage.h b/Modules/Core/Common/include/itkPhasedArray3DSpecialCoordinatesImage.h index b2845ac55a1..d0fc67382e0 100644 --- a/Modules/Core/Common/include/itkPhasedArray3DSpecialCoordinatesImage.h +++ b/Modules/Core/Common/include/itkPhasedArray3DSpecialCoordinatesImage.h @@ -208,6 +208,18 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC return index; } + /** \brief Returns the continuous index from a physical point + * \note This specific overload is easier to use, because it does not have template arguments. It just uses + * `itk::SpacePrecisionType`, both for the coordinates of the point and the index values. + * + * \sa Transform */ + [[nodiscard]] ContinuousIndex + TransformPhysicalPointToContinuousIndex(const PointType & point) const + { + return TransformPhysicalPointToContinuousIndex(point); + } + + /** \brief Get the continuous index from a physical point * * Returns true if the resulting index is within the image, false otherwise. diff --git a/Modules/Core/ImageAdaptors/include/itkImageAdaptor.h b/Modules/Core/ImageAdaptors/include/itkImageAdaptor.h index 789d332cce6..ee48fc86406 100644 --- a/Modules/Core/ImageAdaptors/include/itkImageAdaptor.h +++ b/Modules/Core/ImageAdaptors/include/itkImageAdaptor.h @@ -389,6 +389,18 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBasetemplate TransformPhysicalPointToContinuousIndex(point); } + /** \brief Returns the continuous index from a physical point + * \note This specific overload is easier to use, because it does not have template arguments. It just uses + * `itk::SpacePrecisionType`, both for the coordinates of the point and the index values. + * + * \sa Transform */ + [[nodiscard]] ContinuousIndex + TransformPhysicalPointToContinuousIndex(const PointType & point) const + { + return m_Image->TransformPhysicalPointToContinuousIndex(point); + } + + /** \brief Get the continuous index from a physical point * * Returns true if the resulting index is within the image, false otherwise. From 983bf81bcfe99492c9c94d1cb70d3763bd824361 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 9 Apr 2023 13:12:08 +0200 Subject: [PATCH 3/3] STYLE: Call simpler TransformPhysicalPointToContinuousIndex overloads Did replace `template TransformPhysicalPointToContinuousIndex<.+>` calls with `TransformPhysicalPointToContinuousIndex`, using regular expressions. Only included `TransformPhysicalPointToContinuousIndex` calls for which both template parameters (for `TIndexRep` and `TCoordRep`) were equal to `itk::SpacePrecisionType`. Excluded unit tests from tkImageBaseGTest.cxx and itkImageAdaptorGTest.cxx as they intentionally called the member function _template_. --- Modules/Core/Common/include/itkImageAlgorithm.hxx | 3 +-- .../Core/Mesh/include/itkTriangleMeshToBinaryImageFilter.hxx | 3 +-- Modules/Core/Transform/include/itkBSplineBaseTransform.hxx | 3 +-- Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx | 5 ++--- .../Registration/Common/include/itkImageToImageMetric.hxx | 2 +- .../Common/include/itkKappaStatisticImageToImageMetric.hxx | 2 +- ...tkMeanReciprocalSquareDifferencePointSetToImageMetric.hxx | 4 ++-- .../Common/include/itkMeanSquaresPointSetToImageMetric.hxx | 4 ++-- .../include/itkNormalizedCorrelationImageToImageMetric.hxx | 4 ++-- .../itkNormalizedCorrelationPointSetToImageMetric.hxx | 4 ++-- .../Segmentation/SuperPixel/include/itkSLICImageFilter.hxx | 3 +-- 11 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Modules/Core/Common/include/itkImageAlgorithm.hxx b/Modules/Core/Common/include/itkImageAlgorithm.hxx index 9afddda4db0..3aead3a2b20 100644 --- a/Modules/Core/Common/include/itkImageAlgorithm.hxx +++ b/Modules/Core/Common/include/itkImageAlgorithm.hxx @@ -260,8 +260,7 @@ ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType & outputPoint[d] = inputPoint[d]; } } - outputCorners[count] = - outputImage->template TransformPhysicalPointToContinuousIndex(outputPoint); + outputCorners[count] = outputImage->TransformPhysicalPointToContinuousIndex(outputPoint); } // Compute a rectangular region from the vector of corner indexes diff --git a/Modules/Core/Mesh/include/itkTriangleMeshToBinaryImageFilter.hxx b/Modules/Core/Mesh/include/itkTriangleMeshToBinaryImageFilter.hxx index 1a997bec26c..848709e265c 100644 --- a/Modules/Core/Mesh/include/itkTriangleMeshToBinaryImageFilter.hxx +++ b/Modules/Core/Mesh/include/itkTriangleMeshToBinaryImageFilter.hxx @@ -347,8 +347,7 @@ TriangleMeshToBinaryImageFilter::RasterizeTriangles() { PointType p = points.Value(); // the index value type must match the point value type - const ContinuousIndex ind = - OutputImage->template TransformPhysicalPointToContinuousIndex(p); + const ContinuousIndex ind = OutputImage->TransformPhysicalPointToContinuousIndex(p); NewPoints->InsertElement(pointId++, ind); ++points; diff --git a/Modules/Core/Transform/include/itkBSplineBaseTransform.hxx b/Modules/Core/Transform/include/itkBSplineBaseTransform.hxx index c553079c6dc..e5b2a93328c 100644 --- a/Modules/Core/Transform/include/itkBSplineBaseTransform.hxx +++ b/Modules/Core/Transform/include/itkBSplineBaseTransform.hxx @@ -233,8 +233,7 @@ BSplineBaseTransform:: WeightsType & weights, ParameterIndexArrayType & indexes) const { - ContinuousIndexType index = - this->m_CoefficientImages[0]->template TransformPhysicalPointToContinuousIndex(point); + ContinuousIndexType index = this->m_CoefficientImages[0]->TransformPhysicalPointToContinuousIndex(point); // NOTE: if the support region does not lie totally within the grid // we assume zero displacement and return the input point diff --git a/Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx b/Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx index f28a6043c38..35720e0da2a 100644 --- a/Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx +++ b/Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx @@ -183,9 +183,8 @@ WarpImageFilter::EvaluateDisplace const DisplacementFieldType * fieldPtr, DisplacementType & output) { - const ContinuousIndex index = - fieldPtr->template TransformPhysicalPointToContinuousIndex(point); - unsigned int dim; // index over dimension + const ContinuousIndex index = fieldPtr->TransformPhysicalPointToContinuousIndex(point); + unsigned int dim; // index over dimension /** * Compute base index = closest index below point * Compute distance from point to base index diff --git a/Modules/Registration/Common/include/itkImageToImageMetric.hxx b/Modules/Registration/Common/include/itkImageToImageMetric.hxx index e98a210f145..36a6fa7acc5 100644 --- a/Modules/Registration/Common/include/itkImageToImageMetric.hxx +++ b/Modules/Registration/Common/include/itkImageToImageMetric.hxx @@ -990,7 +990,7 @@ ImageToImageMetric::ComputeImageDerivatives(const Mov if (m_ComputeGradient) { const ContinuousIndex tempIndex = - m_MovingImage->template TransformPhysicalPointToContinuousIndex(mappedPoint); + m_MovingImage->TransformPhysicalPointToContinuousIndex(mappedPoint); MovingImageIndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); gradient = m_GradientImage->GetPixel(mappedIndex); diff --git a/Modules/Registration/Common/include/itkKappaStatisticImageToImageMetric.hxx b/Modules/Registration/Common/include/itkKappaStatisticImageToImageMetric.hxx index eb1621c67ba..6b7a37afad7 100644 --- a/Modules/Registration/Common/include/itkKappaStatisticImageToImageMetric.hxx +++ b/Modules/Registration/Common/include/itkKappaStatisticImageToImageMetric.hxx @@ -249,7 +249,7 @@ KappaStatisticImageToImageMetric::GetDerivative(const using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); diff --git a/Modules/Registration/Common/include/itkMeanReciprocalSquareDifferencePointSetToImageMetric.hxx b/Modules/Registration/Common/include/itkMeanReciprocalSquareDifferencePointSetToImageMetric.hxx index e71e4eb8f47..e2956cccb67 100644 --- a/Modules/Registration/Common/include/itkMeanReciprocalSquareDifferencePointSetToImageMetric.hxx +++ b/Modules/Registration/Common/include/itkMeanReciprocalSquareDifferencePointSetToImageMetric.hxx @@ -148,7 +148,7 @@ MeanReciprocalSquareDifferencePointSetToImageMetric; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); @@ -247,7 +247,7 @@ MeanReciprocalSquareDifferencePointSetToImageMetric; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); diff --git a/Modules/Registration/Common/include/itkMeanSquaresPointSetToImageMetric.hxx b/Modules/Registration/Common/include/itkMeanSquaresPointSetToImageMetric.hxx index fb1de31b02a..c5333495329 100644 --- a/Modules/Registration/Common/include/itkMeanSquaresPointSetToImageMetric.hxx +++ b/Modules/Registration/Common/include/itkMeanSquaresPointSetToImageMetric.hxx @@ -142,7 +142,7 @@ MeanSquaresPointSetToImageMetric::GetDerivative( using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); @@ -242,7 +242,7 @@ MeanSquaresPointSetToImageMetric::GetValueAndDeriv using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); diff --git a/Modules/Registration/Common/include/itkNormalizedCorrelationImageToImageMetric.hxx b/Modules/Registration/Common/include/itkNormalizedCorrelationImageToImageMetric.hxx index 67ccb06adf0..f8a8219a99e 100644 --- a/Modules/Registration/Common/include/itkNormalizedCorrelationImageToImageMetric.hxx +++ b/Modules/Registration/Common/include/itkNormalizedCorrelationImageToImageMetric.hxx @@ -249,7 +249,7 @@ NormalizedCorrelationImageToImageMetric::GetDerivativ using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); @@ -434,7 +434,7 @@ NormalizedCorrelationImageToImageMetric::GetValueAndD using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->m_MovingImage->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->m_MovingImage->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); diff --git a/Modules/Registration/Common/include/itkNormalizedCorrelationPointSetToImageMetric.hxx b/Modules/Registration/Common/include/itkNormalizedCorrelationPointSetToImageMetric.hxx index 68ba2d1f411..9af4b13decc 100644 --- a/Modules/Registration/Common/include/itkNormalizedCorrelationPointSetToImageMetric.hxx +++ b/Modules/Registration/Common/include/itkNormalizedCorrelationPointSetToImageMetric.hxx @@ -192,7 +192,7 @@ NormalizedCorrelationPointSetToImageMetric::GetDer using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->GetMovingImage()->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->GetMovingImage()->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); @@ -335,7 +335,7 @@ NormalizedCorrelationPointSetToImageMetric::GetVal using MovingImageContinuousIndexType = ContinuousIndex; const MovingImageContinuousIndexType tempIndex = - this->GetMovingImage()->template TransformPhysicalPointToContinuousIndex(transformedPoint); + this->GetMovingImage()->TransformPhysicalPointToContinuousIndex(transformedPoint); typename MovingImageType::IndexType mappedIndex; mappedIndex.CopyWithRound(tempIndex); diff --git a/Modules/Segmentation/SuperPixel/include/itkSLICImageFilter.hxx b/Modules/Segmentation/SuperPixel/include/itkSLICImageFilter.hxx index 6a4230f2efa..46072ac8fab 100644 --- a/Modules/Segmentation/SuperPixel/include/itkSLICImageFilter.hxx +++ b/Modules/Segmentation/SuperPixel/include/itkSLICImageFilter.hxx @@ -160,8 +160,7 @@ SLICImageFilter::BeforeThreadedGenera const IndexType & idx = it.GetIndex(); typename InputImageType::PointType pt; shrunkImage->TransformIndexToPhysicalPoint(idx, pt); - const ContinuousIndexType cidx = - inputImage->template TransformPhysicalPointToContinuousIndex(pt); + const ContinuousIndexType cidx = inputImage->TransformPhysicalPointToContinuousIndex(pt); for (unsigned int i = 0; i < ImageDimension; ++i) { cluster[numberOfComponents + i] = cidx[i];