From a9fa3d935bcc25215aa322e35c1f29dd187fc4a6 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 10 Feb 2026 15:01:49 +0100 Subject: [PATCH] ENH: Add `ComputeIndex()` member function to ImageConstIterator Provides an alternative to `ImageConstIterator::GetIndex()`, making it more clear that potentially expensive computation is involved. (cherry picked from commit 3e5a75a03dd0a086add02828794b54c880315096) --- .../Core/Common/include/itkImageConstIterator.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Modules/Core/Common/include/itkImageConstIterator.h b/Modules/Core/Common/include/itkImageConstIterator.h index ec5c9cca7dc..58723f1f47a 100644 --- a/Modules/Core/Common/include/itkImageConstIterator.h +++ b/Modules/Core/Common/include/itkImageConstIterator.h @@ -295,14 +295,22 @@ class ITK_TEMPLATE_EXPORT ImageConstIterator return (m_Buffer + m_Offset) > (it.m_Buffer + it.m_Offset); } - /** Get the index. This provides a read only reference to the index. - * This causes the index to be calculated from pointer arithmetic and is - * therefore an expensive operation. + /** Computes the index. Internally calls ImageBase::ComputeIndex, which may be a relatively expensive operation. * \sa SetIndex */ + [[nodiscard]] IndexType + ComputeIndex() const + { + return m_Image->ComputeIndex(static_cast(m_Offset)); + } + + /** Computes and returns the index. This may be a relatively expensive operation. + * \note It is often preferable for users to call ComputeIndex() directly, to make it more clear that this function + * may be expensive. + * \sa ComputeIndex */ const IndexType GetIndex() const { - return m_Image->ComputeIndex(static_cast(m_Offset)); + return this->ComputeIndex(); } /** Set the index. No bounds checking is performed.