From 452126bd909d7cf0123a80823db03969942978ae Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 4 Sep 2018 15:20:42 +0200 Subject: [PATCH] STYLE: Removed LinearInterpolateImageFunction::m_Neighbors LinearInterpolateImageFunction has a private static const data member 'm_Neighbors' that is only used once, within EvaluateUnoptimized. This commit removes m_Neighbors. Instead, the number of neighbors is now computed at compile-time, within EvaluateUnoptimized, storing the value into a local constexpr variable. This commit may reduce the runtime overhead somewhat, but it's mostly a style improvement, simplifying the code. Change-Id: I96649e11a543fc0f3f246e1f5023ebbc855c520e --- .../include/itkLinearInterpolateImageFunction.h | 3 --- .../include/itkLinearInterpolateImageFunction.hxx | 13 ++++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.h b/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.h index 96703e7a3d7..8e17c71e0cf 100644 --- a/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.h +++ b/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.h @@ -107,9 +107,6 @@ class ITK_TEMPLATE_EXPORT LinearInterpolateImageFunction: void PrintSelf(std::ostream & os, Indent indent) const override; private: - /** Number of neighbors used in the interpolation */ - static const unsigned long m_Neighbors; - struct DispatchBase {}; template< unsigned int > struct Dispatch: public DispatchBase {}; diff --git a/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.hxx b/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.hxx index 2307fc7ee7c..490f6818a91 100644 --- a/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.hxx +++ b/Modules/Core/ImageFunction/include/itkLinearInterpolateImageFunction.hxx @@ -25,14 +25,6 @@ namespace itk { - -// Define the number of neighbors -template< typename TInputImage, typename TCoordRep > -const unsigned long -LinearInterpolateImageFunction< TInputImage, TCoordRep > -::m_Neighbors = 1 << TInputImage::ImageDimension; - - template< typename TInputImage, typename TCoordRep > LinearInterpolateImageFunction< TInputImage, TCoordRep > ::LinearInterpolateImageFunction() @@ -80,7 +72,10 @@ LinearInterpolateImageFunction< TInputImage, TCoordRep > Concept::Detail::UniqueType< typename NumericTraits< InputPixelType >::ScalarRealType >(); - for ( unsigned int counter = 0; counter < m_Neighbors; ++counter ) + // Number of neighbors used in the interpolation + constexpr unsigned long numberOfNeighbors = 1 << TInputImage::ImageDimension; + + for ( unsigned int counter = 0; counter < numberOfNeighbors; ++counter ) { InternalComputationType overlap = 1.0; // Fraction overlap unsigned int upper = counter; // Each bit indicates upper/lower neighbour