Skip to content

Commit

Permalink
STYLE: Prefer compile-time constexpr
Browse files Browse the repository at this point in the history
The values of m_Factor* are known at compile-
time, so compute them only at compile-time.
  • Loading branch information
hjmjohnson committed Dec 30, 2024
1 parent a1ed62f commit 4ef3eaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand All @@ -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;
};

/**
Expand All @@ -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);
};

/**
Expand All @@ -112,14 +112,14 @@ class ITK_TEMPLATE_EXPORT LanczosWindowFunction
if (A == 0.0)
{
return static_cast<TOutput>(1.0);
}
} // namespace Function
const double z = m_Factor * A;
return static_cast<TOutput>(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;
};

/**
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@

namespace itk
{

// Constant definitions for functions
namespace Function
{
template <unsigned int VRadius, typename TInput, typename TOutput>
const double CosineWindowFunction<VRadius, TInput, TOutput>::m_Factor = itk::Math::pi / (2 * VRadius);

template <unsigned int VRadius, typename TInput, typename TOutput>
const double HammingWindowFunction<VRadius, TInput, TOutput>::m_Factor = itk::Math::pi / VRadius;

template <unsigned int VRadius, typename TInput, typename TOutput>
const double WelchWindowFunction<VRadius, TInput, TOutput>::m_Factor = 1.0 / (VRadius * VRadius);

template <unsigned int VRadius, typename TInput, typename TOutput>
const double LanczosWindowFunction<VRadius, TInput, TOutput>::m_Factor = itk::Math::pi / VRadius;

template <unsigned int VRadius, typename TInput, typename TOutput>
const double BlackmanWindowFunction<VRadius, TInput, TOutput>::m_Factor1 = itk::Math::pi / VRadius;

template <unsigned int VRadius, typename TInput, typename TOutput>
const double BlackmanWindowFunction<VRadius, TInput, TOutput>::m_Factor2 = 2.0 * itk::Math::pi / VRadius;
} // end namespace Function

template <typename TInputImage,
unsigned int VRadius,
typename TWindowFunction,
Expand Down

0 comments on commit 4ef3eaa

Please sign in to comment.