Skip to content

Commit 6807db4

Browse files
jhlegarretaN-Dekker
authored andcommitted
STYLE: Use an unsigned integer to store the number of poles
Use an unsigned integer instead of a signed to store the number of poles in `itk::BSplineDecompositionImageFilter`: the number of poles cannot be negative. Take advantage of the commit to use `ITK_TEST_EXPECT_EQUAL` in the corresponding check as an exact comparisons can be performed, ensures that the lh and rh arguments have the exact same types at compile time, and since it improves readability, and avoids boilerplate code.
1 parent 86e2e93 commit 6807db4

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

Modules/Core/ImageFunction/include/itkBSplineDecompositionImageFilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ITK_TEMPLATE_EXPORT BSplineDecompositionImageFilter : public ImageToImageF
116116
itkGetConstMacro(SplinePoles, SplinePolesVectorType);
117117

118118
/** Get the number of poles. */
119-
itkGetConstMacro(NumberOfPoles, int);
119+
itkGetConstMacro(NumberOfPoles, unsigned int);
120120

121121

122122
#ifdef ITK_USE_CONCEPT_CHECKING
@@ -198,7 +198,7 @@ class ITK_TEMPLATE_EXPORT BSplineDecompositionImageFilter : public ImageToImageF
198198

199199
SplinePolesVectorType m_SplinePoles{};
200200

201-
int m_NumberOfPoles{};
201+
unsigned int m_NumberOfPoles{};
202202

203203
/** Tolerance used for determining initial causal coefficient. Default is 1e-10.*/
204204
double m_Tolerance{ 1e-10 };

Modules/Core/ImageFunction/include/itkBSplineDecompositionImageFilter.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>::DataToCoefficients1D
8181
}
8282

8383
// Compute over all gain
84-
for (int k = 0; k < m_NumberOfPoles; ++k)
84+
for (unsigned int k = 0; k < m_NumberOfPoles; ++k)
8585
{
8686
// Note for cubic splines lambda = 6
8787
c0 = c0 * (1.0 - m_SplinePoles[k]) * (1.0 - 1.0 / m_SplinePoles[k]);
@@ -94,7 +94,7 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>::DataToCoefficients1D
9494
}
9595

9696
// Loop over all poles
97-
for (int k = 0; k < m_NumberOfPoles; ++k)
97+
for (unsigned int k = 0; k < m_NumberOfPoles; ++k)
9898
{
9999
// Causal initialization
100100
this->SetInitialCausalCoefficient(m_SplinePoles[k]);

Modules/Core/ImageFunction/test/itkBSplineDecompositionImageFilterTest.cxx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,7 @@ itkBSplineDecompositionImageFilterTest(int argc, char * argv[])
110110

111111
FilterType::SplinePolesVectorType expectedSplinePoles = ParseSplinePoles<FilterType>(argv[2]);
112112

113-
int expectedNumberOfPoles = expectedSplinePoles.size();
114-
int resultNumberOfPoles = filter->GetNumberOfPoles();
115-
if (!itk::Math::ExactlyEquals(expectedNumberOfPoles, resultNumberOfPoles))
116-
{
117-
std::cout << "Test failed!" << std::endl;
118-
std::cout << "Error in GetNumberOfPoles()" << std::endl;
119-
std::cout << "Expected: " << expectedNumberOfPoles << std::endl;
120-
std::cout << " , but got: " << resultNumberOfPoles << std::endl;
121-
return EXIT_FAILURE;
122-
}
113+
ITK_TEST_EXPECT_EQUAL(filter->GetNumberOfPoles(), expectedSplinePoles.size());
123114

124115
FilterType::SplinePolesVectorType resultSplinePoles = filter->GetSplinePoles();
125116
double tolerance1 = 1e-10;

0 commit comments

Comments
 (0)