From 4ef3eaa0246a3b3eaf0a9253cfc48793eed5cdc9 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 22 Dec 2024 16:50:20 -0600 Subject: [PATCH] STYLE: Prefer compile-time constexpr The values of m_Factor* are known at compile- time, so compute them only at compile-time. --- .../itkWindowedSincInterpolateImageFunction.h | 16 ++++++------- ...tkWindowedSincInterpolateImageFunction.hxx | 23 ------------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.h b/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.h index b0a2be4e4d2..09ac2e1b344 100644 --- a/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.h +++ b/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.h @@ -46,7 +46,7 @@ class ITK_TEMPLATE_EXPORT CosineWindowFunction private: /** Equal to \f$ \frac{\pi}{2 m} \f$ */ - static const double m_Factor; + static constexpr double m_Factor = itk::Math::pi / (2 * VRadius); }; /** @@ -68,7 +68,7 @@ class ITK_TEMPLATE_EXPORT HammingWindowFunction private: /** Equal to \f$ \frac{\pi}{m} \f$ */ - static const double m_Factor; + static constexpr double m_Factor = itk::Math::pi / VRadius; }; /** @@ -90,7 +90,7 @@ class ITK_TEMPLATE_EXPORT WelchWindowFunction private: /** Equal to \f$ \frac{1}{m^2} \f$ */ - static const double m_Factor; + static constexpr double m_Factor = 1.0 / (VRadius * VRadius); }; /** @@ -112,14 +112,14 @@ class ITK_TEMPLATE_EXPORT LanczosWindowFunction if (A == 0.0) { return static_cast(1.0); - } + } // namespace Function const double z = m_Factor * A; return static_cast(std::sin(z) / z); - } + } // namespace itk private: /** Equal to \f$ \frac{\pi}{m} \f$ */ - static const double m_Factor; + static constexpr double m_Factor = itk::Math::pi / VRadius; }; /** @@ -141,10 +141,10 @@ class ITK_TEMPLATE_EXPORT BlackmanWindowFunction private: /** Equal to \f$ \frac{\pi}{m} \f$ */ - static const double m_Factor1; + static constexpr double m_Factor1 = itk::Math::pi / VRadius; /** Equal to \f$ \frac{2 \pi}{m} \f$ */ - static const double m_Factor2; + static constexpr double m_Factor2 = 2.0 * itk::Math::pi / VRadius; }; } // namespace Function diff --git a/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.hxx b/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.hxx index fbf5460a377..b2e49d40eeb 100644 --- a/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.hxx +++ b/Modules/Core/ImageFunction/include/itkWindowedSincInterpolateImageFunction.hxx @@ -23,29 +23,6 @@ namespace itk { - -// Constant definitions for functions -namespace Function -{ -template -const double CosineWindowFunction::m_Factor = itk::Math::pi / (2 * VRadius); - -template -const double HammingWindowFunction::m_Factor = itk::Math::pi / VRadius; - -template -const double WelchWindowFunction::m_Factor = 1.0 / (VRadius * VRadius); - -template -const double LanczosWindowFunction::m_Factor = itk::Math::pi / VRadius; - -template -const double BlackmanWindowFunction::m_Factor1 = itk::Math::pi / VRadius; - -template -const double BlackmanWindowFunction::m_Factor2 = 2.0 * itk::Math::pi / VRadius; -} // end namespace Function - template